Skip to content

Commit

Permalink
Add TypeScript definition (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 20, 2019
1 parent 61fdb07 commit b627ea5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 14 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
20 changes: 20 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
Check if a path is in the [current working directory](https://en.wikipedia.org/wiki/Working_directory).
@example
```
import isPathInCwd = require('is-path-in-cwd');
isPathInCwd('unicorn');
//=> true
isPathInCwd('../rainbow');
//=> false
isPathInCwd('.');
//=> false
```
*/
declare function isPathInCwd(path: string): boolean;

export = isPathInCwd;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
const isPathInside = require('is-path-inside');

module.exports = input => isPathInside(input, process.cwd());
module.exports = path => isPathInside(path, process.cwd());
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';
import isPathInCwd = require('.');

expectType<boolean>(isPathInCwd('unicorn'));
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"path",
Expand All @@ -30,10 +31,11 @@
"inside"
],
"dependencies": {
"is-path-inside": "^1.0.0"
"is-path-inside": "^2.1.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
12 changes: 6 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import test from 'ava';
import m from '.';
import isPathInCwd from '.';

test('main', t => {
t.true(m('foo'));
t.false(m('.'));
t.false(m('/'));
t.false(m('..'));
t.false(m('../rainbow'));
t.true(isPathInCwd('foo'));
t.false(isPathInCwd('.'));
t.false(isPathInCwd('/'));
t.false(isPathInCwd('..'));
t.false(isPathInCwd('../rainbow'));
});

0 comments on commit b627ea5

Please sign in to comment.