cafe-utility 10.4.0 → 10.5.0
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/index.d.ts +4 -0
- package/index.js +15 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ declare function getFirstDeep(object: CafeObject, paths: string[], fallbackToAny
|
|
|
36
36
|
declare function forever(callable: (() => Promise<void>) | (() => void), millis: number): Promise<never>;
|
|
37
37
|
declare function asMegabytes(number: number): number;
|
|
38
38
|
declare function convertBytes(bytes: number): string;
|
|
39
|
+
declare function hexToRgb(hex: string): [number, number, number];
|
|
40
|
+
declare function rgbToHex(rgb: [number, number, number]): string;
|
|
39
41
|
declare function isObject(value: any): value is object;
|
|
40
42
|
declare function isStrictlyObject(value: any): value is object;
|
|
41
43
|
declare function isEmptyArray(value: any): boolean;
|
|
@@ -400,6 +402,8 @@ export declare const Numbers: {
|
|
|
400
402
|
parseIntOrThrow: typeof parseIntOrThrow;
|
|
401
403
|
asMegabytes: typeof asMegabytes;
|
|
402
404
|
convertBytes: typeof convertBytes;
|
|
405
|
+
hexToRgb: typeof hexToRgb;
|
|
406
|
+
rgbToHex: typeof rgbToHex;
|
|
403
407
|
};
|
|
404
408
|
export declare const Promises: {
|
|
405
409
|
raceFulfilled: typeof raceFulfilled;
|
package/index.js
CHANGED
|
@@ -310,6 +310,18 @@ function convertBytes(bytes) {
|
|
|
310
310
|
return bytes + ' B'
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
+
function hexToRgb(hex) {
|
|
314
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex.toLowerCase())
|
|
315
|
+
if (!result) {
|
|
316
|
+
throw new Error('Invalid hex color: ' + hex)
|
|
317
|
+
}
|
|
318
|
+
return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)]
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function rgbToHex(rgb) {
|
|
322
|
+
return '#' + rgb.map(x => x.toString(16).padStart(2, '0')).join('')
|
|
323
|
+
}
|
|
324
|
+
|
|
313
325
|
function isObject(value) {
|
|
314
326
|
if (!value) {
|
|
315
327
|
return false
|
|
@@ -2454,7 +2466,9 @@ exports.Numbers = {
|
|
|
2454
2466
|
format: formatNumber,
|
|
2455
2467
|
parseIntOrThrow,
|
|
2456
2468
|
asMegabytes,
|
|
2457
|
-
convertBytes
|
|
2469
|
+
convertBytes,
|
|
2470
|
+
hexToRgb,
|
|
2471
|
+
rgbToHex
|
|
2458
2472
|
}
|
|
2459
2473
|
|
|
2460
2474
|
exports.Promises = {
|