nhb-toolbox 4.20.92 → 4.21.1
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 +70 -60
- package/dist/cjs/colors/Color.js +25 -23
- package/dist/cjs/date/Chronos.js +58 -56
- package/dist/cjs/number/convert.js +2 -2
- package/dist/cjs/utils/stylog.js +3 -1
- package/dist/dts/date/Chronos.d.ts +1 -1
- package/dist/dts/number/convert.d.ts +11 -11
- package/dist/dts/number/types.d.ts +28 -44
- package/dist/esm/colors/Color.js +25 -23
- package/dist/esm/date/Chronos.js +58 -56
- package/dist/esm/number/convert.js +3 -3
- package/dist/esm/utils/stylog.js +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,132 +6,142 @@ All notable changes to the package will be documented here.
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [4.21.1] - 2025-10-13
|
|
10
|
+
|
|
11
|
+
- **Updated** `TypeScript` compiler target from `ESNext` to `ES2023` for *more stable and predictable* `JavaScript` output.
|
|
12
|
+
- *Ensures consistent syntax across `TypeScript` versions.*
|
|
13
|
+
|
|
14
|
+
## [4.21.0] - 2025-10-12
|
|
15
|
+
|
|
16
|
+
- **Renamed** `RomanNumeralCap` type to `RomanCapital` and allow only strict `1-3999` and `RomanNumeral` type to `LooseRomanNumeral`.
|
|
17
|
+
- **Removed** all *Roman numeral type helpers* and **recreated** a *strict* `RomanNumeral` with other *internal types*.
|
|
18
|
+
|
|
9
19
|
## [4.20.92] - 2025-10-12
|
|
10
20
|
|
|
11
|
-
- **Fixed** `RomanNumeralCap` type and **added**
|
|
21
|
+
- **Fixed** `RomanNumeralCap` type and **added** *@remarks* section.
|
|
12
22
|
|
|
13
23
|
## [4.20.91] - 2025-10-12
|
|
14
24
|
|
|
15
|
-
- **Updated**
|
|
25
|
+
- **Updated** *tsdoc* for `fromNow()` `Chronos` method: modified *@remarks* section.
|
|
16
26
|
|
|
17
27
|
## [4.20.90] - 2025-10-12
|
|
18
28
|
|
|
19
|
-
- **Updated** `formatUnitWithPlural` utility: now returns
|
|
29
|
+
- **Updated** `formatUnitWithPlural` utility: now returns *singular unit* for both `0` and `1`.
|
|
20
30
|
- **Updated** `fromNow()` `Chronos` method: **fixed** issues when provided unit level value is `0`.
|
|
21
31
|
|
|
22
32
|
## [4.20.89] - 2025-10-12
|
|
23
33
|
|
|
24
|
-
- **Updated** behavior of `fromNow()` `Chronos` method:
|
|
34
|
+
- **Updated** behavior of `fromNow()` `Chronos` method: *excluded* `week` level and *included* `millisecond` for consistency. **Refactored** *internal logic*.
|
|
25
35
|
|
|
26
36
|
## [4.20.88] - 2025-10-11
|
|
27
37
|
|
|
28
|
-
- **Added** new utility `romanToInteger` and its
|
|
29
|
-
- **Added** new
|
|
38
|
+
- **Added** new utility `romanToInteger` and its *aliases* to convert *Roman numerals* to *Arabic numeric* representation and **updated** *input validation* for `convertToRomanNumerals`.
|
|
39
|
+
- **Added** new *utility type* `Repeat` to repeat literal string, it works like `String.prototype.repeat()` but on *type-level*.
|
|
30
40
|
|
|
31
41
|
## [4.20.87] - 2025-10-08
|
|
32
42
|
|
|
33
|
-
- **Added** new
|
|
43
|
+
- **Added** new *constants* and *types* related to *country information*, e.g. *full country name, code, ISO code* etc.
|
|
34
44
|
|
|
35
45
|
## [4.20.86] - 2025-10-08
|
|
36
46
|
|
|
37
|
-
- **Added** new
|
|
47
|
+
- **Added** new *number utility* `getFactors` and its alias to calculate *factors* of a given number (*integer*).
|
|
38
48
|
|
|
39
49
|
## [4.20.84] - 2025-10-07
|
|
40
50
|
|
|
41
|
-
- **Added** new
|
|
51
|
+
- **Added** new *number utility* `factorial` and its alias to calculate *factorial* of a given number (*integer*).
|
|
42
52
|
|
|
43
53
|
## [4.20.80] - 2025-10-07
|
|
44
54
|
|
|
45
55
|
### 🕧 Updates in Chronos
|
|
46
56
|
|
|
47
|
-
- **Added**
|
|
48
|
-
- **Fixed** issues with `isBusinessHour`: previously skipped
|
|
49
|
-
- **Added** new
|
|
57
|
+
- **Added** *overload signatures* for `isWeekend`, `isWorkDay` and `isBusinessHour` methods from `businessPlugin`.
|
|
58
|
+
- **Fixed** issues with `isBusinessHour`: previously skipped *business start and end hours* in some cases.
|
|
59
|
+
- **Added** new *utility type* `RangeTuple` to create *ranged tuple*.
|
|
50
60
|
|
|
51
61
|
## [4.20.69-70] - 2025-10-07
|
|
52
62
|
|
|
53
63
|
### 🕧 Updates in Chronos
|
|
54
64
|
|
|
55
|
-
- **Added**
|
|
56
|
-
- **Updated** behaviors of `isWeekend`, `isWorkDay` and `isBusinessHour` methods from `businessPlugin`, now accepts
|
|
57
|
-
- **Updated**
|
|
65
|
+
- **Added** *alias* for some methods available through *plugins*: `greet` for `getGreeting`, `getSeasonName` for `season`, `zodiac` for `getZodiacSign`
|
|
66
|
+
- **Updated** behaviors of `isWeekend`, `isWorkDay` and `isBusinessHour` methods from `businessPlugin`, now accepts *indices of weekend day as tuple*.
|
|
67
|
+
- **Updated** *internal states* for most of the plugins; **Renamed** some internal *types* and *exposed* some.
|
|
58
68
|
|
|
59
69
|
## [4.20.66] - 2025-10-05
|
|
60
70
|
|
|
61
|
-
- **Updated** `isObjectWithKeys`: now returns more
|
|
71
|
+
- **Updated** `isObjectWithKeys`: now returns more *structured object shape* with provided keys.
|
|
62
72
|
|
|
63
73
|
## [4.20.64] - 2025-10-05
|
|
64
74
|
|
|
65
|
-
- **Updated** `extractObjectKeys`: now have
|
|
66
|
-
- **Updated** `extractObjectKeysDeep` no longer returns a
|
|
75
|
+
- **Updated** `extractObjectKeys`: now have *overload signatures*, returns a *tuple* or an *array of keys* (string literal).
|
|
76
|
+
- **Updated** `extractObjectKeysDeep` no longer returns a *tuple*, instead now it returns an *array of keys* (string literal).
|
|
67
77
|
|
|
68
78
|
## [4.20.60] - 2025-10-04
|
|
69
79
|
|
|
70
|
-
- **Added** new
|
|
71
|
-
- **Updated** the
|
|
72
|
-
- **Added** new utility `extractObjectKeysDeep` to extract
|
|
73
|
-
- **Updated**
|
|
74
|
-
- **Added** new utility `literalQueryStringToObject` to parse
|
|
80
|
+
- **Added** new *utility types* `ArrayToTuple<T[]>` and `Tuple<T>`.
|
|
81
|
+
- **Updated** the *return type* of `extractObjectKeys`, now it returns *tuple of exact top-level keys*.
|
|
82
|
+
- **Added** new utility `extractObjectKeysDeep` to extract *tuple* of *all nested keys*.
|
|
83
|
+
- **Updated** *query string parser* utilities to receive *generic return type*.
|
|
84
|
+
- **Added** new utility `literalQueryStringToObject` to parse *literal query string*.
|
|
75
85
|
|
|
76
86
|
## [4.20.56] - 2025-10-02
|
|
77
87
|
|
|
78
|
-
- **Updated** `isDeepEqual` utility: Now it accepts
|
|
88
|
+
- **Updated** `isDeepEqual` utility: Now it accepts *arguments of unknown types*.
|
|
79
89
|
|
|
80
90
|
## [4.20.54] - 2025-10-02
|
|
81
91
|
|
|
82
|
-
- **Added** new utility `extractObjectKeys` to
|
|
83
|
-
- **Updated** `isObjectWithKeys`:
|
|
92
|
+
- **Added** new utility `extractObjectKeys` to *extract keys of an object* with *proper typing*.
|
|
93
|
+
- **Updated** `isObjectWithKeys`: *now properly typed*.
|
|
84
94
|
|
|
85
95
|
## [4.20.52] - 2025-09-26
|
|
86
96
|
|
|
87
|
-
- **Added** new `Chronos`
|
|
88
|
-
- **Fixed** some
|
|
97
|
+
- **Added** new `Chronos` *plugin* `greetingPlugin` for accessing `getGreeting` method in `Chronos` instances.
|
|
98
|
+
- **Fixed** some *docs and internal type related issues* in `convertObjectValues` utility.
|
|
89
99
|
|
|
90
100
|
## [4.20.50] - 2025-09-25
|
|
91
101
|
|
|
92
|
-
- **Fixed**
|
|
93
|
-
- **Updated**
|
|
102
|
+
- **Fixed** *return type* of `convertObjectValues` utility to correctly reflect the *transformed object structure* and `keys` option is now *more strict*: **only accepts keys which values are string and/or number** and **the array cannot be left empty**.
|
|
103
|
+
- **Updated** *options type* for `with()` *static method* of `Chronos`.
|
|
94
104
|
|
|
95
105
|
## [4.20.48] - 2025-09-22
|
|
96
106
|
|
|
97
|
-
- **Wrapped** `ChronosMethods` type in `LooseLiteral` to allow passing
|
|
98
|
-
- **Updated**
|
|
107
|
+
- **Wrapped** `ChronosMethods` type in `LooseLiteral` to allow passing *custom method names* without *type errors* when creating a custom [`Chronos Plugin`](https://toolbox.nazmul-nhb.dev/docs/classes/Chronos/plugins#%EF%B8%8F-writing-your-own-custom-plugin).
|
|
108
|
+
- **Updated** *error message* in `convert` method in `Currency` class.
|
|
99
109
|
|
|
100
110
|
## [4.20.46] - 2025-09-22
|
|
101
111
|
|
|
102
|
-
- `Chronos` class is now
|
|
112
|
+
- `Chronos` class is now *exported via subpath* `'nhb-toolbox/chronos'`.
|
|
103
113
|
|
|
104
114
|
## [4.20.44] - 2025-09-20
|
|
105
115
|
|
|
106
|
-
- **Updated** type related issues in `Finder` class. Now it accepts
|
|
116
|
+
- **Updated** type related issues in `Finder` class. Now it accepts *array of objects only*.
|
|
107
117
|
|
|
108
118
|
## [4.20.40] - 2025-09-18
|
|
109
119
|
|
|
110
|
-
- **Added** new **utility types**: `DeepPartialAll`, `Join`,`Split` along with `ValidArray`, `List` and
|
|
120
|
+
- **Added** new **utility types**: `DeepPartialAll`, `Join`,`Split` along with `ValidArray`, `List` and *more*.
|
|
111
121
|
|
|
112
122
|
## [4.20.32] - 2025-09-17
|
|
113
123
|
|
|
114
124
|
- **Renamed** `isPastParticiple()` method to `isParticiple()` in `Verbalizer/verbalizer`.
|
|
115
|
-
- **Optimized**
|
|
116
|
-
- **Updated** all the
|
|
125
|
+
- **Optimized** *internal logic* for `toPast()` and `toParticiple()` methods in `Verbalizer/verbalizer`.
|
|
126
|
+
- **Updated** all the *rules* for `Verbalizer/verbalizer`.
|
|
117
127
|
|
|
118
128
|
## [4.20.30] - 2025-09-17
|
|
119
129
|
|
|
120
|
-
- **Reduced**
|
|
130
|
+
- **Reduced** *unpacked size* by **removing** *tsdoc comments* from js (both `cjs` and `esm`) outputs.
|
|
121
131
|
- **Updated** tsdoc for `Verbalizer/verbalizer`: **added** reference to documentation site.
|
|
122
132
|
|
|
123
133
|
## [4.20.27] - 2025-09-16
|
|
124
134
|
|
|
125
|
-
- **Fixed**
|
|
135
|
+
- **Fixed** *issues*: (**failed to convert already past/participle regular verbs**) with `toPast()` and `toParticiple()` methods in `Verbalizer/verbalizer`.
|
|
126
136
|
|
|
127
137
|
## [4.20.26] - 2025-09-16
|
|
128
138
|
|
|
129
|
-
- **Optimized**
|
|
139
|
+
- **Optimized** *internal logic* in both `Pluralizer` and `Verbalizer`.
|
|
130
140
|
|
|
131
141
|
## [4.20.24] - 2025-09-15
|
|
132
142
|
|
|
133
143
|
- **Added** new class `Verbalizer` and its shared instance `verbalizer` for verb form(s) manipulation.
|
|
134
|
-
- **Updated** `Pluralizer/pluralizer`'s
|
|
144
|
+
- **Updated** `Pluralizer/pluralizer`'s *internal mechanism* to *trim* input(s) and output(s).
|
|
135
145
|
|
|
136
146
|
## [4.20.20] - 2025-09-04
|
|
137
147
|
|
|
@@ -146,26 +156,26 @@ All notable changes to the package will be documented here.
|
|
|
146
156
|
|
|
147
157
|
## [4.20.17] - 2025-09-02
|
|
148
158
|
|
|
149
|
-
- **Added**
|
|
159
|
+
- **Added** *color support detector* for shell/console for `Stylog`/`LogStyler`.
|
|
150
160
|
|
|
151
161
|
## [4.20.16] - 2025-09-01
|
|
152
162
|
|
|
153
|
-
- **Added** new method `string()` in `LogStyler` (also in `Stylog`) and **made** `applyStyles()` method
|
|
163
|
+
- **Added** new method `string()` in `LogStyler` (also in `Stylog`) and **made** `applyStyles()` method *public*.
|
|
154
164
|
|
|
155
165
|
## [4.20.11] - 2025-09-01
|
|
156
166
|
|
|
157
|
-
- **Added** new
|
|
158
|
-
- **Fixed** string coercion issues with `toPrimitive`
|
|
159
|
-
- **Redesigned** `chronos` (`Chronos` wrapper) with
|
|
167
|
+
- **Added** new *Symbol* methods in `Chronos`: `Symbol.isConcatSpreadable` and `Symbol.match`.
|
|
168
|
+
- **Fixed** string coercion issues with `toPrimitive` *Symbol* method in `Chronos`.
|
|
169
|
+
- **Redesigned** `chronos` (`Chronos` wrapper) with *Proxy* and **updated** *TSDoc* for `chronos`.
|
|
160
170
|
|
|
161
171
|
## [4.20.10] - 2025-09-01
|
|
162
172
|
|
|
163
|
-
- **Added** new
|
|
164
|
-
- **Added** new
|
|
173
|
+
- **Added** new *utility types*: `RequireAtLeast`, `RequireExactly`, `RequireBetween`.
|
|
174
|
+
- **Added** new *static* `Chronos` method `Chronos.with(options)` to create `Chronos` instance from specified *time component(s)*.
|
|
165
175
|
|
|
166
176
|
## [4.20.1] - 2025-08-31
|
|
167
177
|
|
|
168
|
-
- **Exported**
|
|
178
|
+
- **Exported** *helper function and guards* used for `Stylog` and `LogStyler`: `hexToAnsi`, `isCSSColor`, `isBGColor`, `isTextStyle`.
|
|
169
179
|
|
|
170
180
|
## [4.20.0] - 2025-08-31
|
|
171
181
|
|
|
@@ -173,8 +183,8 @@ All notable changes to the package will be documented here.
|
|
|
173
183
|
|
|
174
184
|
## [4.14.16] - 2025-08-30
|
|
175
185
|
|
|
176
|
-
- **Updated**
|
|
177
|
-
- **Made** all the (output) properties of `FlattenDotValue` and `FlattenLeafValue`
|
|
186
|
+
- **Updated** *types* related to *object flattening utilities*: `FlattenDotKey`, `DotValue`, `FlattenDotValue`, `FlattenLeafKey`, `LeafValue` and `FlattenLeafValue`.
|
|
187
|
+
- **Made** all the (output) properties of `FlattenDotValue` and `FlattenLeafValue` *optional* to avoid issues.
|
|
178
188
|
|
|
179
189
|
## [4.14.14] - 2025-08-27
|
|
180
190
|
|
|
@@ -182,11 +192,11 @@ All notable changes to the package will be documented here.
|
|
|
182
192
|
|
|
183
193
|
## [4.14.13] - 2025-08-24
|
|
184
194
|
|
|
185
|
-
- **Updated**
|
|
195
|
+
- **Updated** *return type* for `getColorForInitial` utility and **improved** *internal logic* and *error type* for color generator utilities.
|
|
186
196
|
|
|
187
197
|
## [4.14.12] - 2025-08-23
|
|
188
198
|
|
|
189
|
-
- **Updated**
|
|
199
|
+
- **Updated** *error type* for `trimString` utility.
|
|
190
200
|
|
|
191
201
|
## [4.14.10] - 2025-08-17
|
|
192
202
|
|
|
@@ -194,12 +204,12 @@ All notable changes to the package will be documented here.
|
|
|
194
204
|
|
|
195
205
|
## [4.14.9] - 2025-08-16
|
|
196
206
|
|
|
197
|
-
- **Fixed** minor
|
|
207
|
+
- **Fixed** minor *internal issues* and **updated** JSDoc for `Pluralizer`.
|
|
198
208
|
|
|
199
209
|
## [4.14.4-8] - 2025-08-13 - 2025-08-14
|
|
200
210
|
|
|
201
211
|
- **Updated** internal logic of `convertStringCase` utility, added new `options` parameter.
|
|
202
|
-
- **Fixed** multiple
|
|
212
|
+
- **Fixed** multiple *internal issues* and JSDoc; Optimized internal logic.
|
|
203
213
|
|
|
204
214
|
## [4.14.1-3] - 2025-08-11 - 2025-08-12
|
|
205
215
|
|
|
@@ -211,7 +221,7 @@ All notable changes to the package will be documented here.
|
|
|
211
221
|
|
|
212
222
|
## [4.13.11] - 2025-08-06
|
|
213
223
|
|
|
214
|
-
- **Fixed** an issue with `getZodiacSign` method in `Chronos` that could not return correct
|
|
224
|
+
- **Fixed** an issue with `getZodiacSign` method in `Chronos` that could not return correct *Vedic* sign.
|
|
215
225
|
|
|
216
226
|
## [4.13.10] - 2025-08-02
|
|
217
227
|
|
|
@@ -235,7 +245,7 @@ All notable changes to the package will be documented here.
|
|
|
235
245
|
|
|
236
246
|
## [4.13.3] - 2025-07-22
|
|
237
247
|
|
|
238
|
-
- **Updated**
|
|
248
|
+
- **Updated** *pluralization/uncountable rules*, *case restoration method* and fixed other bugs in `pluralizer`.
|
|
239
249
|
- **Updated** docs for `pluralizer`, `Pluralizer` and `formatUnitWithPlural`.
|
|
240
250
|
|
|
241
251
|
## [4.13.1] - 2025-07-22
|
|
@@ -378,7 +388,7 @@ All notable changes to the package will be documented here.
|
|
|
378
388
|
|
|
379
389
|
### 🕧 Updates for Chronos
|
|
380
390
|
|
|
381
|
-
- **Reduced** bloat by moving
|
|
391
|
+
- **Reduced** bloat by moving *rarely used* `Chronos` methods to plugin system.
|
|
382
392
|
- **Changed** plugin import paths as `import { somePlugin } from nhb-toolbox/plugins/somePlugin` format so the users can assume the path easily.
|
|
383
393
|
- **Updated** parameter type for `isBusinessHour` method: instead of multiple parameters can accept one options object now.
|
|
384
394
|
|
|
@@ -386,7 +396,7 @@ All notable changes to the package will be documented here.
|
|
|
386
396
|
|
|
387
397
|
### 🕧 Updates for Chronos
|
|
388
398
|
|
|
389
|
-
- All
|
|
399
|
+
- All *plugin* imports now use statement like `import { somePlugin } from 'nhb-toolbox/plugins/plugin-path';`
|
|
390
400
|
- **Updated** `getZodiacSign` method: includes 2 presets `western` and `vedic` with aliases `tropical` and `sidereal`.
|
|
391
401
|
- **Fixed** issues in `getZodiacSign` method which previously could not parse some date/month range.
|
|
392
402
|
|
|
@@ -485,5 +495,5 @@ All notable changes to the package will be documented here.
|
|
|
485
495
|
### Improved
|
|
486
496
|
|
|
487
497
|
- 🌲 Full **tree-shaking support** for ESM builds (CommonJS remains unaffected).
|
|
488
|
-
- 🌲
|
|
498
|
+
- 🌲 *From the beginning the library was tree-shakable* but now it's **properly tree-shakable** for ESM builds.
|
|
489
499
|
- 📦 CommonJS (`cjs`) build remains unaffected and stable.
|
package/dist/cjs/colors/Color.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.Color = void 0;
|
|
4
5
|
const convert_1 = require("./convert");
|
|
@@ -15,8 +16,8 @@ class Color {
|
|
|
15
16
|
hsla;
|
|
16
17
|
constructor(color) {
|
|
17
18
|
if (color) {
|
|
18
|
-
if (
|
|
19
|
-
const newColor = new
|
|
19
|
+
if (_a.isCSSColor(color)) {
|
|
20
|
+
const newColor = new _a(css_colors_1.CSS_COLORS[color?.trim()]);
|
|
20
21
|
this.hex = newColor.hex;
|
|
21
22
|
this.hex8 = newColor.hex8;
|
|
22
23
|
this.rgb = newColor.rgb;
|
|
@@ -76,7 +77,7 @@ class Color {
|
|
|
76
77
|
const alphaDecimal = validOpacity / 100;
|
|
77
78
|
const rgbValues = (0, utils_1.extractSolidColorValues)(this.rgb);
|
|
78
79
|
const hslValues = (0, utils_1.extractSolidColorValues)(this.hsl);
|
|
79
|
-
return
|
|
80
|
+
return _a.#fromParts({
|
|
80
81
|
hex: this.hex.slice(0, 7).toUpperCase(),
|
|
81
82
|
hex8: `${this.hex.slice(0, 7)}${alphaHex}`.toUpperCase(),
|
|
82
83
|
rgb: `rgb(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]})`,
|
|
@@ -89,30 +90,30 @@ class Color {
|
|
|
89
90
|
const [h, s, l, a] = (0, utils_1.extractAlphaColorValues)(this.hsla);
|
|
90
91
|
const newL = Math.max(0, l - percent);
|
|
91
92
|
const newHSL = `hsl(${h}, ${s}%, ${newL}%)`;
|
|
92
|
-
return new
|
|
93
|
+
return new _a(newHSL).applyOpacity((a * 100));
|
|
93
94
|
}
|
|
94
95
|
applyBrightness(percent) {
|
|
95
96
|
const [h, s, l, a] = (0, utils_1.extractAlphaColorValues)(this.hsla);
|
|
96
97
|
const newL = Math.min(100, l + percent);
|
|
97
98
|
const newHSL = `hsl(${h}, ${s}%, ${newL}%)`;
|
|
98
|
-
return new
|
|
99
|
+
return new _a(newHSL).applyOpacity((a * 100));
|
|
99
100
|
}
|
|
100
101
|
applyDullness(percent) {
|
|
101
102
|
const [h, s, l, a] = (0, utils_1.extractAlphaColorValues)(this.hsla);
|
|
102
103
|
const newS = Math.max(0, s - percent);
|
|
103
104
|
const newHSL = `hsl(${h}, ${newS}%, ${l}%)`;
|
|
104
|
-
return new
|
|
105
|
+
return new _a(newHSL).applyOpacity((a * 100));
|
|
105
106
|
}
|
|
106
107
|
applyWhiteShade(percent) {
|
|
107
108
|
const [h, s, l, a] = (0, utils_1.extractAlphaColorValues)(this.hsla);
|
|
108
109
|
const newS = Math.max(0, s - (s * percent) / 100);
|
|
109
110
|
const newL = Math.min(100, l + ((100 - l) * percent) / 100);
|
|
110
111
|
const newHSL = `hsl(${h}, ${newS}%, ${newL}%)`;
|
|
111
|
-
return new
|
|
112
|
+
return new _a(newHSL).applyOpacity((a * 100));
|
|
112
113
|
}
|
|
113
114
|
blendWith(other, weight = 0.5) {
|
|
114
115
|
const w = Math.max(0, Math.min(1, weight));
|
|
115
|
-
const converted =
|
|
116
|
+
const converted = _a.isCSSColor(other) ? new _a(other) : new _a(other);
|
|
116
117
|
const [r1, b1, g1, a1] = (0, utils_1.extractAlphaColorValues)(this.rgba);
|
|
117
118
|
const [r2, b2, g2, a2] = (0, utils_1.extractAlphaColorValues)(converted.rgba);
|
|
118
119
|
const alpha = Math.round((a1 * (1 - w) + a2 * w) * 100) / 100;
|
|
@@ -123,10 +124,10 @@ class Color {
|
|
|
123
124
|
const g = blendChannel(g1, g2);
|
|
124
125
|
const b = blendChannel(b1, b2);
|
|
125
126
|
const blended = `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
126
|
-
return new
|
|
127
|
+
return new _a(blended);
|
|
127
128
|
}
|
|
128
129
|
contrastRatio(other) {
|
|
129
|
-
const newColor =
|
|
130
|
+
const newColor = _a.isCSSColor(other) ? new _a(other) : new _a(other);
|
|
130
131
|
const luminance = (rgb) => {
|
|
131
132
|
const [r, g, b] = (0, utils_1.extractSolidColorValues)(rgb).map((v) => {
|
|
132
133
|
const c = v / 255;
|
|
@@ -145,20 +146,20 @@ class Color {
|
|
|
145
146
|
const [h, s, l, a] = (0, utils_1.extractAlphaColorValues)(this.hsla);
|
|
146
147
|
const newHue = (h + 180) % 360;
|
|
147
148
|
const newHSL = `hsl(${newHue}, ${s}%, ${l}%)`;
|
|
148
|
-
return new
|
|
149
|
+
return new _a(newHSL).applyOpacity((a * 100));
|
|
149
150
|
}
|
|
150
151
|
getAnalogousColors() {
|
|
151
152
|
const [h, s, l, a] = (0, utils_1.extractAlphaColorValues)(this.hsla);
|
|
152
153
|
const left = `hsl(${(h + 330) % 360}, ${s}%, ${l}%)`;
|
|
153
154
|
const right = `hsl(${(h + 30) % 360}, ${s}%, ${l}%)`;
|
|
154
|
-
const analogous = [this, new
|
|
155
|
+
const analogous = [this, new _a(left), new _a(right)];
|
|
155
156
|
return analogous.map((c) => c.applyOpacity((a * 100)));
|
|
156
157
|
}
|
|
157
158
|
getTriadColors() {
|
|
158
159
|
const [h, s, l, a] = (0, utils_1.extractAlphaColorValues)(this.hsla);
|
|
159
160
|
const c1 = `hsl(${(h + 120) % 360}, ${s}%, ${l}%)`;
|
|
160
161
|
const c2 = `hsl(${(h + 240) % 360}, ${s}%, ${l}%)`;
|
|
161
|
-
const triad = [this, new
|
|
162
|
+
const triad = [this, new _a(c1), new _a(c2)];
|
|
162
163
|
return triad.map((c) => c.applyOpacity((a * 100)));
|
|
163
164
|
}
|
|
164
165
|
getTetradColors() {
|
|
@@ -166,7 +167,7 @@ class Color {
|
|
|
166
167
|
const c1 = `hsl(${(h + 90) % 360}, ${s}%, ${l}%)`;
|
|
167
168
|
const c2 = `hsl(${(h + 180) % 360}, ${s}%, ${l}%)`;
|
|
168
169
|
const c3 = `hsl(${(h + 270) % 360}, ${s}%, ${l}%)`;
|
|
169
|
-
const tetrad = [this, new
|
|
170
|
+
const tetrad = [this, new _a(c1), new _a(c2), new _a(c3)];
|
|
170
171
|
return tetrad.map((c) => c.applyOpacity((a * 100)));
|
|
171
172
|
}
|
|
172
173
|
getWCAGRating(other) {
|
|
@@ -201,8 +202,8 @@ class Color {
|
|
|
201
202
|
return (0, helpers_1._isHSLA)(color);
|
|
202
203
|
}
|
|
203
204
|
static isCSSColor(color) {
|
|
204
|
-
return (!
|
|
205
|
-
!
|
|
205
|
+
return (!_a.isHex6(color) &&
|
|
206
|
+
!_a.isHex8(color) &&
|
|
206
207
|
!(0, helpers_1._isRGB)(color) &&
|
|
207
208
|
!(0, helpers_1._isRGBA)(color) &&
|
|
208
209
|
!(0, helpers_1._isHSL)(color) &&
|
|
@@ -210,27 +211,27 @@ class Color {
|
|
|
210
211
|
color in css_colors_1.CSS_COLORS);
|
|
211
212
|
}
|
|
212
213
|
#convertColorToOthers(color) {
|
|
213
|
-
if (
|
|
214
|
+
if (_a.isHex6(color)) {
|
|
214
215
|
const { rgb, hsl } = (0, convert_1.convertColorCode)(color);
|
|
215
216
|
return { hex: color, rgb, hsl };
|
|
216
217
|
}
|
|
217
|
-
else if (
|
|
218
|
+
else if (_a.isRGB(color)) {
|
|
218
219
|
const { hex, hsl } = (0, convert_1.convertColorCode)(color);
|
|
219
220
|
return { hex, rgb: color, hsl };
|
|
220
221
|
}
|
|
221
|
-
else if (
|
|
222
|
+
else if (_a.isHSL(color)) {
|
|
222
223
|
const { hex, rgb } = (0, convert_1.convertColorCode)(color);
|
|
223
224
|
return { hex, rgb, hsl: color };
|
|
224
225
|
}
|
|
225
|
-
else if (
|
|
226
|
+
else if (_a.isHex8(color)) {
|
|
226
227
|
const { rgba, hsla } = (0, convert_1.convertColorCode)(color);
|
|
227
228
|
return { hex8: color, rgba, hsla };
|
|
228
229
|
}
|
|
229
|
-
else if (
|
|
230
|
+
else if (_a.isRGBA(color)) {
|
|
230
231
|
const { hex8, hsla } = (0, convert_1.convertColorCode)(color);
|
|
231
232
|
return { hex8, rgba: color, hsla };
|
|
232
233
|
}
|
|
233
|
-
else if (
|
|
234
|
+
else if (_a.isHSLA(color)) {
|
|
234
235
|
const { hex8, rgba } = (0, convert_1.convertColorCode)(color);
|
|
235
236
|
return { hex8, rgba, hsla: color };
|
|
236
237
|
}
|
|
@@ -239,7 +240,7 @@ class Color {
|
|
|
239
240
|
});
|
|
240
241
|
}
|
|
241
242
|
static #fromParts(parts) {
|
|
242
|
-
const color = Object.create(
|
|
243
|
+
const color = Object.create(_a.prototype);
|
|
243
244
|
color.hex = parts.hex;
|
|
244
245
|
color.hex8 = parts.hex8;
|
|
245
246
|
color.rgb = parts.rgb;
|
|
@@ -250,3 +251,4 @@ class Color {
|
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
exports.Color = Color;
|
|
254
|
+
_a = Color;
|