@isopodlabs/utilities 1.5.7 → 1.5.9

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/utils.js DELETED
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CallCombiner = exports.CallCombiner0 = exports.Lazy = void 0;
4
- exports.makeCache = makeCache;
5
- exports.compare = compare;
6
- exports.reverse_compare = reverse_compare;
7
- exports.reverse = reverse;
8
- exports.merge = merge;
9
- exports.isEmpty = isEmpty;
10
- exports.clone = clone;
11
- class Lazy {
12
- factory;
13
- _value;
14
- constructor(factory) {
15
- this.factory = factory;
16
- }
17
- get value() {
18
- if (this._value === undefined)
19
- this._value = this.factory();
20
- return this._value;
21
- }
22
- // Add 'then' method only when T is a Promise
23
- then(onFulfilled) {
24
- return this.value.then(onFulfilled);
25
- }
26
- }
27
- exports.Lazy = Lazy;
28
- class CallCombiner0 {
29
- timeout = null;
30
- combine(delay, func) {
31
- if (this.timeout)
32
- clearTimeout(this.timeout);
33
- this.timeout = setTimeout(() => {
34
- this.timeout = null;
35
- func();
36
- }, delay);
37
- }
38
- pending() {
39
- return !!this.timeout;
40
- }
41
- }
42
- exports.CallCombiner0 = CallCombiner0;
43
- class CallCombiner extends CallCombiner0 {
44
- func;
45
- delay;
46
- constructor(func, delay) {
47
- super();
48
- this.func = func;
49
- this.delay = delay;
50
- }
51
- trigger() {
52
- super.combine(this.delay, this.func);
53
- }
54
- }
55
- exports.CallCombiner = CallCombiner;
56
- function makeCache(load) {
57
- const cache = {};
58
- return {
59
- get: (fullpath) => {
60
- if (!cache[fullpath])
61
- cache[fullpath] = load(fullpath);
62
- return cache[fullpath];
63
- },
64
- remove: (fullpath) => {
65
- delete cache[fullpath];
66
- },
67
- };
68
- }
69
- function compare(a, b) {
70
- return a < b ? -1 : a > b ? 1 : 0;
71
- }
72
- function reverse_compare(a, b) {
73
- return compare(b, a);
74
- }
75
- function reverse(func) {
76
- return (a, b) => func(b, a);
77
- }
78
- function merge(...list) {
79
- function isObject(value) {
80
- return typeof value === 'object' && value !== null;
81
- }
82
- function recurse(target, source) {
83
- for (const key in source) {
84
- if (isObject(source[key]) && isObject(target[key]))
85
- recurse(target[key], source[key]);
86
- else
87
- target[key] = source[key];
88
- }
89
- return target;
90
- }
91
- return list.reduce((merged, r) => recurse(merged, r), {});
92
- }
93
- function isEmpty(obj) {
94
- return Object.keys(obj).length === 0;
95
- }
96
- function clone(obj) {
97
- return Object.assign(Object.create(Object.getPrototypeOf(obj)), obj);
98
- }