@tolki/utils 1.0.2 → 1.2.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/dist/guards.js ADDED
@@ -0,0 +1,116 @@
1
+ function f(n) {
2
+ return Array.isArray(n);
3
+ }
4
+ function o(n) {
5
+ return !r(n) && typeof n == "object" && !f(n);
6
+ }
7
+ function c(n) {
8
+ return typeof n == "object";
9
+ }
10
+ function S(n) {
11
+ return !r(n) && !e(n) && c(n);
12
+ }
13
+ function i(n) {
14
+ return typeof n == "string";
15
+ }
16
+ function j(n) {
17
+ return !!(i(n) || t(n) || b(n));
18
+ }
19
+ function b(n) {
20
+ return !!(o(n) && s(n.toString));
21
+ }
22
+ function t(n) {
23
+ return typeof n == "number" && !isNaN(n);
24
+ }
25
+ function A(n) {
26
+ return t(n) && Number.isInteger(n);
27
+ }
28
+ function k(n) {
29
+ return t(n) && !Number.isInteger(n);
30
+ }
31
+ function F(n) {
32
+ return t(n) && n >= 0;
33
+ }
34
+ function d(n) {
35
+ return t(n) && n < 0;
36
+ }
37
+ function u(n) {
38
+ return typeof n == "boolean";
39
+ }
40
+ function s(n) {
41
+ return typeof n == "function";
42
+ }
43
+ function e(n) {
44
+ return typeof n > "u";
45
+ }
46
+ function y(n) {
47
+ return typeof n == "symbol";
48
+ }
49
+ function r(n) {
50
+ return n === null;
51
+ }
52
+ function m(n) {
53
+ return n instanceof Map;
54
+ }
55
+ function N(n) {
56
+ return n instanceof Set;
57
+ }
58
+ function h(n) {
59
+ return r(n) || e(n) || i(n) ? !1 : s(
60
+ n[Symbol.iterator]
61
+ );
62
+ }
63
+ function I(n) {
64
+ return n instanceof WeakMap;
65
+ }
66
+ function M(n) {
67
+ return n instanceof WeakSet;
68
+ }
69
+ function p(n) {
70
+ return Number.isNaN(n) ? !0 : t(n) ? n === 0 : e(n) || r(n) ? !0 : u(n) ? n === !1 : i(n) ? n.trim() === "" : m(n) || N(n) ? n.size === 0 : f(n) ? n.length === 0 : o(n) ? Object.keys(n).length === 0 : !1;
71
+ }
72
+ function O(n) {
73
+ return !p(n);
74
+ }
75
+ function g(n) {
76
+ return r(n) || u(n) || t(n) || i(n) || y(n) || e(n);
77
+ }
78
+ function W(n) {
79
+ return !g(n);
80
+ }
81
+ function P(n) {
82
+ return t(n) && Number.isFinite(n);
83
+ }
84
+ function T(n) {
85
+ return Array.isArray(n);
86
+ }
87
+ export {
88
+ T as isAccessibleData,
89
+ f as isArray,
90
+ u as isBoolean,
91
+ p as isFalsy,
92
+ P as isFiniteNumber,
93
+ k as isFloat,
94
+ s as isFunction,
95
+ A as isInteger,
96
+ h as isIterable,
97
+ m as isMap,
98
+ d as isNegativeNumber,
99
+ W as isNonPrimitive,
100
+ r as isNull,
101
+ t as isNumber,
102
+ o as isObject,
103
+ c as isObjectAny,
104
+ F as isPositiveNumber,
105
+ g as isPrimitive,
106
+ N as isSet,
107
+ i as isString,
108
+ j as isStringable,
109
+ y as isSymbol,
110
+ O as isTruthy,
111
+ S as isTruthyObject,
112
+ e as isUndefined,
113
+ I as isWeakMap,
114
+ M as isWeakSet,
115
+ b as objectToString
116
+ };
package/dist/index.js CHANGED
@@ -1,47 +1,55 @@
1
- import { castableToArray as s, compareValues as t, entriesKeyValue as r, getAccessibleValues as a, isAccessibleData as o, isArray as l, isBoolean as n, isFalsy as b, isFiniteNumber as u, isFloat as c, isFunction as y, isInteger as m, isMap as p, isNegativeNumber as A, isNonPrimitive as N, isNull as S, isNumber as g, isObject as F, isObjectAny as f, isPositiveNumber as v, isPrimitive as T, isSet as j, isString as O, isStringable as P, isSymbol as U, isTruthy as V, isTruthyObject as d, isUndefined as h, isUnsafeKey as k, isWeakMap as q, isWeakSet as w, looseEqual as z, lowerFirst as D, normalizeToArray as E, objectToString as J, resolveDefault as K, strictEqual as M, toArrayable as W, toJsonSerializable as x, toJsonable as B, toLower as I, toUpper as L, typeOf as C, upperFirst as G } from "./utils.js";
1
+ import { castableToArray as r, getAccessibleValues as s, normalizeToArray as t, toArrayable as o, toJsonSerializable as a, toJsonable as l } from "./cast.js";
2
+ import { compareValues as b, looseEqual as m, strictEqual as p } from "./equality.js";
3
+ import { isAccessibleData as y, isArray as c, isBoolean as f, isFalsy as A, isFiniteNumber as N, isFloat as S, isFunction as g, isInteger as x, isIterable as F, isMap as v, isNegativeNumber as T, isNonPrimitive as j, isNull as K, isNumber as O, isObject as P, isObjectAny as d, isPositiveNumber as h, isPrimitive as U, isSet as V, isString as k, isStringable as q, isSymbol as w, isTruthy as z, isTruthyObject as D, isUndefined as E, isWeakMap as I, isWeakSet as J, objectToString as M } from "./guards.js";
4
+ import { defineKey as B, entriesKeyValue as L, isPhpArrayKey as C, isUnsafeKey as G } from "./keys.js";
5
+ import { resolveDefault as Q, typeOf as R } from "./reflect.js";
6
+ import { lowerFirst as Y, toLower as Z, toUpper as _, upperFirst as $ } from "./string.js";
2
7
  export {
3
- s as castableToArray,
4
- t as compareValues,
5
- r as entriesKeyValue,
6
- a as getAccessibleValues,
7
- o as isAccessibleData,
8
- l as isArray,
9
- n as isBoolean,
10
- b as isFalsy,
11
- u as isFiniteNumber,
12
- c as isFloat,
13
- y as isFunction,
14
- m as isInteger,
15
- p as isMap,
16
- A as isNegativeNumber,
17
- N as isNonPrimitive,
18
- S as isNull,
19
- g as isNumber,
20
- F as isObject,
21
- f as isObjectAny,
22
- v as isPositiveNumber,
23
- T as isPrimitive,
24
- j as isSet,
25
- O as isString,
26
- P as isStringable,
27
- U as isSymbol,
28
- V as isTruthy,
29
- d as isTruthyObject,
30
- h as isUndefined,
31
- k as isUnsafeKey,
32
- q as isWeakMap,
33
- w as isWeakSet,
34
- z as looseEqual,
35
- D as lowerFirst,
36
- E as normalizeToArray,
37
- J as objectToString,
38
- K as resolveDefault,
39
- M as strictEqual,
40
- W as toArrayable,
41
- x as toJsonSerializable,
42
- B as toJsonable,
43
- I as toLower,
44
- L as toUpper,
45
- C as typeOf,
46
- G as upperFirst
8
+ r as castableToArray,
9
+ b as compareValues,
10
+ B as defineKey,
11
+ L as entriesKeyValue,
12
+ s as getAccessibleValues,
13
+ y as isAccessibleData,
14
+ c as isArray,
15
+ f as isBoolean,
16
+ A as isFalsy,
17
+ N as isFiniteNumber,
18
+ S as isFloat,
19
+ g as isFunction,
20
+ x as isInteger,
21
+ F as isIterable,
22
+ v as isMap,
23
+ T as isNegativeNumber,
24
+ j as isNonPrimitive,
25
+ K as isNull,
26
+ O as isNumber,
27
+ P as isObject,
28
+ d as isObjectAny,
29
+ C as isPhpArrayKey,
30
+ h as isPositiveNumber,
31
+ U as isPrimitive,
32
+ V as isSet,
33
+ k as isString,
34
+ q as isStringable,
35
+ w as isSymbol,
36
+ z as isTruthy,
37
+ D as isTruthyObject,
38
+ E as isUndefined,
39
+ G as isUnsafeKey,
40
+ I as isWeakMap,
41
+ J as isWeakSet,
42
+ m as looseEqual,
43
+ Y as lowerFirst,
44
+ t as normalizeToArray,
45
+ M as objectToString,
46
+ Q as resolveDefault,
47
+ p as strictEqual,
48
+ o as toArrayable,
49
+ a as toJsonSerializable,
50
+ l as toJsonable,
51
+ Z as toLower,
52
+ _ as toUpper,
53
+ R as typeOf,
54
+ $ as upperFirst
47
55
  };
