Skip to content

Commit

Permalink
Require Node.js 8, add TypeScript definition (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 11, 2019
1 parent 2daa4ad commit e550ce1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
12 changes: 12 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Check if your code is running as an [npm](https://docs.npmjs.com/misc/scripts) or [yarn](https://yarnpkg.com/lang/en/docs/cli/run/) script.
*
* @example
*
* import {isNpm} from 'isNpm';
*
* if (isNpm) {
* console.log('Running as a npm script!');
* }
*/
export const isNpm: boolean;
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
'use strict';
module.exports = 'npm_config_username' in process.env ||

const isNpm =
'npm_config_username' in process.env ||
'npm_package_name' in process.env ||
'npm_config_heading' in process.env;

// TODO: This named export should be replaced by a default export as soon as we move to ES modules
exports.isNpm = isNpm;
4 changes: 4 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {expectType} from 'tsd-check';
import {isNpm} from '.';

expectType<boolean>(isNpm);
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"npm",
Expand All @@ -29,7 +30,8 @@
"script"
],
"devDependencies": {
"ava": "*",
"xo": "*"
"ava": "^1.3.1",
"tsd-check": "^0.3.0",
"xo": "^0.24.0"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $ npm install is-npm
## Usage

```js
const isNpm = require('is-npm');
const {isNpm} = require('is-npm');

console.log(isNpm);
```
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';
import m from '.';
import {isNpm} from '.';

test('main', t => {
t.true(m);
t.true(isNpm);
});

0 comments on commit e550ce1

Please sign in to comment.