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 23, 2019
1 parent 0793882 commit f0b7606
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
29 changes: 29 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
Split a string on the first occurrence of a given separator.
@param string - The string to split.
@param separator - The separator to split on.
@example
```
import splitOnFirst = require('split-on-first');
splitOnFirst('a-b-c', '-');
//=> ['a', 'b-c']
splitOnFirst('key:value:value2', ':');
//=> ['key', 'value:value2']
splitOnFirst('a---b---c', '---');
//=> ['a', 'b---c']
splitOnFirst('a-b-c', '+');
//=> ['a-b-c']
```
*/
declare function splitOnFirst(
string: string,
separator: string
): [string, string?];

export = splitOnFirst;
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 splitOnFirst = require('.');

expectType<[string, string?]>(splitOnFirst('a-b-c', '-'));
8 changes: 5 additions & 3 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": [
"split",
Expand All @@ -28,7 +29,8 @@
"text"
],
"devDependencies": {
"ava": "^1.2.0",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit f0b7606

Please sign in to comment.