Skip to content

Commit d2b71a5

Browse files
committed
fixed hex color issue
1 parent 10ce1f1 commit d2b71a5

File tree

7 files changed

+37
-43
lines changed

7 files changed

+37
-43
lines changed

.eslintignore

Whitespace-only changes.

.eslintrc.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* v2.2.3
2+
- fixed hex color issue
3+
14
* v2.2.2
25
- fixed the tree icon if name is empty
36

eslint.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// https://eslint.org/docs/rules/
2+
3+
const plus = require('eslint-config-plus');
4+
5+
// https://eslint.org/docs/latest/use/configure/configuration-files
6+
module.exports = [
7+
plus
8+
];

lib/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,17 @@ class ConsoleGrid {
654654
}
655655

656656
removeColor(str) {
657-
return `${str}`.replace(/\033\[(\d+)m/g, '');
657+
// https://github.com/chalk/ansi-regex
658+
// Valid string terminator sequences are BEL, ESC\, and 0x9c
659+
const ST = '(?:\\u0007|\\u001B\\u005C|\\u009C)';
660+
const pattern = [
661+
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`,
662+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
663+
].join('|');
664+
665+
const reg = new RegExp(pattern, 'g');
666+
667+
return `${str}`.replace(reg, '');
658668
}
659669

660670
render() {

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"scripts": {
1717
"link": "sf link ./ -f",
1818
"build": "node ./scripts/build.mjs",
19-
"test": "node ./scripts/test.cjs",
19+
"test": "node ./scripts/test.mjs",
2020
"patch": "npm run test && npm run build && sf publish patch -r"
2121
},
2222
"files": [
@@ -27,14 +27,14 @@
2727
"type": "git",
2828
"url": "git+https://github.com/cenfun/console-grid.git"
2929
},
30-
"dependencies": {},
3130
"devDependencies": {
32-
"eastasianwidth": "^0.2.0",
33-
"eight-colors": "^1.3.0",
34-
"eslint": "^8.57.0",
35-
"eslint-config-plus": "^1.0.6",
36-
"eslint-plugin-html": "^8.0.0",
31+
"chalk": "^5.4.1",
32+
"eastasianwidth": "^0.3.0",
33+
"eight-colors": "^1.3.1",
34+
"eslint": "^9.17.0",
35+
"eslint-config-plus": "^2.0.2",
36+
"eslint-plugin-html": "^8.1.2",
3737
"js-beautify": "^1.15.1",
3838
"papaparse": "^5.4.1"
3939
}
40-
}
40+
}

scripts/test.cjs renamed to scripts/test.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const EC = require('eight-colors');
2-
const CG = require('console-grid');
1+
import EC from 'eight-colors';
2+
import chalk from 'chalk';
3+
import CG from 'console-grid';
34

45
console.log(CG);
56

@@ -34,6 +35,8 @@ console.log(cg.getCharByWidth(bgStr, 30));
3435
console.log(cg.getCharByWidth(bgStr, 20));
3536
console.log(cg.getCharByWidth(bgStr, 10));
3637

38+
const hexColor = chalk.hex('#ff0000');
39+
3740
CG({
3841
columns: [{
3942
id: 'name'
@@ -44,5 +47,7 @@ CG({
4447
}, {
4548
name: EC.bg.yellow(`long string ${EC.green('inner green string')} ${EC.red('long red string long red string')}`),
4649
maxWidth: 50
50+
}, {
51+
name: hexColor('Hex Colored Text')
4752
}]
4853
});

0 commit comments

Comments
 (0)