From 7cda68dcadde18b19bfa31b6223e9f0e60b3e319 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 16 Apr 2021 13:07:00 +0700 Subject: [PATCH] Require Node.js 12 and move to ESM --- .github/funding.yml | 2 +- .github/workflows/main.yml | 4 +--- index.d.ts | 6 ++---- index.js | 11 ++++++++--- index.test-d.ts | 2 +- license | 2 +- package.json | 15 +++++++++------ readme.md | 2 +- test.js | 2 +- 9 files changed, 25 insertions(+), 21 deletions(-) diff --git a/.github/funding.yml b/.github/funding.yml index deb26de..949e753 100644 --- a/.github/funding.yml +++ b/.github/funding.yml @@ -1,2 +1,2 @@ -github: [sindresorhus,Qix-] +github: [sindresorhus, Qix-] tidelift: npm/strip-ansi diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18531b3..d36e1a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/index.d.ts b/index.d.ts index 907fccc..44e954d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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' @@ -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; diff --git a/index.js b/index.js index 9a593df..ef3c095 100644 --- a/index.js +++ b/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(), ''); +} diff --git a/index.test-d.ts b/index.test-d.ts index 8b121bc..9075c4e 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,4 @@ import {expectType} from 'tsd'; -import stripAnsi = require('.'); +import stripAnsi from './index.js'; expectType(stripAnsi('\u001B[4mcake\u001B[0m')); diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (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: diff --git a/package.json b/package.json index 65a6c95..19672a3 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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" } } diff --git a/readme.md b/readme.md index 1fbea37..5627851 100644 --- a/readme.md +++ b/readme.md @@ -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' diff --git a/test.js b/test.js index 2884957..0973f22 100644 --- a/test.js +++ b/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');