@qilin-agent/cosmokit 0.0.0-stage → 1.8.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Shigma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,30 @@
1
- # Temporary Holding Version
1
+ # cosmokit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![Codecov](https://img.shields.io/codecov/c/github/shigma/cosmokit?style=flat-square)](https://codecov.io/gh/shigma/cosmokit)
4
+ [![npm](https://img.shields.io/npm/v/cosmokit?style=flat-square)](https://www.npmjs.com/package/cosmokit)
5
+
6
+ A collection of common utilities.
7
+
8
+ ## Usage
9
+
10
+ ### Node.js
11
+
12
+ ```sh
13
+ npm install cosmokit
14
+ ```
15
+
16
+ ```ts
17
+ import cosmokit from 'cosmokit'
18
+ ```
19
+
20
+ ### Deno
21
+
22
+ ```ts
23
+ import cosmokit from 'npm:cosmokit@latest'
24
+ ```
25
+
26
+ ## Config references
27
+
28
+ `Volatile<T>` exposes `get()` for immutable data snapshots. `createVolatile()` copies and freezes validated data; framework-owned `updateVolatile()` transfers a candidate snapshot into an existing reference. Framework-owned `volatileEntries()` enumerates references and their paths through plain config containers, stopping at snapshots and opaque objects. The shared symbol protocol recognizes references across ESM/CJS copies. Plugin consumers import the type from Cordis and retain the reference rather than caching values between operations.
29
+
30
+ `deepEqual()` treats two volatile references as equal regardless of their snapshots. Strict comparisons distinguish null from undefined recursively, compare URLs by normalized `href` and other opaque objects by identity, and treat distinct cyclic structures as unequal. Array comparison visits every index and treats holes as undefined. Snapshot-change detection must compare `.get()` results separately.
package/lib/index.js ADDED
@@ -0,0 +1,418 @@
1
+ //#region lib/types/misc.js
2
+ /** No-op callback returning `undefined` at runtime and `any` at type level. */
3
+ function noop() {}
4
+ /** Return true when a value is `null` or `undefined`. */
5
+ function isNullable(value) {
6
+ return value === null || value === void 0;
7
+ }
8
+ /** Return true when a value is neither `null` nor `undefined`. */
9
+ function isNonNullable(value) {
10
+ return !isNullable(value);
11
+ }
12
+ /** Return true for non-array object values. */
13
+ function isPlainObject(data) {
14
+ return data && typeof data === "object" && !Array.isArray(data);
15
+ }
16
+ /** Filter object entries and return a new object. */
17
+ function filterKeys(object, filter) {
18
+ return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
19
+ }
20
+ /** Map object values while preserving the original key set. */
21
+ function mapValues(object, transform) {
22
+ return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
23
+ }
24
+ /** Pick selected keys from an object, optionally including `undefined` values. */
25
+ function pick(source, keys, forced) {
26
+ if (!keys) return { ...source };
27
+ const result = {};
28
+ for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
29
+ return result;
30
+ }
31
+ /** Omit selected keys from a shallow object copy. */
32
+ function omit(source, keys) {
33
+ if (!keys) return { ...source };
34
+ const result = { ...source };
35
+ for (const key of keys) Reflect.deleteProperty(result, key);
36
+ return result;
37
+ }
38
+ /** Define a non-enumerable writable property and return the object. */
39
+ function defineProperty(object, key, value) {
40
+ return Object.defineProperty(object, key, {
41
+ writable: true,
42
+ value,
43
+ enumerable: false
44
+ });
45
+ }
46
+ //#endregion
47
+ //#region lib/types/array.js
48
+ /** Return true when every item in `array2` is present in `array1`. */
49
+ function contain(array1, array2) {
50
+ return array2.every((item) => array1.includes(item));
51
+ }
52
+ /** Return items that appear in both arrays. */
53
+ function intersection(array1, array2) {
54
+ return array1.filter((item) => array2.includes(item));
55
+ }
56
+ /** Return items from `array1` that do not appear in `array2`. */
57
+ function difference(array1, array2) {
58
+ return array1.filter((item) => !array2.includes(item));
59
+ }
60
+ /** Return the set-union of two arrays while preserving first occurrence order. */
61
+ function union(array1, array2) {
62
+ return Array.from(new Set([...array1, ...array2]));
63
+ }
64
+ /** Remove duplicate values while preserving first occurrence order. */
65
+ function deduplicate(array) {
66
+ return [...new Set(array)];
67
+ }
68
+ /** Remove one item from an array and report whether it was found. */
69
+ function remove(list, item) {
70
+ const index = list?.indexOf(item);
71
+ if (index >= 0) {
72
+ list.splice(index, 1);
73
+ return true;
74
+ } else return false;
75
+ }
76
+ /** Normalize nullish, scalar, or array input to an array. */
77
+ function makeArray(source) {
78
+ return Array.isArray(source) ? source : isNullable(source) ? [] : [source];
79
+ }
80
+ //#endregion
81
+ //#region lib/types/volatile.js
82
+ /** Shared config references used by schema validators and plugin runtimes. */
83
+ const write = Symbol.for("cosmokit.volatile.write");
84
+ function snapshot(value, ancestors = /* @__PURE__ */ new Set()) {
85
+ if (typeof value === "function") throw new TypeError("volatile config cannot contain functions");
86
+ if (value === null || typeof value !== "object") return value;
87
+ if (ancestors.has(value)) throw new TypeError("volatile config cannot contain cycles");
88
+ ancestors.add(value);
89
+ try {
90
+ if (Array.isArray(value)) return Object.freeze(value.map((item) => snapshot(item, ancestors)));
91
+ if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new TypeError("volatile config objects must be plain objects or arrays");
92
+ return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, snapshot(item, ancestors)])));
93
+ } finally {
94
+ ancestors.delete(value);
95
+ }
96
+ }
97
+ /**
98
+ * Create a detached reference containing an immutable copy of the supplied data.
99
+ * @param value - validated config data; class instances and functions are unsupported.
100
+ * @returns a reference whose value is updated only by its owning runtime.
101
+ */
102
+ function createVolatile(value) {
103
+ let current = snapshot(value);
104
+ return Object.freeze({
105
+ get: () => current,
106
+ [write]: (value) => {
107
+ current = value;
108
+ }
109
+ });
110
+ }
111
+ /**
112
+ * Identify references across ESM/CJS copies of the shared library.
113
+ * @param value - a parsed config value.
114
+ * @returns whether the value implements the shared reference protocol.
115
+ */
116
+ function isVolatile(value) {
117
+ return typeof value === "object" && value !== null && write in value;
118
+ }
119
+ /**
120
+ * Collect config references without descending into their snapshots or opaque objects.
121
+ * @internal
122
+ * @param value - parsed config; cyclic ordinary fields are visited once per path.
123
+ * @returns references and their object-key paths, including an empty path for a root reference.
124
+ */
125
+ function volatileEntries(value) {
126
+ const ancestors = /* @__PURE__ */ new Set();
127
+ function visit(value, path) {
128
+ if (isVolatile(value)) return [{
129
+ path,
130
+ ref: value
131
+ }];
132
+ if (!value || typeof value !== "object" || ancestors.has(value)) return [];
133
+ if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) return [];
134
+ ancestors.add(value);
135
+ try {
136
+ return Object.entries(value).flatMap(([key, child]) => visit(child, [...path, key]));
137
+ } finally {
138
+ ancestors.delete(value);
139
+ }
140
+ }
141
+ return visit(value, []);
142
+ }
143
+ /**
144
+ * Commit an already validated immutable snapshot from another reference.
145
+ * @internal
146
+ * @param target - the owning plugin's stable reference.
147
+ * @param source - a newly parsed candidate reference.
148
+ */
149
+ function updateVolatile(target, source) {
150
+ target[write](source.get());
151
+ }
152
+ //#endregion
153
+ //#region lib/types/types.js
154
+ /** Test values using `instanceof` with a `toStringTag` fallback. */
155
+ function is(type, value) {
156
+ if (arguments.length === 1) return (value) => is(type, value);
157
+ return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
158
+ }
159
+ function isArrayBufferLike(value) {
160
+ return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
161
+ }
162
+ function isArrayBufferSource(value) {
163
+ return isArrayBufferLike(value) || ArrayBuffer.isView(value);
164
+ }
165
+ /** Binary source detection and base64/hex conversion helpers. */
166
+ var Binary;
167
+ (function(Binary) {
168
+ Binary.is = isArrayBufferLike;
169
+ Binary.isSource = isArrayBufferSource;
170
+ function fromSource(source) {
171
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
172
+ else return source;
173
+ }
174
+ Binary.fromSource = fromSource;
175
+ function toBase64(source) {
176
+ source = fromSource(source);
177
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
178
+ let binary = "";
179
+ const bytes = new Uint8Array(source);
180
+ for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
181
+ return btoa(binary);
182
+ }
183
+ Binary.toBase64 = toBase64;
184
+ function fromBase64(source) {
185
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
186
+ return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
187
+ }
188
+ Binary.fromBase64 = fromBase64;
189
+ function toHex(source) {
190
+ source = fromSource(source);
191
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
192
+ return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
193
+ }
194
+ Binary.toHex = toHex;
195
+ function fromHex(source) {
196
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
197
+ const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
198
+ const buffer = [];
199
+ for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
200
+ return Uint8Array.from(buffer).buffer;
201
+ }
202
+ Binary.fromHex = fromHex;
203
+ })(Binary || (Binary = {}));
204
+ /** Decode a base64 string into binary data. */
205
+ const base64ToArrayBuffer = Binary.fromBase64;
206
+ /** Encode binary data as base64. */
207
+ const arrayBufferToBase64 = Binary.toBase64;
208
+ /** Decode a hex string into binary data. */
209
+ const hexToArrayBuffer = Binary.fromHex;
210
+ /** Encode binary data as hex. */
211
+ const arrayBufferToHex = Binary.toHex;
212
+ /** Deep-clone common JavaScript values while preserving prototypes and cycles. */
213
+ function clone(source, refs = /* @__PURE__ */ new Map()) {
214
+ if (!source || typeof source !== "object") return source;
215
+ if (is("Date", source)) return new Date(source.valueOf());
216
+ if (is("RegExp", source)) return new RegExp(source.source, source.flags);
217
+ if (isArrayBufferLike(source)) return source.slice(0);
218
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
219
+ const cached = refs.get(source);
220
+ if (cached) return cached;
221
+ if (Array.isArray(source)) {
222
+ const result = [];
223
+ refs.set(source, result);
224
+ source.forEach((value, index) => {
225
+ result[index] = Reflect.apply(clone, null, [value, refs]);
226
+ });
227
+ return result;
228
+ }
229
+ const result = Object.create(Object.getPrototypeOf(source));
230
+ refs.set(source, result);
231
+ for (const key of Reflect.ownKeys(source)) {
232
+ const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
233
+ if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
234
+ Reflect.defineProperty(result, key, descriptor);
235
+ }
236
+ return result;
237
+ }
238
+ /**
239
+ * Compare values recursively, treating two volatile references as equal regardless of value.
240
+ * Strict comparison distinguishes null/undefined, treats opaque objects by identity,
241
+ * compares URLs by normalized href, treats array holes as undefined, and considers distinct cyclic structures unequal.
242
+ * @param a - first value.
243
+ * @param b - second value.
244
+ * @param strict - whether to require strict data equality outside volatile references.
245
+ * @returns whether the values compare equal.
246
+ */
247
+ function deepEqual(a, b, strict) {
248
+ const ancestors = /* @__PURE__ */ new Set();
249
+ function compare(a, b) {
250
+ if (a === b) return true;
251
+ if (isVolatile(a) || isVolatile(b)) return isVolatile(a) && isVolatile(b);
252
+ if (!strict && isNullable(a) && isNullable(b)) return true;
253
+ if (typeof a !== typeof b || typeof a !== "object" || !a || !b) return false;
254
+ if (ancestors.has(a)) return false;
255
+ function check(test, then) {
256
+ return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
257
+ }
258
+ ancestors.add(a);
259
+ try {
260
+ return check(Array.isArray, (a, b) => {
261
+ if (a.length !== b.length) return false;
262
+ for (let index = 0; index < a.length; index++) if (!compare(a[index], b[index])) return false;
263
+ return true;
264
+ }) ?? check(is("Date"), (a, b) => a.valueOf() === b.valueOf()) ?? check(is("URL"), (a, b) => a.href === b.href) ?? check(is("RegExp"), (a, b) => a.source === b.source && a.flags === b.flags) ?? check(isArrayBufferLike, (a, b) => {
265
+ if (a.byteLength !== b.byteLength) return false;
266
+ const viewA = new Uint8Array(a);
267
+ const viewB = new Uint8Array(b);
268
+ for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
269
+ return true;
270
+ }) ?? ((!strict || [a, b].every((value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) && Object.keys({
271
+ ...a,
272
+ ...b
273
+ }).every((key) => compare(a[key], b[key])));
274
+ } finally {
275
+ ancestors.delete(a);
276
+ }
277
+ }
278
+ return compare(a, b);
279
+ }
280
+ //#endregion
281
+ //#region lib/types/string.js
282
+ /** Uppercase the first character of a string. */
283
+ function capitalize(source) {
284
+ return source.charAt(0).toUpperCase() + source.slice(1);
285
+ }
286
+ /** Lowercase the first character of a string. */
287
+ function uncapitalize(source) {
288
+ return source.charAt(0).toLowerCase() + source.slice(1);
289
+ }
290
+ /** Convert dash or underscore delimited text to camelCase. */
291
+ function camelCase(source) {
292
+ return source.replace(/[_-][a-z]/g, (str) => str.slice(1).toUpperCase());
293
+ }
294
+ function tokenize(source, delimiters, delimiter) {
295
+ const output = [];
296
+ let state = 0;
297
+ for (let i = 0; i < source.length; i++) {
298
+ const code = source.charCodeAt(i);
299
+ if (code >= 65 && code <= 90) {
300
+ if (state === 1) {
301
+ const next = source.charCodeAt(i + 1);
302
+ if (next >= 97 && next <= 122) output.push(delimiter);
303
+ output.push(code + 32);
304
+ } else {
305
+ if (state !== 0) output.push(delimiter);
306
+ output.push(code + 32);
307
+ }
308
+ state = 1;
309
+ } else if (code >= 97 && code <= 122) {
310
+ output.push(code);
311
+ state = 2;
312
+ } else if (delimiters.includes(code)) {
313
+ if (state !== 0) output.push(delimiter);
314
+ state = 0;
315
+ } else output.push(code);
316
+ }
317
+ return String.fromCharCode(...output);
318
+ }
319
+ /** Convert text to dash-delimited parameter case. */
320
+ function paramCase(source) {
321
+ return tokenize(source, [45, 95], 45);
322
+ }
323
+ /** Convert text to underscore-delimited snake case. */
324
+ function snakeCase(source) {
325
+ return tokenize(source, [45, 95], 95);
326
+ }
327
+ /** Runtime alias for `camelCase`. */
328
+ const camelize = camelCase;
329
+ /** Runtime alias for `paramCase`. */
330
+ const hyphenate = paramCase;
331
+ /** Format a property key as a JavaScript member access suffix. */
332
+ function formatProperty(key) {
333
+ if (typeof key !== "string") return `[${key.toString()}]`;
334
+ return /^[a-z_$][\w$]*$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
335
+ }
336
+ /** Remove one trailing slash from a path string. */
337
+ function trimSlash(source) {
338
+ return source.replace(/\/$/, "");
339
+ }
340
+ /** Ensure a path starts with `/` and has no trailing slash. */
341
+ function sanitize(source) {
342
+ if (!source.startsWith("/")) source = "/" + source;
343
+ return trimSlash(source);
344
+ }
345
+ //#endregion
346
+ //#region lib/types/time.js
347
+ /** Time constants plus parsing and formatting helpers. */
348
+ var Time;
349
+ (function(Time) {
350
+ Time.millisecond = 1;
351
+ Time.second = 1e3;
352
+ Time.minute = Time.second * 60;
353
+ Time.hour = Time.minute * 60;
354
+ Time.day = Time.hour * 24;
355
+ Time.week = Time.day * 7;
356
+ let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
357
+ function setTimezoneOffset(offset) {
358
+ timezoneOffset = offset;
359
+ }
360
+ Time.setTimezoneOffset = setTimezoneOffset;
361
+ function getTimezoneOffset() {
362
+ return timezoneOffset;
363
+ }
364
+ Time.getTimezoneOffset = getTimezoneOffset;
365
+ function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
366
+ if (typeof date === "number") date = new Date(date);
367
+ if (offset === void 0) offset = timezoneOffset;
368
+ return Math.floor((date.valueOf() / Time.minute - offset) / 1440);
369
+ }
370
+ Time.getDateNumber = getDateNumber;
371
+ function fromDateNumber(value, offset) {
372
+ const date = new Date(value * Time.day);
373
+ if (offset === void 0) offset = timezoneOffset;
374
+ return new Date(+date + offset * Time.minute);
375
+ }
376
+ Time.fromDateNumber = fromDateNumber;
377
+ const numeric = /\d+(?:\.\d+)?/.source;
378
+ const timeRegExp = new RegExp(`^${[
379
+ "w(?:eek(?:s)?)?",
380
+ "d(?:ay(?:s)?)?",
381
+ "h(?:our(?:s)?)?",
382
+ "m(?:in(?:ute)?(?:s)?)?",
383
+ "s(?:ec(?:ond)?(?:s)?)?"
384
+ ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
385
+ function parseTime(source) {
386
+ const capture = timeRegExp.exec(source);
387
+ if (!capture) return 0;
388
+ return (parseFloat(capture[1]) * Time.week || 0) + (parseFloat(capture[2]) * Time.day || 0) + (parseFloat(capture[3]) * Time.hour || 0) + (parseFloat(capture[4]) * Time.minute || 0) + (parseFloat(capture[5]) * Time.second || 0);
389
+ }
390
+ Time.parseTime = parseTime;
391
+ function parseDate(date) {
392
+ const parsed = parseTime(date);
393
+ if (parsed) date = Date.now() + parsed;
394
+ else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
395
+ else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
396
+ return date ? new Date(date) : /* @__PURE__ */ new Date();
397
+ }
398
+ Time.parseDate = parseDate;
399
+ function format(ms) {
400
+ const abs = Math.abs(ms);
401
+ if (abs >= Time.day - Time.hour / 2) return Math.round(ms / Time.day) + "d";
402
+ else if (abs >= Time.hour - Time.minute / 2) return Math.round(ms / Time.hour) + "h";
403
+ else if (abs >= Time.minute - Time.second / 2) return Math.round(ms / Time.minute) + "m";
404
+ else if (abs >= Time.second) return Math.round(ms / Time.second) + "s";
405
+ return ms + "ms";
406
+ }
407
+ Time.format = format;
408
+ function toDigits(source, length = 2) {
409
+ return source.toString().padStart(length, "0");
410
+ }
411
+ Time.toDigits = toDigits;
412
+ function template(template, time = /* @__PURE__ */ new Date()) {
413
+ return template.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
414
+ }
415
+ Time.template = template;
416
+ })(Time || (Time = {}));
417
+ //#endregion
418
+ export { Binary, Time, arrayBufferToBase64, arrayBufferToHex, base64ToArrayBuffer, camelCase, camelize, capitalize, clone, contain, createVolatile, deduplicate, deepEqual, defineProperty, difference, filterKeys, formatProperty, hexToArrayBuffer, hyphenate, intersection, is, isNonNullable, isNullable, isPlainObject, isVolatile, makeArray, mapValues, mapValues as valueMap, noop, omit, paramCase, pick, remove, sanitize, snakeCase, trimSlash, uncapitalize, union, updateVolatile, volatileEntries };
@@ -0,0 +1,15 @@
1
+ /** Return true when every item in `array2` is present in `array1`. */
2
+ export declare function contain(array1: readonly any[], array2: readonly any[]): boolean;
3
+ /** Return items that appear in both arrays. */
4
+ export declare function intersection<T>(array1: readonly T[], array2: readonly T[]): T[];
5
+ /** Return items from `array1` that do not appear in `array2`. */
6
+ export declare function difference<S>(array1: readonly S[], array2: readonly any[]): S[];
7
+ /** Return the set-union of two arrays while preserving first occurrence order. */
8
+ export declare function union<T>(array1: readonly T[], array2: readonly T[]): T[];
9
+ /** Remove duplicate values while preserving first occurrence order. */
10
+ export declare function deduplicate<T>(array: readonly T[]): T[];
11
+ /** Remove one item from an array and report whether it was found. */
12
+ export declare function remove<T>(list: T[], item: T): boolean;
13
+ /** Normalize nullish, scalar, or array input to an array. */
14
+ export declare function makeArray<T>(source: null | undefined | T | T[]): T[];
15
+ //# sourceMappingURL=array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/array.ts"],"names":[],"mappings":"AAEA,sEAAsE;AACtE,wBAAgB,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,EAAE,EAAE,MAAM,EAAE,SAAS,GAAG,EAAE,WAErE;AAED,+CAA+C;AAC/C,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAEzE;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,GAAG,EAAE,OAEzE;AAED,kFAAkF;AAClF,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAElE;AAED,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,OAEjD;AAED,qEAAqE;AACrE,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,WAQ3C;AAED,6DAA6D;AAC7D,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,CAAC,EAAE,OAE9D"}
@@ -0,0 +1,13 @@
1
+ /** Array set and normalization helpers. */
2
+ export * from './array.ts';
3
+ /** Runtime type, binary, clone, and equality helpers. */
4
+ export * from './types.ts';
5
+ /** Shared utility types and object helpers. */
6
+ export * from './misc.ts';
7
+ /** String case, path, and property formatting helpers. */
8
+ export * from './string.ts';
9
+ /** Time constants, parsing, and formatting helpers. */
10
+ export * from './time.ts';
11
+ /** Immutable config references shared by schema validators and runtimes. */
12
+ export * from './volatile.ts';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,cAAc,YAAY,CAAA;AAC1B,yDAAyD;AACzD,cAAc,YAAY,CAAA;AAC1B,+CAA+C;AAC/C,cAAc,WAAW,CAAA;AACzB,0DAA0D;AAC1D,cAAc,aAAa,CAAA;AAC3B,uDAAuD;AACvD,cAAc,WAAW,CAAA;AACzB,4EAA4E;AAC5E,cAAc,eAAe,CAAA"}
@@ -0,0 +1,41 @@
1
+ /** String/symbol keyed dictionary type. */
2
+ export type Dict<T = any, K extends string | symbol = string> = {
3
+ [key in K]: T;
4
+ };
5
+ /** Safely read `T[K]`, returning `never` when `K` is not a key of `T`. */
6
+ export type Get<T extends {}, K> = K extends keyof T ? T[K] : never;
7
+ /** Conditional extraction helper with a configurable return type. */
8
+ export type Extract<S, T, U = S> = S extends T ? U : never;
9
+ /** Accept a value or an array, unless the value is already an array type. */
10
+ export type MaybeArray<T> = [T] extends [unknown[]] ? T : T | T[];
11
+ /** Wrap a value in `Promise`, preserving the resolved type of existing promises. */
12
+ export type Promisify<T> = Promise<T extends Promise<infer S> ? S : T>;
13
+ /** Accept a value or promise unless the value type is already promise-like. */
14
+ export type Awaitable<T> = [T] extends [Promise<unknown>] ? T : T | Promise<T>;
15
+ /** Convert a union type to an intersection type. */
16
+ export type Intersect<U> = (U extends any ? (arg: U) => void : never) extends ((arg: infer I) => void) ? I : never;
17
+ /** No-op callback returning `undefined` at runtime and `any` at type level. */
18
+ export declare function noop(): any;
19
+ /** Return true when a value is `null` or `undefined`. */
20
+ export declare function isNullable(value: any): value is null | undefined | void;
21
+ /** Return true when a value is neither `null` nor `undefined`. */
22
+ export declare function isNonNullable<T>(value: T): value is NonNullable<T>;
23
+ /** Return true for non-array object values. */
24
+ export declare function isPlainObject(data: any): any;
25
+ /** Filter object entries with a key type guard. */
26
+ export declare function filterKeys<T, K extends string, U extends K>(object: Dict<T, K>, filter: (key: K, value: T) => key is U): Dict<T, U>;
27
+ /** Filter object entries with a boolean predicate. */
28
+ export declare function filterKeys<T, K extends string>(object: Dict<T, K>, filter: (key: K, value: T) => boolean): Dict<T, K>;
29
+ /** Map object values while preserving the original key set. */
30
+ export declare function mapValues<U, T, K extends string>(object: Dict<T, K>, transform: (value: T, key: K) => U): Dict<U, K>;
31
+ /** Alias for `mapValues`. */
32
+ export { mapValues as valueMap };
33
+ /** Pick selected keys from an object, optionally including `undefined` values. */
34
+ export declare function pick<T extends object, K extends keyof T>(source: T, keys?: Iterable<K>, forced?: boolean): Pick<T, K>;
35
+ /** Omit selected keys from a shallow object copy. */
36
+ export declare function omit<T, K extends keyof T>(source: T, keys?: Iterable<K>): Omit<T, K>;
37
+ /** Define a non-enumerable writable property with a typed key. */
38
+ export declare function defineProperty<T, K extends keyof T>(object: T, key: K, value: T[K]): T;
39
+ /** Define a non-enumerable writable property with an arbitrary key. */
40
+ export declare function defineProperty<T, K extends keyof any>(object: T, key: K, value: any): T;
41
+ //# sourceMappingURL=misc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../src/misc.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,MAA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,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,cAOxG;AAED,qDAAqD;AACrD,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,cAOvE;AAED,kEAAkE;AAClE,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AACvF,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,CAAA"}
@@ -0,0 +1,89 @@
1
+ /** Uppercase the first character of a string. */
2
+ export declare function capitalize(source: string): string;
3
+ /** Lowercase the first character of a string. */
4
+ export declare function uncapitalize(source: string): string;
5
+ /** Convert dash or underscore delimited text to camelCase. */
6
+ export declare function camelCase(source: string): string;
7
+ /** Convert text to dash-delimited parameter case. */
8
+ export declare function paramCase(source: string): string;
9
+ /** Convert text to underscore-delimited snake case. */
10
+ export declare function snakeCase(source: string): string;
11
+ /** Runtime alias for `camelCase`. */
12
+ export declare const camelize: typeof camelCase;
13
+ /** Runtime alias for `paramCase`. */
14
+ export declare const hyphenate: typeof paramCase;
15
+ declare namespace Letter {
16
+ interface LowerToUpper {
17
+ a: 'A';
18
+ b: 'B';
19
+ c: 'C';
20
+ d: 'D';
21
+ e: 'E';
22
+ f: 'F';
23
+ g: 'G';
24
+ h: 'H';
25
+ i: 'I';
26
+ j: 'J';
27
+ k: 'K';
28
+ l: 'L';
29
+ m: 'M';
30
+ n: 'N';
31
+ o: 'O';
32
+ p: 'P';
33
+ q: 'Q';
34
+ r: 'R';
35
+ s: 'S';
36
+ t: 'T';
37
+ u: 'U';
38
+ v: 'V';
39
+ w: 'W';
40
+ x: 'X';
41
+ y: 'Y';
42
+ z: 'Z';
43
+ }
44
+ interface UpperToLower {
45
+ A: 'a';
46
+ B: 'b';
47
+ C: 'c';
48
+ D: 'd';
49
+ E: 'e';
50
+ F: 'f';
51
+ G: 'g';
52
+ H: 'h';
53
+ I: 'i';
54
+ J: 'j';
55
+ K: 'k';
56
+ L: 'l';
57
+ M: 'm';
58
+ N: 'n';
59
+ O: 'o';
60
+ P: 'p';
61
+ Q: 'q';
62
+ R: 'r';
63
+ S: 's';
64
+ T: 't';
65
+ U: 'u';
66
+ V: 'v';
67
+ W: 'w';
68
+ X: 'x';
69
+ Y: 'y';
70
+ Z: 'z';
71
+ }
72
+ export type Upper = keyof UpperToLower;
73
+ export type Lower = keyof LowerToUpper;
74
+ export type ToUpper<S extends string> = S extends Lower ? LowerToUpper[S] : S;
75
+ export type ToLower<S extends string, P extends string = ''> = S extends Upper ? `${P}${UpperToLower[S]}` : S;
76
+ export {};
77
+ }
78
+ /** Type-level conversion from dash-delimited text to camelCase. */
79
+ export type camelize<S extends string> = S extends `${infer L}-${infer M}${infer R}` ? `${L}${Letter.ToUpper<M>}${camelize<R>}` : S;
80
+ /** Type-level conversion from camelCase text to dash-delimited text. */
81
+ export type hyphenate<S extends string> = S extends `${infer L}${infer R}` ? `${Letter.ToLower<L, '-'>}${hyphenate<R>}` : S;
82
+ /** Format a property key as a JavaScript member access suffix. */
83
+ export declare function formatProperty(key: keyof any): string;
84
+ /** Remove one trailing slash from a path string. */
85
+ export declare function trimSlash(source: string): string;
86
+ /** Ensure a path starts with `/` and has no trailing slash. */
87
+ export declare function sanitize(source: string): string;
88
+ export {};
89
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/string.ts"],"names":[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