Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for Node 14 and 16 #97

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}