-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
82 additions
and
0 deletions.
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,26 @@ | ||
# browser-or-server | ||
|
||
Statically tell if running environment is Node.js or browser | ||
|
||
## Usage | ||
|
||
```javascript | ||
import engine, {isBrowser, isServer} from 'browser-or-server' | ||
console.log(engine) // either 'browser' or 'server' | ||
console.log(isBrowser) // either true or false | ||
console.log(isServer) // either false or true | ||
``` | ||
|
||
## FAQs | ||
|
||
### How does it works? | ||
|
||
It's "server" if it is imported (a.k.a. `require()`d) directly via node and "browser" if it is bundled via browserify, webpack, etc. | ||
|
||
### How is this different from other similar packages? | ||
|
||
TypeScript support. | ||
|
||
## License | ||
|
||
[MIT](https://git.io/vhaEz) © [Hoàng Văn Khải](https://github.com/KSXGitHub) |
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 @@ | ||
import {Engine} from './types' | ||
export const engine: Engine = 'browser' | ||
export const isServer = false | ||
export const isBrowser = true | ||
export default engine |
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,27 @@ | ||
{ | ||
"name": "browser-or-server", | ||
"version": "0.0.0", | ||
"description": "Statically tell if running environment is Node.js or browser", | ||
"author": "Hoàng Văn Khải <hvksmr1996@gmail.com>", | ||
"license": "MIT", | ||
"homepage": "https://github.com/ksxnodemodules/nodemonorepo#readme", | ||
"bugs": { | ||
"url": "https://github.com/ksxnodemodules/nodemonorepo/issues" | ||
}, | ||
"main": "server.js", | ||
"browser": "browser.js", | ||
"keywords": [ | ||
"browser", | ||
"server", | ||
"environment", | ||
"predefined", | ||
"statis" | ||
], | ||
"dependencies": { | ||
"tslib": "^1.9.3", | ||
"@types/node": "^10.9.3" | ||
}, | ||
"engines": { | ||
"node": "^8.9.0" | ||
} | ||
} |
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 @@ | ||
import {Engine} from './types' | ||
export const engine: Engine = 'server' | ||
export const isServer = true | ||
export const isBrowser = false | ||
export default engine |
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,18 @@ | ||
dependencies: | ||
'@types/node': 10.9.4 | ||
tslib: 1.9.3 | ||
packages: | ||
/@types/node/10.9.4: | ||
dev: false | ||
resolution: | ||
integrity: sha512-fCHV45gS+m3hH17zgkgADUSi2RR1Vht6wOZ0jyHP8rjiQra9f+mIcgwPQHllmDocYOstIEbKlxbFDYlgrTPYqw== | ||
/tslib/1.9.3: | ||
dev: false | ||
resolution: | ||
integrity: sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ== | ||
registry: 'https://registry.npmjs.org/' | ||
shrinkwrapMinorVersion: 9 | ||
shrinkwrapVersion: 3 | ||
specifiers: | ||
'@types/node': ^10.9.3 | ||
tslib: ^1.9.3 |
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 @@ | ||
export type Engine = 'browser' | 'server' |