From 55ed49f13be93faefd82c06edb4c8be15080641e Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 30 Oct 2023 02:43:55 +0700 Subject: [PATCH] Add TypeScript types --- index.d.ts | 19 +++++++++++++++++++ package.json | 12 ++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..9b375be --- /dev/null +++ b/index.d.ts @@ -0,0 +1,19 @@ +/** +Slice a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) + +@param string - A string with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk). +@param startSlice - Zero-based index at which to start the slice. +@param endSlice - Zero-based index at which to end the slice. + +@example +``` +import chalk from 'chalk'; +import sliceAnsi from 'slice-ansi'; + +const string = 'The quick brown ' + chalk.red('fox jumped over ') + + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.'); + +console.log(sliceAnsi(string, 20, 30)); +``` +*/ +export default function sliceAnsi(string: string, startSlice: number, endSlice?: number): string; diff --git a/package.json b/package.json index 1eb6ccd..391e9aa 100644 --- a/package.json +++ b/package.json @@ -6,15 +6,19 @@ "repository": "chalk/slice-ansi", "funding": "https://github.com/chalk/slice-ansi?sponsor=1", "type": "module", - "exports": "./index.js", + "exports": { + "types": "./index.d.ts", + "default": "./index.js" + }, "engines": { - "node": ">=14.16" + "node": ">=18" }, "scripts": { - "test": "xo && ava" + "test": "xo && ava && tsc index.d.ts" }, "files": [ - "index.js" + "index.js", + "index.d.ts" ], "keywords": [ "slice",