@valkyriestudios/utils 12.36.0 → 12.38.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/array/groupBy.d.ts +3 -3
- package/array/join.d.ts +2 -2
- package/array/split.d.ts +3 -3
- package/caching/LRU.d.ts +16 -10
- package/{array → cjs/array}/groupBy.js +16 -4
- package/{array → cjs/array}/join.js +15 -3
- package/{array → cjs/array}/mapFnAsMap.js +1 -1
- package/{array → cjs/array}/split.js +16 -7
- package/cjs/caching/LRU.js +123 -0
- package/{caching → cjs/caching}/memoize.js +11 -5
- package/{date → cjs/date}/format.js +7 -7
- package/{date → cjs/date}/isFormat.js +5 -2
- package/cjs/formdata/toObject.js +92 -0
- package/{object → cjs/object}/pick.js +2 -2
- package/{string → cjs/string}/humanizeNumber.js +2 -2
- package/cjs/string/isNotEmpty.js +23 -0
- package/{string → cjs/string}/shorten.js +1 -1
- package/esm/array/dedupe.js +52 -0
- package/esm/array/groupBy.js +43 -0
- package/esm/array/index.js +14 -0
- package/esm/array/is.js +4 -0
- package/esm/array/isNotEmpty.js +4 -0
- package/esm/array/join.js +58 -0
- package/esm/array/mapFn.js +22 -0
- package/esm/array/mapFnAsMap.js +21 -0
- package/esm/array/mapKey.js +22 -0
- package/esm/array/mapKeyAsMap.js +22 -0
- package/esm/array/mapPrimitive.js +33 -0
- package/esm/array/shuffle.js +10 -0
- package/esm/array/sort.js +137 -0
- package/esm/array/split.js +43 -0
- package/esm/boolean/index.js +1 -0
- package/esm/boolean/is.js +4 -0
- package/esm/caching/LRU.js +116 -0
- package/esm/caching/index.js +3 -0
- package/esm/caching/memoize.js +37 -0
- package/esm/date/addUTC.js +41 -0
- package/esm/date/convertToDate.js +12 -0
- package/esm/date/diff.js +34 -0
- package/esm/date/endOfUTC.js +50 -0
- package/esm/date/format.js +241 -0
- package/esm/date/index.js +15 -0
- package/esm/date/is.js +4 -0
- package/esm/date/isFormat.js +118 -0
- package/esm/date/isLeap.js +9 -0
- package/esm/date/nowUnix.js +4 -0
- package/esm/date/nowUnixMs.js +4 -0
- package/esm/date/setTimeUTC.js +10 -0
- package/esm/date/startOfUTC.js +50 -0
- package/esm/date/toUTC.js +7 -0
- package/esm/date/toUnix.js +7 -0
- package/esm/deep/freeze.js +21 -0
- package/esm/deep/get.js +84 -0
- package/esm/deep/index.js +8 -0
- package/esm/deep/seal.js +21 -0
- package/esm/deep/set.js +50 -0
- package/esm/equal.js +67 -0
- package/esm/formdata/index.js +2 -0
- package/esm/formdata/is.js +4 -0
- package/esm/formdata/toObject.js +89 -0
- package/esm/function/debounce.js +39 -0
- package/esm/function/index.js +9 -0
- package/esm/function/is.js +4 -0
- package/esm/function/isAsync.js +4 -0
- package/esm/function/noop.js +2 -0
- package/esm/function/noopresolve.js +4 -0
- package/esm/function/noopreturn.js +4 -0
- package/esm/function/sleep.js +6 -0
- package/esm/hash/fnv1A.js +51 -0
- package/esm/hash/guid.js +31 -0
- package/esm/hash/index.js +2 -0
- package/esm/is.js +63 -0
- package/esm/modules/PubSub.js +187 -0
- package/esm/modules/Scheduler.js +343 -0
- package/esm/modules/index.js +2 -0
- package/esm/number/index.js +37 -0
- package/esm/number/is.js +4 -0
- package/esm/number/isAbove.js +4 -0
- package/esm/number/isAboveOrEqual.js +4 -0
- package/esm/number/isBelow.js +4 -0
- package/esm/number/isBelowOrEqual.js +4 -0
- package/esm/number/isBetween.js +7 -0
- package/esm/number/isInteger.js +4 -0
- package/esm/number/isIntegerAbove.js +4 -0
- package/esm/number/isIntegerAboveOrEqual.js +4 -0
- package/esm/number/isIntegerBelow.js +4 -0
- package/esm/number/isIntegerBelowOrEqual.js +4 -0
- package/esm/number/isIntegerBetween.js +7 -0
- package/esm/number/isNumericalNaN.js +4 -0
- package/esm/number/randomBetween.js +7 -0
- package/esm/number/randomIntBetween.js +7 -0
- package/esm/number/round.js +10 -0
- package/esm/number/toPercentage.js +9 -0
- package/esm/object/define.js +7 -0
- package/esm/object/index.js +7 -0
- package/esm/object/is.js +4 -0
- package/esm/object/isNotEmpty.js +9 -0
- package/esm/object/merge.js +31 -0
- package/esm/object/omit.js +30 -0
- package/esm/object/pick.js +33 -0
- package/esm/regexp/index.js +3 -0
- package/esm/regexp/is.js +4 -0
- package/esm/regexp/sanitize.js +7 -0
- package/esm/string/humanizeBytes.js +15 -0
- package/esm/string/humanizeNumber.js +40 -0
- package/esm/string/index.js +7 -0
- package/esm/string/is.js +4 -0
- package/esm/string/isBetween.js +12 -0
- package/esm/string/isNotEmpty.js +20 -0
- package/esm/string/shorten.js +18 -0
- package/formdata/toObject.d.ts +4 -0
- package/index.d.ts +20 -15
- package/package.json +193 -851
- package/caching/LRU.js +0 -72
- package/formdata/toObject.js +0 -70
- package/string/isNotEmpty.js +0 -9
- /package/{array → cjs/array}/dedupe.js +0 -0
- /package/{array → cjs/array}/index.js +0 -0
- /package/{array → cjs/array}/is.js +0 -0
- /package/{array → cjs/array}/isNotEmpty.js +0 -0
- /package/{array → cjs/array}/mapFn.js +0 -0
- /package/{array → cjs/array}/mapKey.js +0 -0
- /package/{array → cjs/array}/mapKeyAsMap.js +0 -0
- /package/{array → cjs/array}/mapPrimitive.js +0 -0
- /package/{array → cjs/array}/shuffle.js +0 -0
- /package/{array → cjs/array}/sort.js +0 -0
- /package/{boolean → cjs/boolean}/index.js +0 -0
- /package/{boolean → cjs/boolean}/is.js +0 -0
- /package/{caching → cjs/caching}/index.js +0 -0
- /package/{date → cjs/date}/addUTC.js +0 -0
- /package/{date → cjs/date}/convertToDate.js +0 -0
- /package/{date → cjs/date}/diff.js +0 -0
- /package/{date → cjs/date}/endOfUTC.js +0 -0
- /package/{date → cjs/date}/index.js +0 -0
- /package/{date → cjs/date}/is.js +0 -0
- /package/{date → cjs/date}/isLeap.js +0 -0
- /package/{date → cjs/date}/nowUnix.js +0 -0
- /package/{date → cjs/date}/nowUnixMs.js +0 -0
- /package/{date → cjs/date}/setTimeUTC.js +0 -0
- /package/{date → cjs/date}/startOfUTC.js +0 -0
- /package/{date → cjs/date}/toUTC.js +0 -0
- /package/{date → cjs/date}/toUnix.js +0 -0
- /package/{deep → cjs/deep}/freeze.js +0 -0
- /package/{deep → cjs/deep}/get.js +0 -0
- /package/{deep → cjs/deep}/index.js +0 -0
- /package/{deep → cjs/deep}/seal.js +0 -0
- /package/{deep → cjs/deep}/set.js +0 -0
- /package/{equal.js → cjs/equal.js} +0 -0
- /package/{formdata → cjs/formdata}/index.js +0 -0
- /package/{formdata → cjs/formdata}/is.js +0 -0
- /package/{function → cjs/function}/debounce.js +0 -0
- /package/{function → cjs/function}/index.js +0 -0
- /package/{function → cjs/function}/is.js +0 -0
- /package/{function → cjs/function}/isAsync.js +0 -0
- /package/{function → cjs/function}/noop.js +0 -0
- /package/{function → cjs/function}/noopresolve.js +0 -0
- /package/{function → cjs/function}/noopreturn.js +0 -0
- /package/{function → cjs/function}/sleep.js +0 -0
- /package/{hash → cjs/hash}/fnv1A.js +0 -0
- /package/{hash → cjs/hash}/guid.js +0 -0
- /package/{hash → cjs/hash}/index.js +0 -0
- /package/{is.js → cjs/is.js} +0 -0
- /package/{modules → cjs/modules}/PubSub.js +0 -0
- /package/{modules → cjs/modules}/Scheduler.js +0 -0
- /package/{modules → cjs/modules}/index.js +0 -0
- /package/{number → cjs/number}/index.js +0 -0
- /package/{number → cjs/number}/is.js +0 -0
- /package/{number → cjs/number}/isAbove.js +0 -0
- /package/{number → cjs/number}/isAboveOrEqual.js +0 -0
- /package/{number → cjs/number}/isBelow.js +0 -0
- /package/{number → cjs/number}/isBelowOrEqual.js +0 -0
- /package/{number → cjs/number}/isBetween.js +0 -0
- /package/{number → cjs/number}/isInteger.js +0 -0
- /package/{number → cjs/number}/isIntegerAbove.js +0 -0
- /package/{number → cjs/number}/isIntegerAboveOrEqual.js +0 -0
- /package/{number → cjs/number}/isIntegerBelow.js +0 -0
- /package/{number → cjs/number}/isIntegerBelowOrEqual.js +0 -0
- /package/{number → cjs/number}/isIntegerBetween.js +0 -0
- /package/{number → cjs/number}/isNumericalNaN.js +0 -0
- /package/{number → cjs/number}/randomBetween.js +0 -0
- /package/{number → cjs/number}/randomIntBetween.js +0 -0
- /package/{number → cjs/number}/round.js +0 -0
- /package/{number → cjs/number}/toPercentage.js +0 -0
- /package/{object → cjs/object}/define.js +0 -0
- /package/{object → cjs/object}/index.js +0 -0
- /package/{object → cjs/object}/is.js +0 -0
- /package/{object → cjs/object}/isNotEmpty.js +0 -0
- /package/{object → cjs/object}/merge.js +0 -0
- /package/{object → cjs/object}/omit.js +0 -0
- /package/{regexp → cjs/regexp}/index.js +0 -0
- /package/{regexp → cjs/regexp}/is.js +0 -0
- /package/{regexp → cjs/regexp}/sanitize.js +0 -0
- /package/{string → cjs/string}/humanizeBytes.js +0 -0
- /package/{string → cjs/string}/index.js +0 -0
- /package/{string → cjs/string}/is.js +0 -0
- /package/{string → cjs/string}/isBetween.js +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { humanizeNumber } from './humanizeNumber';
|
|
2
|
+
const DEFAULT_UNITS = [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'];
|
|
3
|
+
function humanizeBytes(val, options = {}) {
|
|
4
|
+
return humanizeNumber(val, {
|
|
5
|
+
delim: 'delim' in options ? options.delim : ',',
|
|
6
|
+
separator: 'separator' in options ? options.separator : '.',
|
|
7
|
+
precision: 'precision' in options ? options.precision : 2,
|
|
8
|
+
units: Array.isArray(options?.units) && options.units.length
|
|
9
|
+
? options.units
|
|
10
|
+
: DEFAULT_UNITS,
|
|
11
|
+
divider: 1024,
|
|
12
|
+
real: true,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export { humanizeBytes, humanizeBytes as default };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { round } from '../number/round';
|
|
2
|
+
const DEFAULT_UNITS = ['', 'k', 'm', 'b', 't', 'q'];
|
|
3
|
+
function humanizeNumber(val, options = {}) {
|
|
4
|
+
const DELIM = typeof options?.delim === 'string' ? options.delim : ',';
|
|
5
|
+
const SEPARATOR = typeof options?.separator === 'string' && options.separator.length ? options.separator : '.';
|
|
6
|
+
const PRECISION = Number.isInteger(options?.precision) && options.precision >= 0 ? options.precision : 2;
|
|
7
|
+
const DIVIDER = Number.isInteger(options?.divider) && options.divider >= 2 ? options.divider : 1000;
|
|
8
|
+
const REAL = options?.real === true;
|
|
9
|
+
const UNITS = Array.isArray(options?.units) && options.units.length
|
|
10
|
+
? options.units
|
|
11
|
+
: options?.units === false
|
|
12
|
+
? false
|
|
13
|
+
: DEFAULT_UNITS;
|
|
14
|
+
let normalized = typeof val === 'string' ? parseFloat(val) : val;
|
|
15
|
+
if (!Number.isFinite(normalized) || normalized === 0)
|
|
16
|
+
return UNITS ? '0' + UNITS[0] : '0';
|
|
17
|
+
if (REAL)
|
|
18
|
+
normalized = Math.round(normalized);
|
|
19
|
+
const sign = normalized < 0 ? '-' : '';
|
|
20
|
+
normalized = Math.abs(normalized);
|
|
21
|
+
let unit_ix = 0;
|
|
22
|
+
if (UNITS) {
|
|
23
|
+
while (normalized >= DIVIDER && unit_ix < UNITS.length - 1) {
|
|
24
|
+
normalized /= DIVIDER;
|
|
25
|
+
unit_ix++;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const humanized = ('' + round(normalized, PRECISION)).split('.', 2);
|
|
29
|
+
const integer_part = humanized[0];
|
|
30
|
+
const integer_part_len = integer_part.length;
|
|
31
|
+
let formattedIntegerPart = '';
|
|
32
|
+
for (let i = 0; i < integer_part_len; i++) {
|
|
33
|
+
if (i > 0 && (integer_part_len - i) % 3 === 0) {
|
|
34
|
+
formattedIntegerPart += DELIM;
|
|
35
|
+
}
|
|
36
|
+
formattedIntegerPart += integer_part[i];
|
|
37
|
+
}
|
|
38
|
+
return sign + formattedIntegerPart + (humanized[1] ? SEPARATOR + humanized[1] : '') + (UNITS ? UNITS[unit_ix] : '');
|
|
39
|
+
}
|
|
40
|
+
export { humanizeNumber, humanizeNumber as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { humanizeBytes } from './humanizeBytes';
|
|
2
|
+
export { humanizeNumber } from './humanizeNumber';
|
|
3
|
+
export { shorten } from './shorten';
|
|
4
|
+
export { isString } from './is';
|
|
5
|
+
export { isNotEmptyString } from './isNotEmpty';
|
|
6
|
+
export { isNotEmptyString as isNeString } from './isNotEmpty';
|
|
7
|
+
export { isStringBetween } from './isBetween';
|
package/esm/string/is.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function isStringBetween(val, min, max, trimmed = true) {
|
|
2
|
+
if (typeof val !== 'string' ||
|
|
3
|
+
!Number.isFinite(min) ||
|
|
4
|
+
min < 0 ||
|
|
5
|
+
!Number.isFinite(max) ||
|
|
6
|
+
max < 0 ||
|
|
7
|
+
min >= max)
|
|
8
|
+
return false;
|
|
9
|
+
const length = (trimmed === true ? val.trim() : val).length;
|
|
10
|
+
return length >= min && length <= max;
|
|
11
|
+
}
|
|
12
|
+
export { isStringBetween, isStringBetween as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function isNotEmptyString(val, trimmed = true) {
|
|
2
|
+
if (typeof val !== 'string')
|
|
3
|
+
return false;
|
|
4
|
+
if (trimmed) {
|
|
5
|
+
for (let i = 0; i < val.length; i++) {
|
|
6
|
+
switch (val[i]) {
|
|
7
|
+
case ' ':
|
|
8
|
+
case '\t':
|
|
9
|
+
case '\n':
|
|
10
|
+
case '\r':
|
|
11
|
+
break;
|
|
12
|
+
default:
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return val.length > 0;
|
|
19
|
+
}
|
|
20
|
+
export { isNotEmptyString, isNotEmptyString as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function shorten(val, length, postfix = '...', truncate_words = true) {
|
|
2
|
+
if (typeof val !== 'string')
|
|
3
|
+
return '';
|
|
4
|
+
if (typeof postfix !== 'string' || !Number.isInteger(length) || length <= 0)
|
|
5
|
+
return val;
|
|
6
|
+
const sanitized = val.trim();
|
|
7
|
+
if (sanitized.length <= length)
|
|
8
|
+
return sanitized;
|
|
9
|
+
const truncated = sanitized.substring(0, length);
|
|
10
|
+
if (truncate_words)
|
|
11
|
+
return truncated + postfix;
|
|
12
|
+
let end = length;
|
|
13
|
+
while (end && sanitized[end] !== ' ' && sanitized[end - 1] !== ' ') {
|
|
14
|
+
end--;
|
|
15
|
+
}
|
|
16
|
+
return sanitized.substring(0, end).trimEnd() + postfix;
|
|
17
|
+
}
|
|
18
|
+
export { shorten, shorten as default };
|
package/formdata/toObject.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ type ToObjectConfig = {
|
|
|
11
11
|
* Whether or not we should normalize booleans, defaults to true if not set
|
|
12
12
|
*/
|
|
13
13
|
normalize_bool?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether or not we should normalize null, defaults to true if not set
|
|
16
|
+
*/
|
|
17
|
+
normalize_null?: boolean;
|
|
14
18
|
/**
|
|
15
19
|
* Whether or not we should normalize dates, defaults to true if not set
|
|
16
20
|
*/
|
package/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ declare module "array/join" {
|
|
|
26
26
|
valtrim?: boolean;
|
|
27
27
|
valround?: number;
|
|
28
28
|
}
|
|
29
|
-
function join(val:
|
|
29
|
+
function join<T>(val: T[] | Set<T>, opts?: joinOptions): string;
|
|
30
30
|
export { join, join as default };
|
|
31
31
|
}
|
|
32
32
|
declare module "object/merge" {
|
|
@@ -95,8 +95,8 @@ declare module "object/isNotEmpty" {
|
|
|
95
95
|
export { isNotEmptyObject, isNotEmptyObject as default };
|
|
96
96
|
}
|
|
97
97
|
declare module "array/groupBy" {
|
|
98
|
-
type Handler<T> = (val: T) => string | number | boolean;
|
|
99
|
-
function groupBy<T extends Record<string, any>>(
|
|
98
|
+
type Handler<T> = (val: T) => string | number | boolean | undefined;
|
|
99
|
+
function groupBy<T extends Record<string, any>>(val: T[] | Set<T>, handler: Handler<T> | keyof T): Record<string, T[]>;
|
|
100
100
|
export { groupBy, groupBy as default };
|
|
101
101
|
}
|
|
102
102
|
declare module "array/shuffle" {
|
|
@@ -107,7 +107,7 @@ declare module "array/split" {
|
|
|
107
107
|
type SplitOptions<T> = {
|
|
108
108
|
filter_fn?: (el: T) => boolean;
|
|
109
109
|
};
|
|
110
|
-
function split<T>(arr: T[]
|
|
110
|
+
function split<T>(arr: T[] | Set<T>, size: number, opts?: SplitOptions<T>): T[][];
|
|
111
111
|
export { split, split as default };
|
|
112
112
|
}
|
|
113
113
|
declare module "object/is" {
|
|
@@ -188,16 +188,20 @@ declare module "caching/LRU" {
|
|
|
188
188
|
export type LRUCacheOptions = {
|
|
189
189
|
max_size?: number;
|
|
190
190
|
};
|
|
191
|
-
class LRUCache<
|
|
191
|
+
class LRUCache<V> {
|
|
192
192
|
#private;
|
|
193
193
|
constructor(opts?: LRUCacheOptions);
|
|
194
194
|
get max_size(): number;
|
|
195
195
|
set max_size(max_size: number);
|
|
196
|
-
has(key:
|
|
197
|
-
get(key:
|
|
198
|
-
set(key:
|
|
199
|
-
del(key:
|
|
196
|
+
has(key: string): boolean;
|
|
197
|
+
get(key: string): V | undefined;
|
|
198
|
+
set(key: string, value: V): void;
|
|
199
|
+
del(key: string): void;
|
|
200
200
|
clear(): void;
|
|
201
|
+
private addToFront;
|
|
202
|
+
private removeNode;
|
|
203
|
+
private moveToFront;
|
|
204
|
+
private evictTail;
|
|
201
205
|
}
|
|
202
206
|
export { LRUCache, LRUCache as default };
|
|
203
207
|
}
|
|
@@ -284,6 +288,7 @@ declare module "formdata/toObject" {
|
|
|
284
288
|
raw?: string[] | true;
|
|
285
289
|
single?: string[];
|
|
286
290
|
normalize_bool?: boolean;
|
|
291
|
+
normalize_null?: boolean;
|
|
287
292
|
normalize_date?: boolean;
|
|
288
293
|
normalize_number?: boolean;
|
|
289
294
|
};
|
|
@@ -613,6 +618,12 @@ declare module "is" {
|
|
|
613
618
|
}>;
|
|
614
619
|
export { Is, Is as default };
|
|
615
620
|
}
|
|
621
|
+
declare module "hash/fnv1A" {
|
|
622
|
+
export const FNV_32 = 2166136261;
|
|
623
|
+
export const FNV_64 = 1099511628211;
|
|
624
|
+
function fnv1A(data: unknown, offset?: number): number;
|
|
625
|
+
export { fnv1A, fnv1A as default };
|
|
626
|
+
}
|
|
616
627
|
declare module "caching/memoize" {
|
|
617
628
|
function memoize<T extends (...args: any[]) => unknown>(fn: T, resolver?: (...args: Parameters<T>) => any, cache_duration_ms?: number | false, cache_max_size?: number): T;
|
|
618
629
|
export { memoize, memoize as default };
|
|
@@ -664,12 +675,6 @@ declare module "deep/index" {
|
|
|
664
675
|
export { deepSet as set } from "deep/set";
|
|
665
676
|
export { deepSet } from "deep/set";
|
|
666
677
|
}
|
|
667
|
-
declare module "hash/fnv1A" {
|
|
668
|
-
export const FNV_32 = 2166136261;
|
|
669
|
-
export const FNV_64 = 1099511628211;
|
|
670
|
-
function fnv1A(data: unknown, offset?: number): number;
|
|
671
|
-
export { fnv1A, fnv1A as default };
|
|
672
|
-
}
|
|
673
678
|
declare module "hash/guid" {
|
|
674
679
|
function guid(): string;
|
|
675
680
|
export { guid, guid as default };
|