From d6826bb3d4cd375fb09e688b0c738acb5122f270 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 22 Oct 2023 20:05:34 +0100 Subject: [PATCH] Drop support for Node 14 and 16 --- .github/workflows/main.yml | 8 ++++---- index.js | 21 ++++----------------- package.json | 9 ++++----- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0aad1e7..26c3599 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,15 +10,15 @@ jobs: fail-fast: false matrix: node-version: + - 21 + - 20 - 18 - - 16 - - 14 os: - ubuntu-latest - windows-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.js b/index.js index 18ff319..444c431 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ import process from 'node:process'; -import escapeStringRegexp from 'escape-string-regexp'; import isUnicodeSupported from 'is-unicode-supported'; const {platform} = process; @@ -293,20 +292,8 @@ const shouldUseMain = isUnicodeSupported(); const figures = shouldUseMain ? mainSymbols : fallbackSymbols; export default figures; -const isFallbackSymbol = (key, mainSymbol) => fallbackSymbols[key] !== mainSymbol; -const getFigureRegExp = (key, mainSymbol) => [new RegExp(escapeStringRegexp(mainSymbol), 'g'), fallbackSymbols[key]]; - -let replacements = []; -const getReplacements = () => { - if (replacements.length > 0) { - return replacements; - } - - replacements = Object.entries(mainSymbols) - .filter(([key, mainSymbol]) => isFallbackSymbol(key, mainSymbol)) - .map(([key, mainSymbol]) => getFigureRegExp(key, mainSymbol)); - return replacements; -}; +const replacements = Object.entries(mainSymbols) + .filter(([key, mainSymbol]) => fallbackSymbols[key] !== mainSymbol); // On terminals which do not support Unicode symbols, substitute them to other symbols export const replaceSymbols = string => { @@ -314,8 +301,8 @@ export const replaceSymbols = string => { return string; } - for (const [figureRegExp, fallbackSymbol] of getReplacements()) { - string = string.replace(figureRegExp, fallbackSymbol); + for (const [key, mainSymbol] of replacements) { + string = string.replaceAll(mainSymbol, fallbackSymbols[key]); } return string; diff --git a/package.json b/package.json index 0f9adf2..efcb1ff 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "type": "module", "exports": "./index.js", "engines": { - "node": ">=14" + "node": ">=18" }, "scripts": { "test": "xo && ava && tsd" @@ -35,12 +35,11 @@ "fallback" ], "dependencies": { - "escape-string-regexp": "^5.0.0", "is-unicode-supported": "^1.2.0" }, "devDependencies": { - "ava": "^4.3.1", - "tsd": "^0.22.0", - "xo": "^0.51.0" + "ava": "^5.3.1", + "tsd": "^0.29.0", + "xo": "^0.56.0" } }