@tolki/utils 1.6.1 → 1.6.3

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.
@@ -1,54 +1,23 @@
1
- class n extends Error {
2
- /**
3
- * Create a new exception instance.
4
- *
5
- * @param message - The exception message
6
- */
7
- constructor(e) {
8
- super(e), this.name = "InvalidArgumentException";
9
- }
10
- }
11
- class o extends Error {
12
- /**
13
- * Create a new exception instance.
14
- */
15
- constructor() {
16
- super(""), this.name = "ItemNotFoundException";
17
- }
18
- }
19
- class r extends Error {
20
- /** The number of items found, as Laravel's public `$count`. */
21
- count;
22
- /**
23
- * Create a new exception instance.
24
- *
25
- * @param count - The number of items the lookup matched
26
- */
27
- constructor(e) {
28
- super(`${e} items were found.`), this.name = "MultipleItemsFoundException", this.count = e;
29
- }
30
- /**
31
- * Get the number of items found.
32
- *
33
- * @returns The number of items the lookup matched
34
- */
35
- getCount() {
36
- return this.count;
37
- }
38
- }
39
- class s extends Error {
40
- /**
41
- * Create a new exception instance.
42
- *
43
- * @param message - The exception message
44
- */
45
- constructor(e) {
46
- super(e), this.name = "UnexpectedValueException";
47
- }
48
- }
49
- export {
50
- n as InvalidArgumentException,
51
- o as ItemNotFoundException,
52
- r as MultipleItemsFoundException,
53
- s as UnexpectedValueException
1
+ // src/exceptions.ts
2
+ var e = class extends Error {
3
+ constructor(e) {
4
+ super(e), this.name = "InvalidArgumentException";
5
+ }
6
+ }, t = class extends Error {
7
+ constructor() {
8
+ super(""), this.name = "ItemNotFoundException";
9
+ }
10
+ }, n = class extends Error {
11
+ count;
12
+ constructor(e) {
13
+ super(`${e} items were found.`), this.name = "MultipleItemsFoundException", this.count = e;
14
+ }
15
+ getCount() {
16
+ return this.count;
17
+ }
18
+ }, r = class extends Error {
19
+ constructor(e) {
20
+ super(e), this.name = "UnexpectedValueException";
21
+ }
54
22
  };
23
+ export { e as InvalidArgumentException, t as ItemNotFoundException, n as MultipleItemsFoundException, r as UnexpectedValueException };
package/dist/guards.js CHANGED
@@ -1,184 +1,137 @@
1
- function b(t) {
2
- return Array.isArray(t);
1
+ // src/guards.ts
2
+ function e(e) {
3
+ return Array.isArray(e);
3
4
  }
4
- function y(t) {
5
- return !o(t) && typeof t == "object" && !b(t);
5
+ function t(t) {
6
+ return !b(t) && typeof t == "object" && !e(t);
6
7
  }
7
- function m(t) {
8
- if (!y(t))
9
- return !1;
10
- const n = Object.getPrototypeOf(t);
11
- return n === Object.prototype || n === null;
8
+ function n(e) {
9
+ if (!t(e)) return !1;
10
+ let n = Object.getPrototypeOf(e);
11
+ return n === Object.prototype || n === null;
12
12
  }
13
- function w(t) {
14
- return m(t) && Object.hasOwn(t, "name") && e(t.name) && Object.hasOwn(t, "value") && (e(t.value) || r(t.value));
13
+ function r(e) {
14
+ return n(e) && Object.hasOwn(e, "name") && s(e.name) && Object.hasOwn(e, "value") && (s(e.value) || u(e.value));
15
15
  }
16
- function j(t) {
17
- return typeof t == "object";
16
+ function i(e) {
17
+ return typeof e == "object";
18
18
  }
19
- function P(t) {
20
- return !o(t) && !c(t) && j(t);
19
+ function a(e) {
20
+ return !b(e) && !v(e) && i(e);
21
21
  }
22
- function E(t) {
23
- if (!P(t) && !u(t))
24
- return !1;
25
- const n = Object.getOwnPropertyDescriptor(
26
- t,
27
- "constructor"
28
- )?.value;
29
- return u(n) && n.prototype === t;
22
+ function o(e) {
23
+ if (!a(e) && !_(e)) return !1;
24
+ let t = Object.getOwnPropertyDescriptor(e, "constructor")?.value;
25
+ return _(t) && t.prototype === e;
30
26
  }
31
- function e(t) {
32
- return typeof t == "string";
27
+ function s(e) {
28
+ return typeof e == "string";
33
29
  }
34
- function W(t) {
35
- return !!(e(t) || r(t) || S(t));
30
+ function c(e) {
31
+ return !!(s(e) || u(e) || l(e));
36
32
  }
37
- function S(t) {
38
- return !!(y(t) && u(t.toString));
33
+ function l(e) {
34
+ return !!(t(e) && _(e.toString));
39
35
  }
40
- function r(t) {
41
- return typeof t == "number" && !isNaN(t);
36
+ function u(e) {
37
+ return typeof e == "number" && !isNaN(e);
42
38
  }
43
- function d(t) {
44
- return r(t) && Number.isInteger(t);
39
+ function d(e) {
40
+ return u(e) && Number.isInteger(e);
45
41
  }
46
- function z(t) {
47
- return r(t) && !Number.isInteger(t);
42
+ function f(e) {
43
+ return u(e) && !Number.isInteger(e);
48
44
  }
49
- function R(t) {
50
- return d(t) && t >= -9223372036854776e3 && t < 2 ** 63 && !Object.is(t, -0);
45
+ function p(e) {
46
+ return d(e) && e >= -(2 ** 63) && e < 2 ** 63 && !Object.is(e, -0);
51
47
  }
52
- function _(t) {
53
- return r(t) && t >= 0;
48
+ function m(e) {
49
+ return u(e) && e >= 0;
54
50
  }
55
- function B(t) {
56
- return r(t) && t < 0;
51
+ function h(e) {
52
+ return u(e) && e < 0;
57
53
  }
58
- function N(t) {
59
- return typeof t == "boolean";
54
+ function g(e) {
55
+ return typeof e == "boolean";
60
56
  }
61
- function u(t) {
62
- return typeof t == "function";
57
+ function _(e) {
58
+ return typeof e == "function";
63
59
  }
64
- function c(t) {
65
- return typeof t > "u";
60
+ function v(e) {
61
+ return e === void 0;
66
62
  }
67
- function A(t) {
68
- return typeof t == "symbol";
63
+ function y(e) {
64
+ return typeof e == "symbol";
69
65
  }
70
- function o(t) {
71
- return t === null;
66
+ function b(e) {
67
+ return e === null;
72
68
  }
73
- function h(t) {
74
- return t instanceof Map;
69
+ function x(e) {
70
+ return e instanceof Map;
75
71
  }
76
- function g(t) {
77
- return t instanceof Set;
72
+ function S(e) {
73
+ return e instanceof Set;
78
74
  }
79
- function C(t) {
80
- return o(t) || c(t) || e(t) ? !1 : u(
81
- t[Symbol.iterator]
82
- );
75
+ function C(e) {
76
+ return b(e) || v(e) || s(e) ? !1 : _(e[Symbol.iterator]);
83
77
  }
84
- function D(t) {
85
- return t instanceof WeakMap;
78
+ function w(e) {
79
+ return e instanceof WeakMap;
86
80
  }
87
- function U(t) {
88
- return t instanceof WeakSet;
81
+ function T(e) {
82
+ return e instanceof WeakSet;
89
83
  }
90
- function k(t) {
91
- return Number.isNaN(t) ? !0 : r(t) ? t === 0 : c(t) || o(t) ? !0 : N(t) ? t === !1 : e(t) ? t.trim() === "" : h(t) || g(t) ? t.size === 0 : b(t) ? t.length === 0 : y(t) ? Object.keys(t).length === 0 : !1;
84
+ function E(n) {
85
+ return Number.isNaN(n) ? !0 : u(n) ? n === 0 : v(n) || b(n) ? !0 : g(n) ? n === !1 : s(n) ? n.trim() === "" : x(n) || S(n) ? n.size === 0 : e(n) ? n.length === 0 : t(n) ? Object.keys(n).length === 0 : !1;
92
86
  }
93
- function V(t) {
94
- return !k(t);
87
+ function D(e) {
88
+ return !E(e);
95
89
  }
96
- function x(t) {
97
- return t === !1 || t === null || c(t) || t === 0 || t === 0n || t === "" || t === "0" ? !0 : b(t) ? t.length === 0 : h(t) || g(t) ? t.size === 0 : m(t) ? Object.keys(t).length === 0 : !1;
90
+ function O(t) {
91
+ return t === !1 || t === null || v(t) || t === 0 || t === 0n || t === "" || t === "0" ? !0 : e(t) ? t.length === 0 : x(t) || S(t) ? t.size === 0 : n(t) ? Object.keys(t).length === 0 : !1;
98
92
  }
99
- const I = /^[ \t\n\r\v\f]*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?[ \t\n\r\v\f]*$/;
100
- function G(t) {
101
- return typeof t == "number" ? !0 : e(t) ? I.test(t) : !1;
93
+ var k = /^[ \t\n\r\v\f]*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?[ \t\n\r\v\f]*$/;
94
+ function A(e) {
95
+ return typeof e == "number" ? !0 : s(e) ? k.test(e) : !1;
102
96
  }
103
- function M(t) {
104
- return o(t) || N(t) || r(t) || e(t) || A(t) || c(t);
97
+ function j(e) {
98
+ return b(e) || g(e) || u(e) || s(e) || y(e) || v(e);
105
99
  }
106
- function H(t) {
107
- return !M(t);
100
+ function M(e) {
101
+ return !j(e);
102
+ }
103
+ function N(e) {
104
+ return u(e) && Number.isFinite(e);
105
+ }
106
+ function P(e) {
107
+ return Array.isArray(e);
108
108
  }
109
109
  function F(t) {
110
- return r(t) && Number.isFinite(t);
111
- }
112
- function $(t) {
113
- return Array.isArray(t);
114
- }
115
- function q(t) {
116
- return b(t) || m(t) || h(t);
117
- }
118
- function p(t) {
119
- if (e(t))
120
- return t;
121
- if (N(t))
122
- return t ? "1" : "";
123
- if (o(t))
124
- return "";
125
- if (F(t)) {
126
- const n = String(t);
127
- return n.includes("e") ? null : n;
128
- }
129
- return null;
130
- }
131
- function T(t, n) {
132
- const f = p(t), i = p(n);
133
- return f !== null && i !== null ? f === i : t === n || typeof t == "number" && typeof n == "number" && Number.isNaN(t) && Number.isNaN(n);
134
- }
135
- function J(t) {
136
- const n = /* @__PURE__ */ new Set(), f = [];
137
- for (const i of t) {
138
- const s = p(i);
139
- o(s) ? f.push(i) : n.add(s);
140
- }
141
- return (i) => {
142
- const s = p(i);
143
- return o(s) ? f.some((O) => T(i, O)) : n.has(s);
144
- };
145
- }
146
- export {
147
- $ as isAccessibleData,
148
- b as isArray,
149
- N as isBoolean,
150
- w as isEnumCase,
151
- k as isFalsy,
152
- F as isFiniteNumber,
153
- z as isFloat,
154
- u as isFunction,
155
- d as isInteger,
156
- C as isIterable,
157
- h as isMap,
158
- B as isNegativeNumber,
159
- H as isNonPrimitive,
160
- o as isNull,
161
- r as isNumber,
162
- y as isObject,
163
- j as isObjectAny,
164
- q as isPhpAccessible,
165
- x as isPhpFalsy,
166
- R as isPhpInt,
167
- G as isPhpNumeric,
168
- m as isPlainObject,
169
- _ as isPositiveNumber,
170
- M as isPrimitive,
171
- E as isPrototypeObject,
172
- g as isSet,
173
- e as isString,
174
- W as isStringable,
175
- A as isSymbol,
176
- V as isTruthy,
177
- P as isTruthyObject,
178
- c as isUndefined,
179
- D as isWeakMap,
180
- U as isWeakSet,
181
- S as objectToString,
182
- T as phpValueMatch,
183
- J as phpValueMatcher
184
- };
110
+ return e(t) || n(t) || x(t);
111
+ }
112
+ function I(e) {
113
+ if (s(e)) return e;
114
+ if (g(e)) return e ? "1" : "";
115
+ if (b(e)) return "";
116
+ if (N(e)) {
117
+ let t = String(e);
118
+ return t.includes("e") ? null : t;
119
+ }
120
+ return null;
121
+ }
122
+ function L(e, t) {
123
+ let n = I(e), r = I(t);
124
+ return n !== null && r !== null ? n === r : e === t || typeof e == "number" && typeof t == "number" && Number.isNaN(e) && Number.isNaN(t);
125
+ }
126
+ function R(e) {
127
+ let t = /* @__PURE__ */ new Set(), n = [];
128
+ for (let r of e) {
129
+ let e = I(r);
130
+ b(e) ? n.push(r) : t.add(e);
131
+ }
132
+ return (e) => {
133
+ let r = I(e);
134
+ return b(r) ? n.some((t) => L(e, t)) : t.has(r);
135
+ };
136
+ }
137
+ export { P as isAccessibleData, e as isArray, g as isBoolean, r as isEnumCase, E as isFalsy, N as isFiniteNumber, f as isFloat, _ as isFunction, d as isInteger, C as isIterable, x as isMap, h as isNegativeNumber, M as isNonPrimitive, b as isNull, u as isNumber, t as isObject, i as isObjectAny, F as isPhpAccessible, O as isPhpFalsy, p as isPhpInt, A as isPhpNumeric, n as isPlainObject, m as isPositiveNumber, j as isPrimitive, o as isPrototypeObject, S as isSet, s as isString, c as isStringable, y as isSymbol, D as isTruthy, a as isTruthyObject, v as isUndefined, w as isWeakMap, T as isWeakSet, l as objectToString, L as phpValueMatch, R as phpValueMatcher };
package/dist/index.js CHANGED
@@ -1,102 +1,11 @@
1
- import { arrayableItems as t, arrayableValues as i, castableToArray as s, cssListItemToString as a, getAccessibleValues as o, normalizeToArray as p, phpIntArgument as n, phpIntCast as l, phpStringCast as y, toArrayable as m, toJsonSerializable as u, toJsonable as c, toPhpKeyString as b } from "./cast.js";
2
- import { compareValues as g, looseEqual as x, operatorMatch as S, strictEqual as f } from "./equality.js";
3
- import { InvalidArgumentException as K, ItemNotFoundException as d, MultipleItemsFoundException as P, UnexpectedValueException as A } from "./exceptions.js";
4
- import { isAccessibleData as E, isArray as M, isBoolean as N, isEnumCase as T, isFalsy as F, isFiniteNumber as O, isFloat as V, isFunction as C, isInteger as j, isIterable as k, isMap as w, isNegativeNumber as L, isNonPrimitive as U, isNull as z, isNumber as D, isObject as R, isObjectAny as q, isPhpAccessible as J, isPhpFalsy as W, isPhpInt as B, isPhpNumeric as G, isPlainObject as H, isPositiveNumber as Q, isPrimitive as X, isPrototypeObject as Y, isSet as Z, isString as _, isStringable as $, isSymbol as ee, isTruthy as re, isTruthyObject as te, isUndefined as ie, isWeakMap as se, isWeakSet as ae, objectToString as oe, phpValueMatch as pe, phpValueMatcher as ne } from "./guards.js";
5
- import { arrayKeyExistsError as ye, defineKey as me, deleteMapKey as ue, entriesKeyValue as ce, hasOwnToString as be, isIllegalOffset as he, isIntegerLikeKey as ge, isPhpArrayKey as xe, isUnsafeKey as Se, keyedEntries as fe, nextIntegerKey as Ie, phpArrayKey as Ke, phpComputedKey as de, readMapKey as Pe, reindexIntegerKeys as Ae, renumberPhpIntegerKeys as ve, writeMapKey as Ee } from "./keys.js";
6
- import { resolvePadLength as Ne, resolveRangeSize as Te, resolveSliceRange as Fe, resolveSpliceRange as Oe, resolveTakeCount as Ve } from "./range.js";
7
- import { phpDebugType as je, phpTypeName as ke, resolveDefault as we, typeOf as Le } from "./reflect.js";
8
- import { createSortSpecComparator as ze, phpSortComparator as De } from "./sorting.js";
9
- import { arrayValueMessage as qe, lowerFirst as Je, toLower as We, toUpper as Be, upperFirst as Ge } from "./string.js";
10
- export {
11
- K as InvalidArgumentException,
12
- d as ItemNotFoundException,
13
- P as MultipleItemsFoundException,
14
- A as UnexpectedValueException,
15
- ye as arrayKeyExistsError,
16
- qe as arrayValueMessage,
17
- t as arrayableItems,
18
- i as arrayableValues,
19
- s as castableToArray,
20
- g as compareValues,
21
- ze as createSortSpecComparator,
22
- a as cssListItemToString,
23
- me as defineKey,
24
- ue as deleteMapKey,
25
- ce as entriesKeyValue,
26
- o as getAccessibleValues,
27
- be as hasOwnToString,
28
- E as isAccessibleData,
29
- M as isArray,
30
- N as isBoolean,
31
- T as isEnumCase,
32
- F as isFalsy,
33
- O as isFiniteNumber,
34
- V as isFloat,
35
- C as isFunction,
36
- he as isIllegalOffset,
37
- j as isInteger,
38
- ge as isIntegerLikeKey,
39
- k as isIterable,
40
- w as isMap,
41
- L as isNegativeNumber,
42
- U as isNonPrimitive,
43
- z as isNull,
44
- D as isNumber,
45
- R as isObject,
46
- q as isObjectAny,
47
- J as isPhpAccessible,
48
- xe as isPhpArrayKey,
49
- W as isPhpFalsy,
50
- B as isPhpInt,
51
- G as isPhpNumeric,
52
- H as isPlainObject,
53
- Q as isPositiveNumber,
54
- X as isPrimitive,
55
- Y as isPrototypeObject,
56
- Z as isSet,
57
- _ as isString,
58
- $ as isStringable,
59
- ee as isSymbol,
60
- re as isTruthy,
61
- te as isTruthyObject,
62
- ie as isUndefined,
63
- Se as isUnsafeKey,
64
- se as isWeakMap,
65
- ae as isWeakSet,
66
- fe as keyedEntries,
67
- x as looseEqual,
68
- Je as lowerFirst,
69
- Ie as nextIntegerKey,
70
- p as normalizeToArray,
71
- oe as objectToString,
72
- S as operatorMatch,
73
- Ke as phpArrayKey,
74
- de as phpComputedKey,
75
- je as phpDebugType,
76
- n as phpIntArgument,
77
- l as phpIntCast,
78
- De as phpSortComparator,
79
- y as phpStringCast,
80
- ke as phpTypeName,
81
- pe as phpValueMatch,
82
- ne as phpValueMatcher,
83
- Pe as readMapKey,
84
- Ae as reindexIntegerKeys,
85
- ve as renumberPhpIntegerKeys,
86
- we as resolveDefault,
87
- Ne as resolvePadLength,
88
- Te as resolveRangeSize,
89
- Fe as resolveSliceRange,
90
- Oe as resolveSpliceRange,
91
- Ve as resolveTakeCount,
92
- f as strictEqual,
93
- m as toArrayable,
94
- u as toJsonSerializable,
95
- c as toJsonable,
96
- We as toLower,
97
- b as toPhpKeyString,
98
- Be as toUpper,
99
- Le as typeOf,
100
- Ge as upperFirst,
101
- Ee as writeMapKey
102
- };
1
+ import { isAccessibleData as e, isArray as t, isBoolean as n, isEnumCase as r, isFalsy as i, isFiniteNumber as a, isFloat as o, isFunction as s, isInteger as c, isIterable as l, isMap as u, isNegativeNumber as d, isNonPrimitive as f, isNull as p, isNumber as m, isObject as h, isObjectAny as g, isPhpAccessible as _, isPhpFalsy as v, isPhpInt as y, isPhpNumeric as b, isPlainObject as x, isPositiveNumber as S, isPrimitive as C, isPrototypeObject as w, isSet as T, isString as E, isStringable as D, isSymbol as O, isTruthy as k, isTruthyObject as A, isUndefined as j, isWeakMap as M, isWeakSet as N, objectToString as P, phpValueMatch as F, phpValueMatcher as I } from "./guards.js";
2
+ import { phpDebugType as L, phpTypeName as R, resolveDefault as z, typeOf as B } from "./reflect.js";
3
+ import { arrayKeyExistsError as V, defineKey as H, deleteMapKey as U, entriesKeyValue as W, hasOwnToString as G, isIllegalOffset as K, isIntegerLikeKey as q, isPhpArrayKey as J, isUnsafeKey as Y, keyedEntries as X, nextIntegerKey as Z, phpArrayKey as Q, phpComputedKey as $, readMapKey as ee, reindexIntegerKeys as te, renumberPhpIntegerKeys as ne, writeMapKey as re } from "./keys.js";
4
+ import { arrayableItems as ie, arrayableValues as ae, castableToArray as oe, cssListItemToString as se, getAccessibleValues as ce, normalizeToArray as le, phpIntArgument as ue, phpIntCast as de, phpStringCast as fe, toArrayable as pe, toJsonSerializable as me, toJsonable as he, toPhpKeyString as ge } from "./cast.js";
5
+ import { compareValues as _e, looseEqual as ve, operatorMatch as ye, strictEqual as be } from "./equality.js";
6
+ import { InvalidArgumentException as xe, ItemNotFoundException as Se, MultipleItemsFoundException as Ce, UnexpectedValueException as we } from "./exceptions.js";
7
+ import { resolvePadLength as Te, resolveRangeSize as Ee, resolveSliceRange as De, resolveSpliceRange as Oe, resolveTakeCount as ke } from "./range.js";
8
+ import { createSortSpecComparator as Ae, phpSortComparator as je } from "./sorting.js";
9
+ import { arrayValueMessage as Me, escapeShellArg as Ne, escapeWindowsShellArg as Pe, lowerFirst as Fe, toLower as Ie, toUpper as Le, upperFirst as Re } from "./string.js";
10
+ import "./utils.js";
11
+ export { xe as InvalidArgumentException, Se as ItemNotFoundException, Ce as MultipleItemsFoundException, we as UnexpectedValueException, V as arrayKeyExistsError, Me as arrayValueMessage, ie as arrayableItems, ae as arrayableValues, oe as castableToArray, _e as compareValues, Ae as createSortSpecComparator, se as cssListItemToString, H as defineKey, U as deleteMapKey, W as entriesKeyValue, Ne as escapeShellArg, Pe as escapeWindowsShellArg, ce as getAccessibleValues, G as hasOwnToString, e as isAccessibleData, t as isArray, n as isBoolean, r as isEnumCase, i as isFalsy, a as isFiniteNumber, o as isFloat, s as isFunction, K as isIllegalOffset, c as isInteger, q as isIntegerLikeKey, l as isIterable, u as isMap, d as isNegativeNumber, f as isNonPrimitive, p as isNull, m as isNumber, h as isObject, g as isObjectAny, _ as isPhpAccessible, J as isPhpArrayKey, v as isPhpFalsy, y as isPhpInt, b as isPhpNumeric, x as isPlainObject, S as isPositiveNumber, C as isPrimitive, w as isPrototypeObject, T as isSet, E as isString, D as isStringable, O as isSymbol, k as isTruthy, A as isTruthyObject, j as isUndefined, Y as isUnsafeKey, M as isWeakMap, N as isWeakSet, X as keyedEntries, ve as looseEqual, Fe as lowerFirst, Z as nextIntegerKey, le as normalizeToArray, P as objectToString, ye as operatorMatch, Q as phpArrayKey, $ as phpComputedKey, L as phpDebugType, ue as phpIntArgument, de as phpIntCast, je as phpSortComparator, fe as phpStringCast, R as phpTypeName, F as phpValueMatch, I as phpValueMatcher, ee as readMapKey, te as reindexIntegerKeys, ne as renumberPhpIntegerKeys, z as resolveDefault, Te as resolvePadLength, Ee as resolveRangeSize, De as resolveSliceRange, Oe as resolveSpliceRange, ke as resolveTakeCount, be as strictEqual, pe as toArrayable, me as toJsonSerializable, he as toJsonable, Ie as toLower, ge as toPhpKeyString, Le as toUpper, B as typeOf, Re as upperFirst, re as writeMapKey };