package/dist/keys.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Figures out if the entry key should be a number or a string.
3
+ *
4
+ * @param value - The entry key value (number, string, or symbol)
5
+ * @returns The entry key as a number if it can be converted, otherwise returns the original value
6
+ */
7
+ export declare function entriesKeyValue<T extends PropertyKey>(value: T): T extends `${number}` ? number : T;
8
+ /**
9
+ * Check if a key is unsafe for property assignment (prototype pollution).
10
+ * Returns true for `__proto__`, `constructor`, and `prototype`.
11
+ *
12
+ * @param key - The key to check
13
+ * @returns True if the key could cause prototype pollution
14
+ */
15
+ export declare function isUnsafeKey(key: string): boolean;
16
+ /**
17
+ * Check whether a value can be used as a PHP array key. PHP accepts strings
18
+ * and integers in the inclusive range [-2^63, 2^63 - 1]; numbers outside that
19
+ * range are floats there, so they are rejected rather than producing a key PHP
20
+ * could never generate.
21
+ *
22
+ * @param value - The value to check
23
+ * @returns True if the value can be used as a PHP array key
24
+ */
25
+ export declare function isPhpArrayKey(value: unknown): value is string | number;
26
+ /**
27
+ * Define an own enumerable property on the target without going through a
28
+ * setter, so a key such as `__proto__` becomes a real own key rather than
29
+ * reaching `Object.prototype` through the inherited setter.
30
+ *
31
+ * @param target - The object to define the key on
32
+ * @param key - The key to define
33
+ * @param value - The value to store under the key
34
+ */
35
+ export declare function defineKey<TValue>(target: Record<string, TValue>, key: string, value: TValue): void;
36
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAUA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,EACjD,KAAK,EAAE,CAAC,GACT,CAAC,SAAS,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,CAMpC;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,GAAG,MAAM,CAatE;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACd,IAAI,CAON"}
package/dist/keys.js ADDED
@@ -0,0 +1,25 @@
1
+ import { isString as i, isInteger as o } from "./guards.js";
2
+ const t = 2 ** 63;
3
+ function f(r) {
4
+ return !isNaN(Number(r)) && !isNaN(parseFloat(String(r))) ? Number(r) : r;
5
+ }
6
+ function s(r) {
7
+ return r === "__proto__" || r === "constructor" || r === "prototype";
8
+ }
9
+ function c(r) {
10
+ return i(r) ? !0 : o(r) ? r >= -t && r < t : !1;
11
+ }
12
+ function p(r, e, n) {
13
+ Object.defineProperty(r, e, {
14
+ value: n,
15
+ enumerable: !0,
16
+ writable: !0,
17
+ configurable: !0
18
+ });
19
+ }
20
+ export {
21
+ p as defineKey,
22
+ f as entriesKeyValue,
23
+ c as isPhpArrayKey,
24
+ s as isUnsafeKey
25
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Get a more specific type description for debugging purposes.
3
+ * Differentiates between null, arrays, and other types.
4
+ *
5
+ * @param {unknown} v - The value to get the type of.
6
+ * @returns {string} A string describing the type.
7
+ * @example
8
+ * Get specific types
9
+ * typeOf(null); -> "null"
10
+ * typeOf([]); -> "array"
11
+ * typeOf({}); -> "object"
12
+ */
13
+ export declare function typeOf(v: unknown): string;
14
+ /**
15
+ * Helper function to resolve a default value (either direct value or lazy function).
16
+ *
17
+ * @param defaultValue - The default value or lazy function
18
+ * @returns The resolved default value
19
+ *
20
+ * @example
21
+ * resolveDefault('hello'); -> 'hello'
22
+ * resolveDefault(() => 'world'); -> 'world'
23
+ * resolveDefault(undefined); -> null
24
+ */
25
+ export declare function resolveDefault<D>(defaultValue?: D | (() => D)): D | null;
26
+ //# sourceMappingURL=reflect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflect.d.ts","sourceRoot":"","sources":["../src/reflect.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CASzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAOxE"}
@@ -0,0 +1,11 @@
1
+ import { isNull as n, isArray as t } from "./guards.js";
2
+ function i(r) {
3
+ return n(r) ? "object" : t(r) ? "array" : typeof r;
4
+ }
5
+ function f(r) {
6
+ return r === void 0 ? null : typeof r == "function" ? r() : r;
7
+ }
8
+ export {
9
+ f as resolveDefault,
10
+ i as typeOf
11
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Convert a string to lower-case.
3
+ */
4
+ export declare function toLower(value: string): string;
5
+ /**
6
+ * Convert a string to upper-case.
7
+ */
8
+ export declare function toUpper(value: string): string;
9
+ /**
10
+ * Convert the first character of a string to lower-case.
11
+ */
12
+ export declare function lowerFirst(value: string): string;
13
+ /**
14
+ * Convert the first character of a string to upper-case.
15
+ */
16
+ export declare function upperFirst(value: string): string;
17
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD"}
package/dist/string.js ADDED
@@ -0,0 +1,20 @@
1
+ function n(r) {
2
+ return r.toLowerCase();
3
+ }
4
+ function e(r) {
5
+ return r.toUpperCase();
6
+ }
7
+ function o(r) {
8
+ const t = [...r];
9
+ return t.length === 0 ? r : (t[0] = t[0].toLowerCase(), t.join(""));
10
+ }
11
+ function i(r) {
12
+ const t = [...r];
13
+ return t.length === 0 ? r : (t[0] = t[0].toUpperCase(), t.join(""));
14
+ }
15
+ export {
16
+ o as lowerFirst,
17
+ n as toLower,
18
+ e as toUpper,
19
+ i as upperFirst
20
+ };