Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
navigator
global with userAgent
property
- Loading branch information
1 parent
f4e136d
commit 2331b1e
Showing
4 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'nxjs-runtime': patch | ||
--- | ||
|
||
Add `navigator` global with `userAgent` property |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { def } from './utils'; | ||
import type { SwitchClass } from './switch'; | ||
|
||
declare const Switch: SwitchClass; | ||
|
||
/** | ||
* The `Navigator` interface represents the state and the identity of the user agent. | ||
* It allows scripts to query it and to register themselves to carry on some activities. | ||
* | ||
* A `Navigator` instance can be retrieved by accessing the global {@link navigator | `navigator`} property. | ||
* | ||
* @see https://developer.mozilla.org/docs/Web/API/Navigator | ||
*/ | ||
export class Navigator { | ||
constructor() { | ||
throw new TypeError('Illegal constructor.'); | ||
} | ||
|
||
/** | ||
* Returns the value used for the `User-Agent` HTTP request header for | ||
* HTTP requests initiated with {@link fetch | `fetch()`}. | ||
* | ||
* @example "my-app/0.0.1 (Switch; en-us; rv:14.1.2|AMS 1.5.4|E) nx.js/0.0.18" | ||
* @see https://developer.mozilla.org/docs/Web/API/Navigator/userAgent | ||
*/ | ||
get userAgent(): string { | ||
return `nx.js/${Switch.version.nxjs}`; | ||
} | ||
} | ||
def('Navigator', Navigator); | ||
|
||
export const navigator: Navigator = Object.create(Navigator.prototype); | ||
def('navigator', navigator); |