Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 16, 2021
1 parent d6d1128 commit 7cda68d
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/funding.yml
@@ -1,2 +1,2 @@
github: [sindresorhus,Qix-]
github: [sindresorhus, Qix-]
tidelift: npm/strip-ansi
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Expand Up @@ -12,11 +12,9 @@ jobs:
node-version:
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
6 changes: 2 additions & 4 deletions index.d.ts
Expand Up @@ -3,7 +3,7 @@ Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a
@example
```
import stripAnsi = require('strip-ansi');
import stripAnsi from 'strip-ansi';
stripAnsi('\u001B[4mUnicorn\u001B[0m');
//=> 'Unicorn'
Expand All @@ -12,6 +12,4 @@ stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
//=> 'Click'
```
*/
declare function stripAnsi(string: string): string;

export = stripAnsi;
export default function stripAnsi(string: string): string;
11 changes: 8 additions & 3 deletions index.js
@@ -1,4 +1,9 @@
'use strict';
const ansiRegex = require('ansi-regex');
import ansiRegex from 'ansi-regex';

module.exports = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
export default function stripAnsi(string) {
if (typeof string !== 'string') {
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
}

return string.replace(ansiRegex(), '');
}
2 changes: 1 addition & 1 deletion index.test-d.ts
@@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import stripAnsi = require('.');
import stripAnsi from './index.js';

expectType<string>(stripAnsi('\u001B[4mcake\u001B[0m'));
2 changes: 1 addition & 1 deletion license
@@ -1,6 +1,6 @@
MIT License

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

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:

Expand Down
15 changes: 9 additions & 6 deletions package.json
Expand Up @@ -4,13 +4,16 @@
"description": "Strip ANSI escape codes from a string",
"license": "MIT",
"repository": "chalk/strip-ansi",
"funding": "https://github.com/chalk/strip-ansi?sponsor=1",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down Expand Up @@ -44,11 +47,11 @@
"text"
],
"dependencies": {
"ansi-regex": "^5.0.0"
"ansi-regex": "^6.0.0"
},
"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.10.0",
"xo": "^0.25.3"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -11,7 +11,7 @@ $ npm install strip-ansi
## Usage

```js
const stripAnsi = require('strip-ansi');
import stripAnsi from 'strip-ansi';

stripAnsi('\u001B[4mUnicorn\u001B[0m');
//=> 'Unicorn'
Expand Down
2 changes: 1 addition & 1 deletion test.js
@@ -1,5 +1,5 @@
import test from 'ava';
import stripAnsi from '.';
import stripAnsi from './index.js';

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

0 comments on commit 7cda68d

Please sign in to comment.