cafe-utility 10.4.0 → 10.6.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.
Files changed (3) hide show
  1. package/index.d.ts +4 -0
  2. package/index.js +18 -3
  3. 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
@@ -1565,7 +1577,7 @@ function fromObjectString(string) {
1565
1577
  return JSON.parse(string)
1566
1578
  }
1567
1579
 
1568
- const thresholds = [1e3, 1e6, 1e9, 1e12, 1e15, 1e18, 1e21, 1e24, 1e27, 1e30, 1e16, 1e18, 1e18, 1e18, 1e33]
1580
+ const thresholds = [1e3, 1e6, 1e9, 1e12, 1e15, 1e18, 1e21, 1e24, 1e27, 1e30, 1e9, 1e16, 1e18, 1e18, 1e18, 1e33]
1569
1581
  const longNumberUnits = [
1570
1582
  'thousand',
1571
1583
  'million',
@@ -1577,13 +1589,14 @@ const longNumberUnits = [
1577
1589
  'septillion',
1578
1590
  'octillion',
1579
1591
  'nonillion',
1592
+ 'gwei',
1580
1593
  'bzz',
1581
1594
  'btc',
1582
1595
  'eth',
1583
1596
  'dai',
1584
1597
  'decillion'
1585
1598
  ]
1586
- const shortNumberUnits = ['K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'O', 'N', 'bzz', 'eth', 'btc', 'dai', 'D']
1599
+ const shortNumberUnits = ['K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'O', 'N', 'gwei', 'bzz', 'eth', 'btc', 'dai', 'D']
1587
1600
  function formatNumber(number, options) {
1588
1601
  var _a, _b
1589
1602
  const longFormat =
@@ -2454,7 +2467,9 @@ exports.Numbers = {
2454
2467
  format: formatNumber,
2455
2468
  parseIntOrThrow,
2456
2469
  asMegabytes,
2457
- convertBytes
2470
+ convertBytes,
2471
+ hexToRgb,
2472
+ rgbToHex
2458
2473
  }
2459
2474
 
2460
2475
  exports.Promises = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "10.4.0",
3
+ "version": "10.6.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {