Skip to content

Commit 7cda68d

Browse files
committedApr 16, 2021
Require Node.js 12 and move to ESM
1 parent d6d1128 commit 7cda68d

File tree

9 files changed

+25
-21
lines changed

9 files changed

+25
-21
lines changed
 

‎.github/funding.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github: [sindresorhus,Qix-]
1+
github: [sindresorhus, Qix-]
22
tidelift: npm/strip-ansi

‎.github/workflows/main.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ jobs:
1212
node-version:
1313
- 14
1414
- 12
15-
- 10
16-
- 8
1715
steps:
1816
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
17+
- uses: actions/setup-node@v2
2018
with:
2119
node-version: ${{ matrix.node-version }}
2220
- run: npm install

‎index.d.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a
33
44
@example
55
```
6-
import stripAnsi = require('strip-ansi');
6+
import stripAnsi from 'strip-ansi';
77
88
stripAnsi('\u001B[4mUnicorn\u001B[0m');
99
//=> 'Unicorn'
@@ -12,6 +12,4 @@ stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
1212
//=> 'Click'
1313
```
1414
*/
15-
declare function stripAnsi(string: string): string;
16-
17-
export = stripAnsi;
15+
export default function stripAnsi(string: string): string;

‎index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
'use strict';
2-
const ansiRegex = require('ansi-regex');
1+
import ansiRegex from 'ansi-regex';
32

4-
module.exports = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
3+
export default function stripAnsi(string) {
4+
if (typeof string !== 'string') {
5+
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
6+
}
7+
8+
return string.replace(ansiRegex(), '');
9+
}

‎index.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import {expectType} from 'tsd';
2-
import stripAnsi = require('.');
2+
import stripAnsi from './index.js';
33

44
expectType<string>(stripAnsi('\u001B[4mcake\u001B[0m'));

‎license

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

‎package.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Strip ANSI escape codes from a string",
55
"license": "MIT",
66
"repository": "chalk/strip-ansi",
7+
"funding": "https://github.com/chalk/strip-ansi?sponsor=1",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "sindresorhus@gmail.com",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=8"
16+
"node": ">=12"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd"
@@ -44,11 +47,11 @@
4447
"text"
4548
],
4649
"dependencies": {
47-
"ansi-regex": "^5.0.0"
50+
"ansi-regex": "^6.0.0"
4851
},
4952
"devDependencies": {
50-
"ava": "^2.4.0",
51-
"tsd": "^0.10.0",
52-
"xo": "^0.25.3"
53+
"ava": "^3.15.0",
54+
"tsd": "^0.14.0",
55+
"xo": "^0.38.2"
5356
}
5457
}

‎readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $ npm install strip-ansi
1111
## Usage
1212

1313
```js
14-
const stripAnsi = require('strip-ansi');
14+
import stripAnsi from 'strip-ansi';
1515

1616
stripAnsi('\u001B[4mUnicorn\u001B[0m');
1717
//=> 'Unicorn'

‎test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import stripAnsi from '.';
2+
import stripAnsi from './index.js';
33

44
test('strip color from string', t => {
55
t.is(stripAnsi('\u001B[0m\u001B[4m\u001B[42m\u001B[31mfoo\u001B[39m\u001B[49m\u001B[24mfoo\u001B[0m'), 'foofoo');

0 commit comments

Comments
 (0)
Please sign in to comment.