Skip to content

Commit

Permalink
Drop support for Node 14 and 16 (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Oct 29, 2023
1 parent fd67dc5 commit 3302caa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 4 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import process from 'node:process';
import escapeStringRegexp from 'escape-string-regexp';
import isUnicodeSupported from 'is-unicode-supported';

const {platform} = process;
Expand Down Expand Up @@ -293,29 +292,17 @@ 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 => {
if (shouldUseMain) {
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;
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=14"
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -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"
}
}

0 comments on commit 3302caa

Please sign in to comment.