@fluixi/utils 1.0.0-alpha.83 → 1.0.0-alpha.84
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/index.cjs +2858 -1
- package/dist/index.mjs +2838 -1
- package/dist/lib/array/advanced.cjs +2227 -1
- package/dist/lib/array/advanced.mjs +2204 -1
- package/dist/lib/array/array.cjs +57 -1
- package/dist/lib/array/array.mjs +36 -1
- package/dist/lib/array/index.cjs +2344 -1
- package/dist/lib/array/index.mjs +2322 -1
- package/dist/lib/array/utils.cjs +103 -1
- package/dist/lib/array/utils.mjs +82 -1
- package/dist/lib/color/color.cjs +2190 -1
- package/dist/lib/color/color.mjs +2167 -1
- package/dist/lib/color/constants.cjs +380 -1
- package/dist/lib/color/constants.mjs +359 -1
- package/dist/lib/color/conversions.cjs +629 -1
- package/dist/lib/color/conversions.mjs +608 -1
- package/dist/lib/color/helpers.cjs +2534 -1
- package/dist/lib/color/helpers.mjs +2511 -1
- package/dist/lib/color/index.cjs +2641 -1
- package/dist/lib/color/index.mjs +2619 -1
- package/dist/lib/color/types.cjs +18 -1
- package/dist/lib/color/utils.cjs +962 -1
- package/dist/lib/color/utils.mjs +939 -1
- package/dist/lib/compare/comparators.cjs +171 -1
- package/dist/lib/compare/comparators.mjs +150 -1
- package/dist/lib/compare/index.cjs +172 -1
- package/dist/lib/compare/index.mjs +152 -1
- package/dist/lib/crypto/hash.cjs +83 -1
- package/dist/lib/crypto/hash.mjs +62 -1
- package/dist/lib/crypto/index.cjs +85 -1
- package/dist/lib/crypto/index.mjs +62 -1
- package/dist/lib/dom/events.cjs +40 -1
- package/dist/lib/dom/events.mjs +19 -1
- package/dist/lib/dom/index.cjs +78 -1
- package/dist/lib/dom/index.mjs +56 -1
- package/dist/lib/dom/utils.cjs +57 -1
- package/dist/lib/dom/utils.mjs +36 -1
- package/dist/lib/functions/functions.cjs +366 -1
- package/dist/lib/functions/functions.mjs +345 -1
- package/dist/lib/functions/index.cjs +369 -1
- package/dist/lib/functions/index.mjs +347 -1
- package/dist/lib/functions/types.cjs +18 -1
- package/dist/lib/helpers.cjs +78 -1
- package/dist/lib/helpers.mjs +59 -1
- package/dist/lib/index.cjs +2857 -1
- package/dist/lib/index.mjs +2836 -1
- package/dist/lib/maths/constants.cjs +70 -1
- package/dist/lib/maths/constants.mjs +50 -1
- package/dist/lib/maths/fn/advanced.cjs +231 -1
- package/dist/lib/maths/fn/advanced.mjs +208 -1
- package/dist/lib/maths/fn/basic.cjs +212 -1
- package/dist/lib/maths/fn/basic.mjs +191 -1
- package/dist/lib/maths/fn/complex.cjs +268 -1
- package/dist/lib/maths/fn/complex.mjs +247 -1
- package/dist/lib/maths/fn/index.cjs +877 -1
- package/dist/lib/maths/fn/index.mjs +855 -1
- package/dist/lib/maths/fn/trigo.cjs +179 -1
- package/dist/lib/maths/fn/trigo.mjs +156 -1
- package/dist/lib/maths/fn/vector.cjs +728 -1
- package/dist/lib/maths/fn/vector.mjs +707 -1
- package/dist/lib/maths/formatter.cjs +61 -1
- package/dist/lib/maths/formatter.mjs +40 -1
- package/dist/lib/maths/guards.cjs +164 -1
- package/dist/lib/maths/guards.mjs +144 -1
- package/dist/lib/maths/index.cjs +1152 -1
- package/dist/lib/maths/index.mjs +1130 -1
- package/dist/lib/maths/parser.cjs +75 -1
- package/dist/lib/maths/parser.mjs +54 -1
- package/dist/lib/maths/random.cjs +49 -1
- package/dist/lib/maths/random.mjs +28 -1
- package/dist/lib/maths/types/advanced.cjs +18 -1
- package/dist/lib/maths/types/basic.cjs +18 -1
- package/dist/lib/maths/types/index.cjs +19 -1
- package/dist/lib/maths/types/index.mjs +1 -0
- package/dist/lib/maths/types/negative.cjs +18 -1
- package/dist/lib/maths/types/operations.cjs +18 -1
- package/dist/lib/object/clone.cjs +88 -1
- package/dist/lib/object/clone.mjs +65 -1
- package/dist/lib/object/diff.cjs +573 -1
- package/dist/lib/object/diff.mjs +550 -1
- package/dist/lib/object/getter-setter.cjs +2351 -1
- package/dist/lib/object/getter-setter.mjs +2330 -1
- package/dist/lib/object/index.cjs +3956 -6
- package/dist/lib/object/index.mjs +3936 -6
- package/dist/lib/object/merge.cjs +1029 -1
- package/dist/lib/object/merge.mjs +1006 -1
- package/dist/lib/object/object.cjs +280 -1
- package/dist/lib/object/object.mjs +257 -1
- package/dist/lib/object/omit.cjs +2022 -1
- package/dist/lib/object/omit.mjs +1999 -1
- package/dist/lib/object/reconcile.cjs +126 -1
- package/dist/lib/object/reconcile.mjs +105 -1
- package/dist/lib/object/selector.cjs +303 -1
- package/dist/lib/object/selector.mjs +282 -1
- package/dist/lib/object/sort.cjs +209 -1
- package/dist/lib/object/sort.mjs +186 -1
- package/dist/lib/object/transform.cjs +2211 -1
- package/dist/lib/object/transform.mjs +2190 -1
- package/dist/lib/object/types.cjs +18 -1
- package/dist/lib/object/utils.cjs +326 -6
- package/dist/lib/object/utils.mjs +305 -6
- package/dist/lib/primitive/boolean/boolean.cjs +407 -1
- package/dist/lib/primitive/boolean/boolean.mjs +386 -1
- package/dist/lib/primitive/boolean/index.cjs +382 -1
- package/dist/lib/primitive/boolean/index.mjs +359 -1
- package/dist/lib/primitive/boolean/types.cjs +18 -1
- package/dist/lib/primitive/date/date.cjs +1126 -1
- package/dist/lib/primitive/date/date.mjs +1105 -1
- package/dist/lib/primitive/date/index.cjs +1128 -1
- package/dist/lib/primitive/date/index.mjs +1105 -1
- package/dist/lib/primitive/date/types.cjs +18 -1
- package/dist/lib/primitive/index.cjs +2338 -5
- package/dist/lib/primitive/index.mjs +2316 -5
- package/dist/lib/primitive/string/index.cjs +875 -5
- package/dist/lib/primitive/string/index.mjs +852 -5
- package/dist/lib/primitive/string/parser-2.cjs +543 -8
- package/dist/lib/primitive/string/parser-2.mjs +522 -8
- package/dist/lib/primitive/string/parser.cjs +236 -3
- package/dist/lib/primitive/string/parser.mjs +215 -3
- package/dist/lib/primitive/string/string.cjs +926 -5
- package/dist/lib/primitive/string/string.mjs +903 -5
- package/dist/lib/primitive/string/types.cjs +18 -1
- package/dist/lib/primitive/types.cjs +18 -1
- package/dist/lib/url/index.cjs +327 -1
- package/dist/lib/url/index.mjs +304 -1
- package/dist/lib/url/parser.cjs +325 -1
- package/dist/lib/url/parser.mjs +304 -1
- package/dist/lib/url/types.cjs +18 -1
- package/package.json +5 -5
|
@@ -1 +1,347 @@
|
|
|
1
|
-
|
|
1
|
+
/*! @fluixi/utils v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
|
|
3
|
+
// src/lib/functions/functions.ts
|
|
4
|
+
import { isClass } from "@fluixi/utils/object";
|
|
5
|
+
function isFunction(v) {
|
|
6
|
+
return typeof v === "function" && !isClass(v);
|
|
7
|
+
}
|
|
8
|
+
function isPromise(v) {
|
|
9
|
+
return v instanceof Promise || !!v && (typeof v === "object" || typeof v === "function") && "then" in v;
|
|
10
|
+
}
|
|
11
|
+
function isAsyncFunction(v) {
|
|
12
|
+
return isFunction(v) && v.constructor.name === "AsyncFunction";
|
|
13
|
+
}
|
|
14
|
+
function memoize(fn, resolver) {
|
|
15
|
+
const cache = /* @__PURE__ */ new Map();
|
|
16
|
+
const memoized = function(...args) {
|
|
17
|
+
const key = resolver ? resolver(...args) : JSON.stringify(args);
|
|
18
|
+
if (cache.has(key)) {
|
|
19
|
+
return cache.get(key);
|
|
20
|
+
}
|
|
21
|
+
const result = fn.apply(this, args);
|
|
22
|
+
cache.set(key, result);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
memoized.cache = cache;
|
|
26
|
+
return memoized;
|
|
27
|
+
}
|
|
28
|
+
function debounce(fn, wait, options = {}) {
|
|
29
|
+
const { leading = false, trailing = true, maxWait } = options;
|
|
30
|
+
let timerId;
|
|
31
|
+
let maxTimerId;
|
|
32
|
+
let lastCallTime;
|
|
33
|
+
let lastInvokeTime = 0;
|
|
34
|
+
let lastArgs;
|
|
35
|
+
let lastThis;
|
|
36
|
+
let result;
|
|
37
|
+
function invokeFunc(time) {
|
|
38
|
+
const args = lastArgs;
|
|
39
|
+
const thisArg = lastThis;
|
|
40
|
+
lastArgs = lastThis = void 0;
|
|
41
|
+
lastInvokeTime = time;
|
|
42
|
+
result = fn.apply(thisArg, args);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function startTimer(pendingFunc, wait2) {
|
|
46
|
+
return setTimeout(pendingFunc, wait2);
|
|
47
|
+
}
|
|
48
|
+
function cancelTimer(id) {
|
|
49
|
+
if (id !== void 0) {
|
|
50
|
+
clearTimeout(id);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function leadingEdge(time) {
|
|
54
|
+
lastInvokeTime = time;
|
|
55
|
+
timerId = startTimer(timerExpired, wait);
|
|
56
|
+
return leading ? invokeFunc(time) : result;
|
|
57
|
+
}
|
|
58
|
+
function remainingWait(time) {
|
|
59
|
+
const timeSinceLastCall = time - lastCallTime;
|
|
60
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
61
|
+
const timeWaiting = wait - timeSinceLastCall;
|
|
62
|
+
return maxWait !== void 0 ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
63
|
+
}
|
|
64
|
+
function shouldInvoke(time) {
|
|
65
|
+
const timeSinceLastCall = time - lastCallTime;
|
|
66
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
67
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxWait !== void 0 && timeSinceLastInvoke >= maxWait;
|
|
68
|
+
}
|
|
69
|
+
function timerExpired() {
|
|
70
|
+
const time = Date.now();
|
|
71
|
+
if (shouldInvoke(time)) {
|
|
72
|
+
trailingEdge(time);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
timerId = startTimer(timerExpired, remainingWait(time));
|
|
76
|
+
}
|
|
77
|
+
function trailingEdge(time) {
|
|
78
|
+
timerId = void 0;
|
|
79
|
+
if (trailing && lastArgs) {
|
|
80
|
+
return invokeFunc(time);
|
|
81
|
+
}
|
|
82
|
+
lastArgs = lastThis = void 0;
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
function cancel() {
|
|
86
|
+
cancelTimer(timerId);
|
|
87
|
+
cancelTimer(maxTimerId);
|
|
88
|
+
lastInvokeTime = 0;
|
|
89
|
+
lastArgs = lastCallTime = lastThis = timerId = maxTimerId = void 0;
|
|
90
|
+
}
|
|
91
|
+
function flush() {
|
|
92
|
+
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
93
|
+
}
|
|
94
|
+
function pending() {
|
|
95
|
+
return timerId !== void 0;
|
|
96
|
+
}
|
|
97
|
+
function debounced(...args) {
|
|
98
|
+
const time = Date.now();
|
|
99
|
+
const isInvoking = shouldInvoke(time);
|
|
100
|
+
lastArgs = args;
|
|
101
|
+
lastThis = this;
|
|
102
|
+
lastCallTime = time;
|
|
103
|
+
if (isInvoking) {
|
|
104
|
+
if (timerId === void 0) {
|
|
105
|
+
return leadingEdge(lastCallTime);
|
|
106
|
+
}
|
|
107
|
+
if (maxWait !== void 0) {
|
|
108
|
+
timerId = startTimer(timerExpired, wait);
|
|
109
|
+
return invokeFunc(lastCallTime);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (timerId === void 0) {
|
|
113
|
+
timerId = startTimer(timerExpired, wait);
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
debounced.cancel = cancel;
|
|
118
|
+
debounced.flush = flush;
|
|
119
|
+
debounced.pending = pending;
|
|
120
|
+
return debounced;
|
|
121
|
+
}
|
|
122
|
+
function throttle(fn, wait, options = {}) {
|
|
123
|
+
const { leading = true, trailing = true } = options;
|
|
124
|
+
return debounce(fn, wait, {
|
|
125
|
+
leading,
|
|
126
|
+
trailing,
|
|
127
|
+
maxWait: wait
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function once(fn) {
|
|
131
|
+
let called = false;
|
|
132
|
+
let result;
|
|
133
|
+
const wrapped = function(...args) {
|
|
134
|
+
if (!called) {
|
|
135
|
+
called = true;
|
|
136
|
+
result = fn.apply(this, args);
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
};
|
|
140
|
+
Object.defineProperty(wrapped, "called", {
|
|
141
|
+
get() {
|
|
142
|
+
return called;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return wrapped;
|
|
146
|
+
}
|
|
147
|
+
function rearg(fn, ...indexes) {
|
|
148
|
+
return function(...args) {
|
|
149
|
+
const reordered = indexes.map((i) => args[i]);
|
|
150
|
+
return fn.apply(this, reordered);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function curry(fn, arity = fn.length) {
|
|
154
|
+
return function curried(...args) {
|
|
155
|
+
if (args.length >= arity) {
|
|
156
|
+
return fn.apply(this, args);
|
|
157
|
+
}
|
|
158
|
+
return function(...nextArgs) {
|
|
159
|
+
return curried.apply(this, [...args, ...nextArgs]);
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function compose(...fns) {
|
|
164
|
+
return fns.reduceRight(
|
|
165
|
+
(prevFn, nextFn) => (value) => nextFn(prevFn(value)),
|
|
166
|
+
(value) => value
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
function pipe(...fns) {
|
|
170
|
+
return fns.reduce(
|
|
171
|
+
(prevFn, nextFn) => (value) => nextFn(prevFn(value)),
|
|
172
|
+
(value) => value
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
function negate(predicate) {
|
|
176
|
+
return function(...args) {
|
|
177
|
+
return !predicate.apply(this, args);
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function overArgs(fn, ...transforms) {
|
|
181
|
+
return function(...args) {
|
|
182
|
+
const transformedArgs = args.map(
|
|
183
|
+
(arg, index) => transforms[index] ? transforms[index](arg) : arg
|
|
184
|
+
);
|
|
185
|
+
return fn.apply(this, transformedArgs);
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function partial(fn, ...partials) {
|
|
189
|
+
return function(...args) {
|
|
190
|
+
return fn.apply(this, [...partials, ...args]);
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function partialRight(fn, ...partials) {
|
|
194
|
+
return function(...args) {
|
|
195
|
+
return fn.apply(this, [...args, ...partials]);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function bind(fn, thisArg, ...partials) {
|
|
199
|
+
return function(...args) {
|
|
200
|
+
return fn.apply(thisArg, [...partials, ...args]);
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function flip(fn) {
|
|
204
|
+
return function(...args) {
|
|
205
|
+
return fn.apply(this, args.reverse());
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function ary(fn, n) {
|
|
209
|
+
return function(...args) {
|
|
210
|
+
return fn.apply(this, args.slice(0, n));
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function unary(fn) {
|
|
214
|
+
return function(arg) {
|
|
215
|
+
return fn.call(this, arg);
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function defer(fn, ...args) {
|
|
219
|
+
return setTimeout(fn, 1, ...args);
|
|
220
|
+
}
|
|
221
|
+
function delay(fn, wait, ...args) {
|
|
222
|
+
return setTimeout(fn, wait, ...args);
|
|
223
|
+
}
|
|
224
|
+
function memoizeWithTTL(fn, ttl, resolver) {
|
|
225
|
+
const cache = /* @__PURE__ */ new Map();
|
|
226
|
+
const memoized = function(...args) {
|
|
227
|
+
const key = resolver ? resolver(...args) : JSON.stringify(args);
|
|
228
|
+
const now = Date.now();
|
|
229
|
+
const cached = cache.get(key);
|
|
230
|
+
if (cached && cached.expires > now) {
|
|
231
|
+
return cached.value;
|
|
232
|
+
}
|
|
233
|
+
const result = fn.apply(this, args);
|
|
234
|
+
cache.set(key, { value: result, expires: now + ttl });
|
|
235
|
+
for (const [k, v] of cache.entries()) {
|
|
236
|
+
if (v.expires <= now) {
|
|
237
|
+
cache.delete(k);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return result;
|
|
241
|
+
};
|
|
242
|
+
memoized.cache = cache;
|
|
243
|
+
return memoized;
|
|
244
|
+
}
|
|
245
|
+
function before(fn, n) {
|
|
246
|
+
let result;
|
|
247
|
+
let callCount = 0;
|
|
248
|
+
return function(...args) {
|
|
249
|
+
if (++callCount < n) {
|
|
250
|
+
result = fn.apply(this, args);
|
|
251
|
+
}
|
|
252
|
+
if (callCount >= n) {
|
|
253
|
+
fn = void 0;
|
|
254
|
+
}
|
|
255
|
+
return result;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function after(fn, n) {
|
|
259
|
+
let callCount = 0;
|
|
260
|
+
return function(...args) {
|
|
261
|
+
if (++callCount >= n) {
|
|
262
|
+
return fn.apply(this, args);
|
|
263
|
+
}
|
|
264
|
+
return void 0;
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function tryCatch(fn, errorHandler) {
|
|
268
|
+
return function(...args) {
|
|
269
|
+
try {
|
|
270
|
+
return fn.apply(this, args);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
return errorHandler(error, ...args);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function flow(...fns) {
|
|
277
|
+
return pipe(...fns);
|
|
278
|
+
}
|
|
279
|
+
function flowRight(...fns) {
|
|
280
|
+
return compose(...fns);
|
|
281
|
+
}
|
|
282
|
+
function retry(fn, options = {}) {
|
|
283
|
+
const { retries = 3, delay: delay2 = 1e3, backoff = 2, onRetry } = options;
|
|
284
|
+
return async function(...args) {
|
|
285
|
+
let lastError;
|
|
286
|
+
let currentDelay = delay2;
|
|
287
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
288
|
+
try {
|
|
289
|
+
return await fn.apply(this, args);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
lastError = error;
|
|
292
|
+
if (attempt < retries) {
|
|
293
|
+
if (onRetry) {
|
|
294
|
+
onRetry(lastError, attempt + 1);
|
|
295
|
+
}
|
|
296
|
+
await new Promise((resolve) => setTimeout(resolve, currentDelay));
|
|
297
|
+
currentDelay *= backoff;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
throw lastError;
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function withTimeout(fn, timeout, onTimeout) {
|
|
305
|
+
return async function(...args) {
|
|
306
|
+
return Promise.race([
|
|
307
|
+
fn.apply(this, args),
|
|
308
|
+
new Promise(
|
|
309
|
+
(_, reject) => setTimeout(() => {
|
|
310
|
+
if (onTimeout) onTimeout();
|
|
311
|
+
reject(new Error(`Function timed out after ${timeout}ms`));
|
|
312
|
+
}, timeout)
|
|
313
|
+
)
|
|
314
|
+
]);
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
export {
|
|
318
|
+
after,
|
|
319
|
+
ary,
|
|
320
|
+
before,
|
|
321
|
+
bind,
|
|
322
|
+
compose,
|
|
323
|
+
curry,
|
|
324
|
+
debounce,
|
|
325
|
+
defer,
|
|
326
|
+
delay,
|
|
327
|
+
flip,
|
|
328
|
+
flow,
|
|
329
|
+
flowRight,
|
|
330
|
+
isAsyncFunction,
|
|
331
|
+
isFunction,
|
|
332
|
+
isPromise,
|
|
333
|
+
memoize,
|
|
334
|
+
memoizeWithTTL,
|
|
335
|
+
negate,
|
|
336
|
+
once,
|
|
337
|
+
overArgs,
|
|
338
|
+
partial,
|
|
339
|
+
partialRight,
|
|
340
|
+
pipe,
|
|
341
|
+
rearg,
|
|
342
|
+
retry,
|
|
343
|
+
throttle,
|
|
344
|
+
tryCatch,
|
|
345
|
+
unary,
|
|
346
|
+
withTimeout
|
|
347
|
+
};
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/lib/functions/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/lib/helpers.cjs
CHANGED
|
@@ -1 +1,78 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/helpers.ts
|
|
21
|
+
var helpers_exports = {};
|
|
22
|
+
__export(helpers_exports, {
|
|
23
|
+
generateID: () => generateID,
|
|
24
|
+
generateUUID: () => generateUUID,
|
|
25
|
+
getKind: () => getKind,
|
|
26
|
+
isDefined: () => isDefined,
|
|
27
|
+
isNull: () => isNull,
|
|
28
|
+
isPrimitive: () => isPrimitive,
|
|
29
|
+
isUndefined: () => isUndefined,
|
|
30
|
+
isUndefinedOrNull: () => isUndefinedOrNull
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
33
|
+
var import_primitive = require("@fluixi/utils/primitive");
|
|
34
|
+
var import_object = require("@fluixi/utils/object");
|
|
35
|
+
var import_array = require("@fluixi/utils/array");
|
|
36
|
+
var import_functions = require("@fluixi/utils/functions");
|
|
37
|
+
function isNull(v) {
|
|
38
|
+
return v === null;
|
|
39
|
+
}
|
|
40
|
+
function isUndefined(v) {
|
|
41
|
+
return v === void 0;
|
|
42
|
+
}
|
|
43
|
+
var isUndefinedOrNull = (element) => {
|
|
44
|
+
if (typeof element === "undefined" || element === null) return true;
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
47
|
+
function isPrimitive(v) {
|
|
48
|
+
const type = typeof v;
|
|
49
|
+
return v === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "bigint" || type === "undefined" || (0, import_primitive.isDate)(v);
|
|
50
|
+
}
|
|
51
|
+
function isDefined(obj) {
|
|
52
|
+
return obj !== void 0 && obj !== null;
|
|
53
|
+
}
|
|
54
|
+
function getKind(obj) {
|
|
55
|
+
if (obj === null) return "null";
|
|
56
|
+
if (obj === void 0) return "undefined";
|
|
57
|
+
if ((0, import_primitive.isDate)(obj)) return "date";
|
|
58
|
+
if ((0, import_object.isClass)(obj)) return "class";
|
|
59
|
+
if ((0, import_functions.isFunction)(obj)) return "function";
|
|
60
|
+
if ((0, import_array.isArray)(obj)) return "array";
|
|
61
|
+
if (isPrimitive(obj)) return "primitive";
|
|
62
|
+
if ((0, import_object.isObject)(obj)) return "object";
|
|
63
|
+
return "primitive";
|
|
64
|
+
}
|
|
65
|
+
var generateUUID = () => {
|
|
66
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
67
|
+
let r = Math.random() * 16 | 0;
|
|
68
|
+
let v = c === "x" ? r : r & 3 | 8;
|
|
69
|
+
return v.toString(16);
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
var generateID = () => {
|
|
73
|
+
return "xxyxxxxxxy-4xx8".replace(/[xy]/g, function(c) {
|
|
74
|
+
let r = Math.random() * 16 | 0;
|
|
75
|
+
let v = c === "x" ? r : r & 3 | 8;
|
|
76
|
+
return v.toString(16);
|
|
77
|
+
});
|
|
78
|
+
};
|
package/dist/lib/helpers.mjs
CHANGED
|
@@ -1 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/helpers.ts
|
|
2
|
+
import {
|
|
3
|
+
isDate
|
|
4
|
+
} from "@fluixi/utils/primitive";
|
|
5
|
+
import { isClass, isObject } from "@fluixi/utils/object";
|
|
6
|
+
import { isArray } from "@fluixi/utils/array";
|
|
7
|
+
import { isFunction } from "@fluixi/utils/functions";
|
|
8
|
+
function isNull(v) {
|
|
9
|
+
return v === null;
|
|
10
|
+
}
|
|
11
|
+
function isUndefined(v) {
|
|
12
|
+
return v === void 0;
|
|
13
|
+
}
|
|
14
|
+
var isUndefinedOrNull = (element) => {
|
|
15
|
+
if (typeof element === "undefined" || element === null) return true;
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
18
|
+
function isPrimitive(v) {
|
|
19
|
+
const type = typeof v;
|
|
20
|
+
return v === null || type === "string" || type === "number" || type === "boolean" || type === "symbol" || type === "bigint" || type === "undefined" || isDate(v);
|
|
21
|
+
}
|
|
22
|
+
function isDefined(obj) {
|
|
23
|
+
return obj !== void 0 && obj !== null;
|
|
24
|
+
}
|
|
25
|
+
function getKind(obj) {
|
|
26
|
+
if (obj === null) return "null";
|
|
27
|
+
if (obj === void 0) return "undefined";
|
|
28
|
+
if (isDate(obj)) return "date";
|
|
29
|
+
if (isClass(obj)) return "class";
|
|
30
|
+
if (isFunction(obj)) return "function";
|
|
31
|
+
if (isArray(obj)) return "array";
|
|
32
|
+
if (isPrimitive(obj)) return "primitive";
|
|
33
|
+
if (isObject(obj)) return "object";
|
|
34
|
+
return "primitive";
|
|
35
|
+
}
|
|
36
|
+
var generateUUID = () => {
|
|
37
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
38
|
+
let r = Math.random() * 16 | 0;
|
|
39
|
+
let v = c === "x" ? r : r & 3 | 8;
|
|
40
|
+
return v.toString(16);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var generateID = () => {
|
|
44
|
+
return "xxyxxxxxxy-4xx8".replace(/[xy]/g, function(c) {
|
|
45
|
+
let r = Math.random() * 16 | 0;
|
|
46
|
+
let v = c === "x" ? r : r & 3 | 8;
|
|
47
|
+
return v.toString(16);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
generateID,
|
|
52
|
+
generateUUID,
|
|
53
|
+
getKind,
|
|
54
|
+
isDefined,
|
|
55
|
+
isNull,
|
|
56
|
+
isPrimitive,
|
|
57
|
+
isUndefined,
|
|
58
|
+
isUndefinedOrNull
|
|
59
|
+
};
|