Skip to content

Commit 3b7a6b6

Browse files
committed
isBrowser or isNode works =)
1 parent 3ca276f commit 3b7a6b6

File tree

13 files changed

+251
-0
lines changed

13 files changed

+251
-0
lines changed

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": ["stage-2", "es2015"],
3+
"plugins": [
4+
"add-module-exports"
5+
]
6+
}

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# EditorConfig helps developers define and maintain
2+
# consistent coding styles between different editors and IDEs.
3+
4+
root = true
5+
6+
[*]
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
indent_style = space
12+
indent_size = 2
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

.eslintrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": "airbnb",
4+
"env": {
5+
"mocha": true
6+
},
7+
rules: {
8+
"comma-dangle": ["error", "only-multiline"]
9+
}
10+
}

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# nyc test coverage
18+
.nyc_output
19+
20+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21+
.grunt
22+
23+
# node-waf configuration
24+
.lock-wscript
25+
26+
# Compiled binary addons (http://nodejs.org/api/addons.html)
27+
build/Release
28+
29+
# Dependency directories
30+
node_modules
31+
jspm_packages
32+
33+
# Optional npm cache directory
34+
.npm
35+
36+
# Optional REPL history
37+
.node_repl_history
38+
39+
# Editors
40+
.idea
41+
42+
# Lib
43+
lib
44+
45+
# npm package lock
46+
package-lock.json

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: node_js
2+
node_js:
3+
- '8'
4+
- '6'
5+
script:
6+
- npm run lint
7+
- npm run test
8+
- npm run build
9+
- npm run test:examples
10+
branches:
11+
only:
12+
- master

LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Dineshkumar Pandiyan <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Browser or Node.js
2+
[![Build Status](https://travis-ci.org/flexdinesh/brower-or-node.svg?branch=master)](https://travis-ci.org/flexdinesh/brower-or-node)
3+
[![npm version](https://badge.fury.io/js/brower-or-node.svg)](https://www.npmjs.com/package/brower-or-node)
4+
[![dependencies Status](https://david-dm.org/flexdinesh/brower-or-node/status.svg)](https://david-dm.org/flexdinesh/brower-or-node)
5+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6+
[![npm](https://img.shields.io/npm/dt/brower-or-node.svg)](https://www.npmjs.com/package/brower-or-node)
7+
8+
Check whether the code is running in the browser or node.js runtime.
9+
10+
## Install
11+
12+
```
13+
$ npm install --save brower-or-node
14+
```
15+
16+
## Usage
17+
18+
ES6 style import
19+
```js
20+
import { isBrowser, isNode } from 'brower-or-node';
21+
22+
if (isBrowser) {
23+
// do browser only stuff
24+
}
25+
26+
if (isNode) {
27+
// do node.js only stuff
28+
}
29+
30+
```
31+
ES5 style import
32+
```js
33+
var jsEnv = require('brower-or-node');
34+
35+
if (jsEnv.isBrowser) {
36+
// do browser only stuff
37+
}
38+
39+
if (jsEnv.isNode) {
40+
// do node.js only stuff
41+
}
42+
43+
```
44+
45+
## License
46+
47+
MIT © Dineshkumar Pandiyan

examples/example.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* eslint-disable import/no-extraneous-dependencies, no-console */
2+
const jsEnv = require('../lib');
3+
4+
console.log(jsEnv.isBrowser); // false when this runs in node.js
5+
console.log(jsEnv.isNode); // true when this runs in node.js

examples/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const example = require('./example');
2+
3+
module.exports = {
4+
example
5+
};

0 commit comments

Comments
 (0)