nhb-toolbox 4.20.16 → 4.20.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/utils/constants.js +101 -0
- package/dist/cjs/utils/helpers.js +47 -0
- package/dist/cjs/utils/stylog.js +330 -86
- package/dist/dts/utils/constants.d.ts +44 -0
- package/dist/dts/utils/constants.d.ts.map +1 -0
- package/dist/dts/utils/helpers.d.ts +23 -0
- package/dist/dts/utils/helpers.d.ts.map +1 -0
- package/dist/dts/utils/stylog.d.ts +357 -46
- package/dist/dts/utils/stylog.d.ts.map +1 -1
- package/dist/esm/utils/constants.js +98 -0
- package/dist/esm/utils/helpers.js +40 -0
- package/dist/esm/utils/stylog.js +328 -86
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,21 @@ All notable changes to the package will be documented here.
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [4.20.20] - 2025-09-04
|
|
10
|
+
|
|
11
|
+
### 🎨 Updates for Stylog/LogStyler
|
|
12
|
+
|
|
13
|
+
- **Reorganized** full `stylog` module.
|
|
14
|
+
- **Renamed** `string()` method to `toANSI()` and `applyStyles()` to `toCSS()`.
|
|
15
|
+
- **Added** new `ansi16()` method to apply `ANSI-16` color codes.
|
|
16
|
+
- **Added** new `hsl()` and `bgHSL()` methods to colorize using custom `hsl` color values.
|
|
17
|
+
- **Added** new `rgb()` and `bgRGB()` methods to colorize using custom `rgb` color values.
|
|
18
|
+
- **Added** new `hex()` and `bgHex()` methods to colorize using custom `hex` color values.
|
|
19
|
+
|
|
20
|
+
## [4.20.17] - 2025-09-02
|
|
21
|
+
|
|
22
|
+
- **Added** _color support detector_ for shell/console for `Stylog`/`LogStyler`.
|
|
23
|
+
|
|
9
24
|
## [4.20.16] - 2025-09-01
|
|
10
25
|
|
|
11
26
|
- **Added** new method `string()` in `LogStyler` (also in `Stylog`) and **made** `applyStyles()` method _public_.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CSS_16_COLORS = exports.ANSI_16_COLORS = exports.CSS_TEXT_STYLES = exports.ANSI_TEXT_STYLES = void 0;
|
|
4
|
+
/** ANSI styles for non-color text effects */
|
|
5
|
+
exports.ANSI_TEXT_STYLES = Object.freeze({
|
|
6
|
+
bold: ['\x1b[1m', '\x1b[22m'],
|
|
7
|
+
bolder: ['\x1b[1m', '\x1b[22m'],
|
|
8
|
+
dim: ['\x1b[2m', '\x1b[22m'],
|
|
9
|
+
italic: ['\x1b[3m', '\x1b[23m'],
|
|
10
|
+
underline: ['\x1b[4m', '\x1b[24m'],
|
|
11
|
+
strikethrough: ['\x1b[9m', '\x1b[29m'],
|
|
12
|
+
inverse: ['\x1b[7m', '\x1b[27m'],
|
|
13
|
+
});
|
|
14
|
+
/** Browser CSS equivalents */
|
|
15
|
+
exports.CSS_TEXT_STYLES = Object.freeze({
|
|
16
|
+
bold: 'font-weight: bold',
|
|
17
|
+
bolder: 'font-weight: bolder',
|
|
18
|
+
dim: 'opacity: 0.7',
|
|
19
|
+
italic: 'font-style: italic',
|
|
20
|
+
underline: 'text-decoration: underline',
|
|
21
|
+
strikethrough: 'text-decoration: line-through',
|
|
22
|
+
inverse: 'filter: invert(1)',
|
|
23
|
+
});
|
|
24
|
+
/** Records of ANSI-16 colors with values */
|
|
25
|
+
exports.ANSI_16_COLORS = Object.freeze({
|
|
26
|
+
// Foreground Colors
|
|
27
|
+
black: [30, 39],
|
|
28
|
+
red: [31, 39],
|
|
29
|
+
green: [32, 39],
|
|
30
|
+
yellow: [33, 39],
|
|
31
|
+
blue: [34, 39],
|
|
32
|
+
purple: [35, 39],
|
|
33
|
+
cyan: [36, 39],
|
|
34
|
+
white: [37, 39],
|
|
35
|
+
// Bright Foreground Colors
|
|
36
|
+
blackBright: [90, 39],
|
|
37
|
+
redBright: [91, 39],
|
|
38
|
+
greenBright: [92, 39],
|
|
39
|
+
yellowBright: [93, 39],
|
|
40
|
+
blueBright: [94, 39],
|
|
41
|
+
purpleBright: [95, 39],
|
|
42
|
+
cyanBright: [96, 39],
|
|
43
|
+
whiteBright: [97, 39],
|
|
44
|
+
// Background Colors
|
|
45
|
+
bgBlack: [40, 49],
|
|
46
|
+
bgRed: [41, 49],
|
|
47
|
+
bgGreen: [42, 49],
|
|
48
|
+
bgYellow: [43, 49],
|
|
49
|
+
bgBlue: [44, 49],
|
|
50
|
+
bgPurple: [45, 49],
|
|
51
|
+
bgCyan: [46, 49],
|
|
52
|
+
bgWhite: [47, 49],
|
|
53
|
+
// Bright Background Colors
|
|
54
|
+
bgBlackBright: [100, 49],
|
|
55
|
+
bgRedBright: [101, 49],
|
|
56
|
+
bgGreenBright: [102, 49],
|
|
57
|
+
bgYellowBright: [103, 49],
|
|
58
|
+
bgBlueBright: [104, 49],
|
|
59
|
+
bgPurpleBright: [105, 49],
|
|
60
|
+
bgCyanBright: [106, 49],
|
|
61
|
+
bgWhiteBright: [107, 49],
|
|
62
|
+
});
|
|
63
|
+
/** Browser CSS equivalents for ANSI 16 colors */
|
|
64
|
+
exports.CSS_16_COLORS = Object.freeze({
|
|
65
|
+
// Foreground Colors
|
|
66
|
+
black: '#000000',
|
|
67
|
+
red: '#800000',
|
|
68
|
+
green: '#008000',
|
|
69
|
+
yellow: '#808000',
|
|
70
|
+
blue: '#000080',
|
|
71
|
+
purple: '#800080',
|
|
72
|
+
cyan: '#008080',
|
|
73
|
+
white: '#c0c0c0',
|
|
74
|
+
// Bright Foreground Colors
|
|
75
|
+
blackBright: '#808080',
|
|
76
|
+
redBright: '#ff0000',
|
|
77
|
+
greenBright: '#00ff00',
|
|
78
|
+
yellowBright: '#ffff00',
|
|
79
|
+
blueBright: '#0000ff',
|
|
80
|
+
purpleBright: '#ff00ff',
|
|
81
|
+
cyanBright: '#00ffff',
|
|
82
|
+
whiteBright: '#ffffff',
|
|
83
|
+
// Background Colors
|
|
84
|
+
bgBlack: '#000000',
|
|
85
|
+
bgRed: '#800000',
|
|
86
|
+
bgGreen: '#008000',
|
|
87
|
+
bgYellow: '#808000',
|
|
88
|
+
bgBlue: '#000080',
|
|
89
|
+
bgPurple: '#800080',
|
|
90
|
+
bgCyan: '#008080',
|
|
91
|
+
bgWhite: '#c0c0c0',
|
|
92
|
+
// Bright Background Colors
|
|
93
|
+
bgBlackBright: '#808080',
|
|
94
|
+
bgRedBright: '#ff0000',
|
|
95
|
+
bgGreenBright: '#00ff00',
|
|
96
|
+
bgYellowBright: '#ffff00',
|
|
97
|
+
bgBlueBright: '#0000ff',
|
|
98
|
+
bgPurpleBright: '#ff00ff',
|
|
99
|
+
bgCyanBright: '#00ffff',
|
|
100
|
+
bgWhiteBright: '#ffffff',
|
|
101
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._extractColorName = _extractColorName;
|
|
4
|
+
exports._isAnsiSequence = _isAnsiSequence;
|
|
5
|
+
exports._isAnsi16ColorValue = _isAnsi16ColorValue;
|
|
6
|
+
exports._isCSS16Color = _isCSS16Color;
|
|
7
|
+
exports._css16ToHex = _css16ToHex;
|
|
8
|
+
const non_primitives_1 = require("../guards/non-primitives");
|
|
9
|
+
const primitives_1 = require("../guards/primitives");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
/**
|
|
12
|
+
* * Extract the CSS color name from a background-prefixed style key.
|
|
13
|
+
*
|
|
14
|
+
* @param bgColor Style key starting with `bg` (e.g. `"bgRed"`).
|
|
15
|
+
* @returns Extracted CSS color name.
|
|
16
|
+
*/
|
|
17
|
+
function _extractColorName(bgColor) {
|
|
18
|
+
return bgColor.slice(2).toLowerCase();
|
|
19
|
+
}
|
|
20
|
+
/** * Check if a string represents a valid `AnsiSequence`. */
|
|
21
|
+
function _isAnsiSequence(seq) {
|
|
22
|
+
return ((0, non_primitives_1.isArrayOfType)(seq, primitives_1.isString) &&
|
|
23
|
+
seq?.length === 2 &&
|
|
24
|
+
(seq[0].startsWith('\x1b[48') || seq[0].startsWith('\x1b[38')) &&
|
|
25
|
+
(seq[1].startsWith('\x1b[49') || seq[1].startsWith('\x1b[39')));
|
|
26
|
+
}
|
|
27
|
+
/** * Check if a value represents a valid `Ansi16Value`. */
|
|
28
|
+
function _isAnsi16ColorValue(value) {
|
|
29
|
+
return ((0, non_primitives_1.isArrayOfType)(value, primitives_1.isNumber) &&
|
|
30
|
+
value?.length === 2 &&
|
|
31
|
+
value[0] >= 30 &&
|
|
32
|
+
value[0] <= 107 &&
|
|
33
|
+
(value[1] === 39 || value[1] === 49));
|
|
34
|
+
}
|
|
35
|
+
/** * Check if a value represents a valid `CSS16Color` against `Ansi16Value`. */
|
|
36
|
+
function _isCSS16Color(value) {
|
|
37
|
+
return value?.startsWith('css-') && value?.replace('css-', '') in constants_1.CSS_16_COLORS;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* * Convert a `CSS16Color` value in `Hex6` format
|
|
41
|
+
*
|
|
42
|
+
* @param value `CSS16Color` value to convert
|
|
43
|
+
* @returns Converted `CSS16Color` value in `Hex6` format
|
|
44
|
+
*/
|
|
45
|
+
function _css16ToHex(value) {
|
|
46
|
+
return constants_1.CSS_16_COLORS?.[value?.replace('css-', '')];
|
|
47
|
+
}
|