Skip to content

Commit 55ed49f

Browse files
committed
Add TypeScript types
1 parent 8c06536 commit 55ed49f

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

index.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
Slice a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
3+
4+
@param string - A string with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk).
5+
@param startSlice - Zero-based index at which to start the slice.
6+
@param endSlice - Zero-based index at which to end the slice.
7+
8+
@example
9+
```
10+
import chalk from 'chalk';
11+
import sliceAnsi from 'slice-ansi';
12+
13+
const string = 'The quick brown ' + chalk.red('fox jumped over ') +
14+
'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
15+
16+
console.log(sliceAnsi(string, 20, 30));
17+
```
18+
*/
19+
export default function sliceAnsi(string: string, startSlice: number, endSlice?: number): string;

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
"repository": "chalk/slice-ansi",
77
"funding": "https://github.com/chalk/slice-ansi?sponsor=1",
88
"type": "module",
9-
"exports": "./index.js",
9+
"exports": {
10+
"types": "./index.d.ts",
11+
"default": "./index.js"
12+
},
1013
"engines": {
11-
"node": ">=14.16"
14+
"node": ">=18"
1215
},
1316
"scripts": {
14-
"test": "xo && ava"
17+
"test": "xo && ava && tsc index.d.ts"
1518
},
1619
"files": [
17-
"index.js"
20+
"index.js",
21+
"index.d.ts"
1822
],
1923
"keywords": [
2024
"slice",

0 commit comments

Comments
 (0)