@ztimson/utils 0.24.12 → 0.25.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/dist/cache.d.ts +6 -5
- package/dist/color.d.ts +1 -1
- package/dist/database.d.ts +17 -0
- package/dist/index.cjs +166 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +166 -95
- package/dist/index.mjs.map +1 -1
- package/dist/jwt.d.ts +9 -1
- package/dist/math.d.ts +2 -1
- package/dist/misc.d.ts +8 -0
- package/dist/search.d.ts +9 -0
- package/dist/types.d.ts +1 -21
- package/package.json +2 -1
package/dist/cache.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Collection } from './database.ts';
|
|
1
2
|
export type CacheOptions = {
|
|
2
3
|
/** Delete keys automatically after x amount of seconds */
|
|
3
4
|
ttl?: number;
|
|
4
5
|
/** Storage to persist cache */
|
|
5
|
-
storage?: Storage
|
|
6
|
+
storage?: Storage | Collection<any, any>;
|
|
6
7
|
/** Key cache will be stored under */
|
|
7
8
|
storageKey?: string;
|
|
8
9
|
/** Keep or delete cached items once expired, defaults to delete */
|
|
@@ -52,12 +53,12 @@ export declare class Cache<K extends string | number | symbol, T> {
|
|
|
52
53
|
/**
|
|
53
54
|
* Remove all keys from cache
|
|
54
55
|
*/
|
|
55
|
-
clear():
|
|
56
|
+
clear(): this;
|
|
56
57
|
/**
|
|
57
58
|
* Delete an item from the cache
|
|
58
59
|
* @param {K} key Item's primary key
|
|
59
60
|
*/
|
|
60
|
-
delete(key: K):
|
|
61
|
+
delete(key: K): this;
|
|
61
62
|
/**
|
|
62
63
|
* Return cache as an array of key-value pairs
|
|
63
64
|
* @return {[K, T][]} Key-value pairs array
|
|
@@ -67,13 +68,13 @@ export declare class Cache<K extends string | number | symbol, T> {
|
|
|
67
68
|
* Manually expire a cached item
|
|
68
69
|
* @param {K} key Key to expire
|
|
69
70
|
*/
|
|
70
|
-
expire(key: K):
|
|
71
|
+
expire(key: K): this;
|
|
71
72
|
/**
|
|
72
73
|
* Get item from the cache
|
|
73
74
|
* @param {K} key Key to lookup
|
|
74
75
|
* @return {T} Cached item
|
|
75
76
|
*/
|
|
76
|
-
get(key: K, expired?: boolean): T | null;
|
|
77
|
+
get(key: K, expired?: boolean): CachedValue<T> | null;
|
|
77
78
|
/**
|
|
78
79
|
* Get a list of cached keys
|
|
79
80
|
* @return {K[]} Array of keys
|
package/dist/color.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param {string} background Color to compare against
|
|
4
4
|
* @return {"white" | "black"} Color with the most contrast
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function contrast(background: string): 'white' | 'black';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class Collection<K extends IDBValidKey, T> {
|
|
2
|
+
readonly db: string;
|
|
3
|
+
readonly collection: string;
|
|
4
|
+
readonly version?: number | undefined;
|
|
5
|
+
private setup?;
|
|
6
|
+
private database;
|
|
7
|
+
constructor(db: string, collection: string, version?: number | undefined, setup?: ((db: IDBDatabase, event: IDBVersionChangeEvent) => void) | undefined);
|
|
8
|
+
tx<T>(collection: string, fn: ((store: IDBObjectStore) => IDBRequest), readonly?: boolean): Promise<T>;
|
|
9
|
+
add(value: T, key?: K): Promise<void>;
|
|
10
|
+
count(): Promise<number>;
|
|
11
|
+
put(key: K, value: T): Promise<void>;
|
|
12
|
+
getAll(): Promise<T[]>;
|
|
13
|
+
getAllKeys(): Promise<K[]>;
|
|
14
|
+
get(key: K): Promise<T>;
|
|
15
|
+
delete(key: K): Promise<void>;
|
|
16
|
+
clear(): Promise<void>;
|
|
17
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -65,7 +65,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
65
65
|
extras.push(arg);
|
|
66
66
|
continue;
|
|
67
67
|
}
|
|
68
|
-
const value = argDef.default === false ? true : argDef.default === true ? false : queue.splice(queue.findIndex((q) => q[0] != "-"), 1)[0] || argDef.default;
|
|
68
|
+
const value = combined[1] != null ? combined[1] : argDef.default === false ? true : argDef.default === true ? false : queue.splice(queue.findIndex((q) => q[0] != "-"), 1)[0] || argDef.default;
|
|
69
69
|
if (value == null) parsed["_error"].push(`Option missing value: ${argDef.name || combined[0]}`);
|
|
70
70
|
parsed[argDef.name] = value;
|
|
71
71
|
} else {
|
|
@@ -124,7 +124,7 @@ ${opts.message || this.desc}`;
|
|
|
124
124
|
function clean(obj, undefinedOnly = false) {
|
|
125
125
|
if (obj == null) throw new Error("Cannot clean a NULL value");
|
|
126
126
|
if (Array.isArray(obj)) {
|
|
127
|
-
obj = obj.filter((o) => o != null);
|
|
127
|
+
obj = obj.filter((o) => undefinedOnly ? o !== void 0 : o != null);
|
|
128
128
|
} else {
|
|
129
129
|
Object.entries(obj).forEach(([key, value]) => {
|
|
130
130
|
if (undefinedOnly && value === void 0 || !undefinedOnly && value == null) delete obj[key];
|
|
@@ -175,7 +175,6 @@ ${opts.message || this.desc}`;
|
|
|
175
175
|
for (const key of Object.keys(obj)) {
|
|
176
176
|
const propName = parent ? `${parent}.${key}` : key;
|
|
177
177
|
if (typeof obj[key] === "object" && obj[key] != null && !Array.isArray(obj[key])) {
|
|
178
|
-
console.log(propName);
|
|
179
178
|
flattenObj(obj[key], propName, result);
|
|
180
179
|
} else {
|
|
181
180
|
result[propName] = obj[key];
|
|
@@ -231,55 +230,15 @@ ${opts.message || this.desc}`;
|
|
|
231
230
|
return obj;
|
|
232
231
|
}
|
|
233
232
|
function JSONSanitize(obj, space) {
|
|
233
|
+
const cache = [];
|
|
234
234
|
return JSON.stringify(obj, (key, value) => {
|
|
235
|
+
if (typeof value === "object" && value !== null) {
|
|
236
|
+
if (cache.includes(value)) return "[Circular]";
|
|
237
|
+
cache.push(value);
|
|
238
|
+
}
|
|
235
239
|
return value;
|
|
236
240
|
}, space);
|
|
237
241
|
}
|
|
238
|
-
function addUnique(array, el) {
|
|
239
|
-
if (array.indexOf(el) === -1) array.push(el);
|
|
240
|
-
return array;
|
|
241
|
-
}
|
|
242
|
-
function arrayDiff(a, b) {
|
|
243
|
-
return makeUnique([
|
|
244
|
-
...a.filter((v1) => !b.includes((v2) => isEqual(v1, v2))),
|
|
245
|
-
...b.filter((v1) => !a.includes((v2) => isEqual(v1, v2)))
|
|
246
|
-
]);
|
|
247
|
-
}
|
|
248
|
-
function caseInsensitiveSort(prop) {
|
|
249
|
-
return function(a, b) {
|
|
250
|
-
const aVal = dotNotation(a, prop);
|
|
251
|
-
const bVal = dotNotation(b, prop);
|
|
252
|
-
if (typeof aVal !== "string" || typeof bVal !== "string") return 1;
|
|
253
|
-
return aVal.toLowerCase().localeCompare(bVal.toLowerCase());
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
function findByProp(prop, value) {
|
|
257
|
-
return (v) => isEqual(dotNotation(v, prop), value);
|
|
258
|
-
}
|
|
259
|
-
function flattenArr(arr, result = []) {
|
|
260
|
-
arr.forEach((el) => Array.isArray(el) ? flattenArr(el, result) : result.push(el));
|
|
261
|
-
return result;
|
|
262
|
-
}
|
|
263
|
-
function sortByProp(prop, reverse = false) {
|
|
264
|
-
return function(a, b) {
|
|
265
|
-
const aVal = dotNotation(a, prop);
|
|
266
|
-
const bVal = dotNotation(b, prop);
|
|
267
|
-
if (typeof aVal == "number" && typeof bVal == "number")
|
|
268
|
-
return (reverse ? -1 : 1) * (aVal - bVal);
|
|
269
|
-
if (aVal > bVal) return reverse ? -1 : 1;
|
|
270
|
-
if (aVal < bVal) return reverse ? 1 : -1;
|
|
271
|
-
return 0;
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
function makeUnique(arr) {
|
|
275
|
-
for (let i = arr.length - 1; i >= 0; i--) {
|
|
276
|
-
if (arr.slice(0, i).find((n) => isEqual(n, arr[i]))) arr.splice(i, 1);
|
|
277
|
-
}
|
|
278
|
-
return arr;
|
|
279
|
-
}
|
|
280
|
-
function makeArray(value) {
|
|
281
|
-
return Array.isArray(value) ? value : [value];
|
|
282
|
-
}
|
|
283
242
|
class ASet extends Array {
|
|
284
243
|
/** Number of elements in set */
|
|
285
244
|
get size() {
|
|
@@ -395,6 +354,102 @@ ${opts.message || this.desc}`;
|
|
|
395
354
|
return new ASet([...this, ...set]);
|
|
396
355
|
}
|
|
397
356
|
}
|
|
357
|
+
function addUnique(array, el) {
|
|
358
|
+
if (array.indexOf(el) === -1) array.push(el);
|
|
359
|
+
return array;
|
|
360
|
+
}
|
|
361
|
+
function arrayDiff(a, b) {
|
|
362
|
+
return new ASet(a).symmetricDifference(new ASet(b));
|
|
363
|
+
}
|
|
364
|
+
function caseInsensitiveSort(prop) {
|
|
365
|
+
return function(a, b) {
|
|
366
|
+
const aVal = dotNotation(a, prop);
|
|
367
|
+
const bVal = dotNotation(b, prop);
|
|
368
|
+
if (typeof aVal !== "string" || typeof bVal !== "string") return 1;
|
|
369
|
+
return aVal.toLowerCase().localeCompare(bVal.toLowerCase());
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function findByProp(prop, value) {
|
|
373
|
+
return (v) => isEqual(dotNotation(v, prop), value);
|
|
374
|
+
}
|
|
375
|
+
function flattenArr(arr, result = []) {
|
|
376
|
+
arr.forEach((el) => Array.isArray(el) ? flattenArr(el, result) : result.push(el));
|
|
377
|
+
return result;
|
|
378
|
+
}
|
|
379
|
+
function sortByProp(prop, reverse = false) {
|
|
380
|
+
return function(a, b) {
|
|
381
|
+
const aVal = dotNotation(a, prop);
|
|
382
|
+
const bVal = dotNotation(b, prop);
|
|
383
|
+
if (typeof aVal == "number" && typeof bVal == "number")
|
|
384
|
+
return (reverse ? -1 : 1) * (aVal - bVal);
|
|
385
|
+
if (aVal > bVal) return reverse ? -1 : 1;
|
|
386
|
+
if (aVal < bVal) return reverse ? 1 : -1;
|
|
387
|
+
return 0;
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function makeUnique(arr) {
|
|
391
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
392
|
+
if (arr.slice(0, i).find((n) => isEqual(n, arr[i]))) arr.splice(i, 1);
|
|
393
|
+
}
|
|
394
|
+
return arr;
|
|
395
|
+
}
|
|
396
|
+
function makeArray(value) {
|
|
397
|
+
return Array.isArray(value) ? value : [value];
|
|
398
|
+
}
|
|
399
|
+
class Collection {
|
|
400
|
+
constructor(db, collection, version, setup) {
|
|
401
|
+
__publicField(this, "database");
|
|
402
|
+
this.db = db;
|
|
403
|
+
this.collection = collection;
|
|
404
|
+
this.version = version;
|
|
405
|
+
this.setup = setup;
|
|
406
|
+
this.database = new Promise((resolve, reject) => {
|
|
407
|
+
const req = indexedDB.open(this.db, this.version);
|
|
408
|
+
req.onerror = () => reject(req.error);
|
|
409
|
+
req.onsuccess = () => resolve(req.result);
|
|
410
|
+
req.onupgradeneeded = (event) => {
|
|
411
|
+
const db2 = req.result;
|
|
412
|
+
if (!db2.objectStoreNames.contains(collection)) db2.createObjectStore(collection, { keyPath: void 0 });
|
|
413
|
+
if (this.setup) this.setup(db2, event);
|
|
414
|
+
};
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
async tx(collection, fn2, readonly) {
|
|
418
|
+
const db = await this.database;
|
|
419
|
+
const tx = db.transaction(collection, readonly ? "readonly" : "readwrite");
|
|
420
|
+
const store = tx.objectStore(collection);
|
|
421
|
+
return new Promise((resolve, reject) => {
|
|
422
|
+
const request = fn2(store);
|
|
423
|
+
request.onsuccess = () => resolve(request.result);
|
|
424
|
+
request.onerror = () => reject(request.error);
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
add(value, key) {
|
|
428
|
+
return this.tx(this.collection, (store) => store.add(value, key));
|
|
429
|
+
}
|
|
430
|
+
count() {
|
|
431
|
+
return this.tx(this.collection, (store) => store.count(), true);
|
|
432
|
+
}
|
|
433
|
+
put(key, value) {
|
|
434
|
+
debugger;
|
|
435
|
+
return this.tx(this.collection, (store) => store.put(value, key));
|
|
436
|
+
}
|
|
437
|
+
getAll() {
|
|
438
|
+
return this.tx(this.collection, (store) => store.getAll(), true);
|
|
439
|
+
}
|
|
440
|
+
getAllKeys() {
|
|
441
|
+
return this.tx(this.collection, (store) => store.getAllKeys(), true);
|
|
442
|
+
}
|
|
443
|
+
get(key) {
|
|
444
|
+
return this.tx(this.collection, (store) => store.get(key), true);
|
|
445
|
+
}
|
|
446
|
+
delete(key) {
|
|
447
|
+
return this.tx(this.collection, (store) => store.delete(key));
|
|
448
|
+
}
|
|
449
|
+
clear() {
|
|
450
|
+
return this.tx(this.collection, (store) => store.clear());
|
|
451
|
+
}
|
|
452
|
+
}
|
|
398
453
|
class Cache {
|
|
399
454
|
/**
|
|
400
455
|
* Create new cache
|
|
@@ -410,14 +465,19 @@ ${opts.message || this.desc}`;
|
|
|
410
465
|
* @return {T[]} Array of items
|
|
411
466
|
*/
|
|
412
467
|
__publicField(this, "values", this.all());
|
|
468
|
+
var _a;
|
|
413
469
|
this.key = key;
|
|
414
470
|
this.options = options;
|
|
415
|
-
if (options.storageKey && !options.storage && typeof Storage !== "undefined")
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
471
|
+
if (options.storageKey && !options.storage && typeof Storage !== "undefined") options.storage = localStorage;
|
|
472
|
+
if (options.storage) {
|
|
473
|
+
if (options.storage instanceof Collection) {
|
|
474
|
+
(async () => {
|
|
475
|
+
var _a2;
|
|
476
|
+
(await ((_a2 = options.storage) == null ? void 0 : _a2.getAll())).forEach((v) => this.add(v));
|
|
477
|
+
})();
|
|
478
|
+
} else if (options.storageKey) {
|
|
479
|
+
const stored = (_a = options.storage) == null ? void 0 : _a.getItem(options.storageKey);
|
|
480
|
+
if (stored != null) try {
|
|
421
481
|
Object.assign(this.store, JSON.parse(stored));
|
|
422
482
|
} catch {
|
|
423
483
|
}
|
|
@@ -439,9 +499,14 @@ ${opts.message || this.desc}`;
|
|
|
439
499
|
if (!this.key) throw new Error("No key defined");
|
|
440
500
|
return value[this.key];
|
|
441
501
|
}
|
|
442
|
-
save() {
|
|
443
|
-
if (this.options.
|
|
444
|
-
this.options.storage
|
|
502
|
+
save(key) {
|
|
503
|
+
if (this.options.storage) {
|
|
504
|
+
if (this.options.storage instanceof Collection) {
|
|
505
|
+
this.options.storage.put(key, this.store[key]);
|
|
506
|
+
} else if (this.options.storageKey) {
|
|
507
|
+
this.options.storage.setItem(this.options.storageKey, JSONSanitize(this.store));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
445
510
|
}
|
|
446
511
|
/**
|
|
447
512
|
* Get all cached items
|
|
@@ -479,6 +544,7 @@ ${opts.message || this.desc}`;
|
|
|
479
544
|
clear() {
|
|
480
545
|
this.complete = false;
|
|
481
546
|
this.store = {};
|
|
547
|
+
return this;
|
|
482
548
|
}
|
|
483
549
|
/**
|
|
484
550
|
* Delete an item from the cache
|
|
@@ -486,7 +552,8 @@ ${opts.message || this.desc}`;
|
|
|
486
552
|
*/
|
|
487
553
|
delete(key) {
|
|
488
554
|
delete this.store[key];
|
|
489
|
-
this.save();
|
|
555
|
+
this.save(key);
|
|
556
|
+
return this;
|
|
490
557
|
}
|
|
491
558
|
/**
|
|
492
559
|
* Return cache as an array of key-value pairs
|
|
@@ -503,6 +570,7 @@ ${opts.message || this.desc}`;
|
|
|
503
570
|
this.complete = false;
|
|
504
571
|
if (this.options.expiryPolicy == "keep") this.store[key]._expired = true;
|
|
505
572
|
else this.delete(key);
|
|
573
|
+
return this;
|
|
506
574
|
}
|
|
507
575
|
/**
|
|
508
576
|
* Get item from the cache
|
|
@@ -542,18 +610,18 @@ ${opts.message || this.desc}`;
|
|
|
542
610
|
set(key, value, ttl = this.options.ttl) {
|
|
543
611
|
if (this.options.expiryPolicy == "keep") delete value._expired;
|
|
544
612
|
this.store[key] = value;
|
|
545
|
-
this.save();
|
|
613
|
+
this.save(key);
|
|
546
614
|
if (ttl) setTimeout(() => {
|
|
547
615
|
this.expire(key);
|
|
548
|
-
this.save();
|
|
549
|
-
}, ttl * 1e3);
|
|
616
|
+
this.save(key);
|
|
617
|
+
}, (ttl || 0) * 1e3);
|
|
550
618
|
return this;
|
|
551
619
|
}
|
|
552
620
|
}
|
|
553
|
-
function
|
|
554
|
-
const exploded = background == null ? void 0 : background.match(background.length >= 6 ?
|
|
555
|
-
if (!exploded) return "black";
|
|
556
|
-
const [r, g, b] = exploded.map((hex) => parseInt(hex, 16));
|
|
621
|
+
function contrast(background) {
|
|
622
|
+
const exploded = background == null ? void 0 : background.match(background.length >= 6 ? /[0-9a-fA-F]{2}/g : /[0-9a-fA-F]/g);
|
|
623
|
+
if (!exploded || (exploded == null ? void 0 : exploded.length) < 3) return "black";
|
|
624
|
+
const [r, g, b] = exploded.map((hex) => parseInt(hex.length == 1 ? `${hex}${hex}` : hex, 16));
|
|
557
625
|
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
558
626
|
return luminance > 0.5 ? "black" : "white";
|
|
559
627
|
}
|
|
@@ -563,7 +631,7 @@ ${opts.message || this.desc}`;
|
|
|
563
631
|
const CHAR_LIST = LETTER_LIST + LETTER_LIST.toLowerCase() + NUMBER_LIST + SYMBOL_LIST;
|
|
564
632
|
function camelCase(str) {
|
|
565
633
|
const text = pascalCase(str);
|
|
566
|
-
return text[0].toLowerCase() + text.slice(1);
|
|
634
|
+
return !text ? "" : text[0].toLowerCase() + text.slice(1);
|
|
567
635
|
}
|
|
568
636
|
function formatBytes(bytes, decimals = 2) {
|
|
569
637
|
if (bytes === 0) return "0 Bytes";
|
|
@@ -589,12 +657,9 @@ ${opts.message || this.desc}`;
|
|
|
589
657
|
return text.toString().padEnd(length, char);
|
|
590
658
|
}
|
|
591
659
|
function pascalCase(str) {
|
|
660
|
+
var _a;
|
|
592
661
|
if (!str) return "";
|
|
593
|
-
|
|
594
|
-
var _a;
|
|
595
|
-
return ((_a = args[1]) == null ? void 0 : _a.toUpperCase()) || "";
|
|
596
|
-
});
|
|
597
|
-
return text[0].toUpperCase() + text.slice(1);
|
|
662
|
+
return ((_a = str.match(/[a-zA-Z0-9]+/g)) == null ? void 0 : _a.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("")) ?? "";
|
|
598
663
|
}
|
|
599
664
|
function randomHex(length) {
|
|
600
665
|
return Array(length).fill(null).map(() => Math.round(Math.random() * 15).toString(16)).join("");
|
|
@@ -1016,7 +1081,7 @@ ${opts.message || this.desc}`;
|
|
|
1016
1081
|
}
|
|
1017
1082
|
static off(event, listener) {
|
|
1018
1083
|
const e = event.toString();
|
|
1019
|
-
this.listeners[e] = (this.listeners[e] || []).filter((l) => l
|
|
1084
|
+
this.listeners[e] = (this.listeners[e] || []).filter((l) => l != listener);
|
|
1020
1085
|
}
|
|
1021
1086
|
static on(event, listener) {
|
|
1022
1087
|
var _a;
|
|
@@ -1039,7 +1104,7 @@ ${opts.message || this.desc}`;
|
|
|
1039
1104
|
(this.listeners[event] || []).forEach((l) => l(...args));
|
|
1040
1105
|
}
|
|
1041
1106
|
off(event, listener) {
|
|
1042
|
-
this.listeners[event] = (this.listeners[event] || []).filter((l) => l
|
|
1107
|
+
this.listeners[event] = (this.listeners[event] || []).filter((l) => l != listener);
|
|
1043
1108
|
}
|
|
1044
1109
|
on(event, listener) {
|
|
1045
1110
|
var _a;
|
|
@@ -1336,6 +1401,11 @@ ${opts.message || this.desc}`;
|
|
|
1336
1401
|
__publicField(_Http, "interceptors", {});
|
|
1337
1402
|
__publicField(_Http, "headers", {});
|
|
1338
1403
|
let Http = _Http;
|
|
1404
|
+
function createJwt(payload, signature = "unsigned") {
|
|
1405
|
+
const header = Buffer.from(JSON.stringify({ alg: "HS256", typ: "JWT" })).toString("base64url");
|
|
1406
|
+
const body = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
1407
|
+
return `${header}.${body}.${signature}`;
|
|
1408
|
+
}
|
|
1339
1409
|
function decodeJwt(token) {
|
|
1340
1410
|
const base64 = token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
1341
1411
|
return JSONAttemptParse(decodeURIComponent(atob(base64).split("").map(function(c) {
|
|
@@ -1431,20 +1501,22 @@ ${opts.message || this.desc}`;
|
|
|
1431
1501
|
};
|
|
1432
1502
|
__publicField(_Logger, "LOG_LEVEL", 4);
|
|
1433
1503
|
let Logger = _Logger;
|
|
1434
|
-
function dec2Frac(num) {
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
};
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1504
|
+
function dec2Frac(num, maxDen = 1e3) {
|
|
1505
|
+
let sign = Math.sign(num);
|
|
1506
|
+
num = Math.abs(num);
|
|
1507
|
+
if (Number.isInteger(num)) return sign * num + "";
|
|
1508
|
+
let closest = { n: 0, d: 1, diff: Math.abs(num) };
|
|
1509
|
+
for (let d = 1; d <= maxDen; d++) {
|
|
1510
|
+
let n = Math.round(num * d);
|
|
1511
|
+
let diff = Math.abs(num - n / d);
|
|
1512
|
+
if (diff < closest.diff) {
|
|
1513
|
+
closest = { n, d, diff };
|
|
1514
|
+
if (diff < 1e-8) break;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
let integer = Math.floor(closest.n / closest.d);
|
|
1518
|
+
let numerator = closest.n - integer * closest.d;
|
|
1519
|
+
return (sign < 0 ? "-" : "") + (integer ? integer + " " : "") + (numerator ? numerator + "/" + closest.d : "");
|
|
1448
1520
|
}
|
|
1449
1521
|
function fracToDec(frac) {
|
|
1450
1522
|
let split = frac.split(" ");
|
|
@@ -1564,6 +1636,7 @@ ${opts.message || this.desc}`;
|
|
|
1564
1636
|
const l1 = p1.fullPath.length, l2 = p2.fullPath.length;
|
|
1565
1637
|
return l1 < l2 ? 1 : l1 > l2 ? -1 : 0;
|
|
1566
1638
|
}).reduce((acc, p) => {
|
|
1639
|
+
if (acc && !acc.fullPath.startsWith(p.fullPath)) return acc;
|
|
1567
1640
|
if (p.none) hitNone = true;
|
|
1568
1641
|
if (!acc) return p;
|
|
1569
1642
|
if (hitNone) return acc;
|
|
@@ -1671,15 +1744,15 @@ ${opts.message || this.desc}`;
|
|
|
1671
1744
|
this.prefix = prefix;
|
|
1672
1745
|
}
|
|
1673
1746
|
emit(event, ...args) {
|
|
1674
|
-
const parsed = new PathEvent(`${this.prefix}/${
|
|
1675
|
-
this.listeners.filter((l) => PathEvent.has(l[0], event)).forEach(async (l) => l[1](parsed, ...args));
|
|
1747
|
+
const parsed = new PathEvent(`${this.prefix}/${new PathEvent(event).toString()}`);
|
|
1748
|
+
this.listeners.filter((l) => PathEvent.has(l[0], `${this.prefix}/${event}`)).forEach(async (l) => l[1](parsed, ...args));
|
|
1676
1749
|
}
|
|
1677
1750
|
off(listener) {
|
|
1678
1751
|
this.listeners = this.listeners.filter((l) => l[1] != listener);
|
|
1679
1752
|
}
|
|
1680
1753
|
on(event, listener) {
|
|
1681
1754
|
makeArray(event).forEach((e) => this.listeners.push([
|
|
1682
|
-
new PathEvent(`${this.prefix}/${
|
|
1755
|
+
new PathEvent(`${this.prefix}/${new PathEvent(e).toString()}`),
|
|
1683
1756
|
listener
|
|
1684
1757
|
]));
|
|
1685
1758
|
return () => this.off(listener);
|
|
@@ -1750,9 +1823,6 @@ ${opts.message || this.desc}`;
|
|
|
1750
1823
|
}).length == and.length;
|
|
1751
1824
|
});
|
|
1752
1825
|
}
|
|
1753
|
-
function typeKeys() {
|
|
1754
|
-
return Object.keys({});
|
|
1755
|
-
}
|
|
1756
1826
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
1757
1827
|
var dist = {};
|
|
1758
1828
|
var persist$1 = {};
|
|
@@ -1932,6 +2002,7 @@ ${opts.message || this.desc}`;
|
|
|
1932
2002
|
exports2.CliBackground = CliBackground;
|
|
1933
2003
|
exports2.CliEffects = CliEffects;
|
|
1934
2004
|
exports2.CliForeground = CliForeground;
|
|
2005
|
+
exports2.Collection = Collection;
|
|
1935
2006
|
exports2.CustomError = CustomError;
|
|
1936
2007
|
exports2.ForbiddenError = ForbiddenError;
|
|
1937
2008
|
exports2.GatewayTimeoutError = GatewayTimeoutError;
|
|
@@ -1962,10 +2033,11 @@ ${opts.message || this.desc}`;
|
|
|
1962
2033
|
exports2.addUnique = addUnique;
|
|
1963
2034
|
exports2.adjustedInterval = adjustedInterval;
|
|
1964
2035
|
exports2.arrayDiff = arrayDiff;
|
|
1965
|
-
exports2.blackOrWhite = blackOrWhite;
|
|
1966
2036
|
exports2.camelCase = camelCase;
|
|
1967
2037
|
exports2.caseInsensitiveSort = caseInsensitiveSort;
|
|
1968
2038
|
exports2.clean = clean;
|
|
2039
|
+
exports2.contrast = contrast;
|
|
2040
|
+
exports2.createJwt = createJwt;
|
|
1969
2041
|
exports2.dec2Frac = dec2Frac;
|
|
1970
2042
|
exports2.decodeJwt = decodeJwt;
|
|
1971
2043
|
exports2.deepCopy = deepCopy;
|
|
@@ -2015,7 +2087,6 @@ ${opts.message || this.desc}`;
|
|
|
2015
2087
|
exports2.timeUntil = timeUntil;
|
|
2016
2088
|
exports2.timestampFilename = timestampFilename;
|
|
2017
2089
|
exports2.toCsv = toCsv;
|
|
2018
|
-
exports2.typeKeys = typeKeys;
|
|
2019
2090
|
exports2.uploadWithProgress = uploadWithProgress;
|
|
2020
2091
|
exports2.validateEmail = validateEmail;
|
|
2021
2092
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|