@unieai/cosmokit 1.8.2

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 ADDED
@@ -0,0 +1,24 @@
1
+ # cosmokit
2
+
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
+ ```
package/lib/index.js ADDED
@@ -0,0 +1,325 @@
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/types.js
82
+ /** Test values using `instanceof` with a `toStringTag` fallback. */
83
+ function is(type, value) {
84
+ if (arguments.length === 1) return (value) => is(type, value);
85
+ return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
86
+ }
87
+ function isArrayBufferLike(value) {
88
+ return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
89
+ }
90
+ function isArrayBufferSource(value) {
91
+ return isArrayBufferLike(value) || ArrayBuffer.isView(value);
92
+ }
93
+ /** Binary source detection and base64/hex conversion helpers. */
94
+ var Binary;
95
+ (function(Binary) {
96
+ Binary.is = isArrayBufferLike;
97
+ Binary.isSource = isArrayBufferSource;
98
+ function fromSource(source) {
99
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
100
+ else return source;
101
+ }
102
+ Binary.fromSource = fromSource;
103
+ function toBase64(source) {
104
+ source = fromSource(source);
105
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
106
+ let binary = "";
107
+ const bytes = new Uint8Array(source);
108
+ for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
109
+ return btoa(binary);
110
+ }
111
+ Binary.toBase64 = toBase64;
112
+ function fromBase64(source) {
113
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
114
+ return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
115
+ }
116
+ Binary.fromBase64 = fromBase64;
117
+ function toHex(source) {
118
+ source = fromSource(source);
119
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
120
+ return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
121
+ }
122
+ Binary.toHex = toHex;
123
+ function fromHex(source) {
124
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
125
+ const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
126
+ const buffer = [];
127
+ for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
128
+ return Uint8Array.from(buffer).buffer;
129
+ }
130
+ Binary.fromHex = fromHex;
131
+ })(Binary || (Binary = {}));
132
+ /** Decode a base64 string into binary data. */
133
+ const base64ToArrayBuffer = Binary.fromBase64;
134
+ /** Encode binary data as base64. */
135
+ const arrayBufferToBase64 = Binary.toBase64;
136
+ /** Decode a hex string into binary data. */
137
+ const hexToArrayBuffer = Binary.fromHex;
138
+ /** Encode binary data as hex. */
139
+ const arrayBufferToHex = Binary.toHex;
140
+ /** Deep-clone common JavaScript values while preserving prototypes and cycles. */
141
+ function clone(source, refs = /* @__PURE__ */ new Map()) {
142
+ if (!source || typeof source !== "object") return source;
143
+ if (is("Date", source)) return new Date(source.valueOf());
144
+ if (is("RegExp", source)) return new RegExp(source.source, source.flags);
145
+ if (isArrayBufferLike(source)) return source.slice(0);
146
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
147
+ const cached = refs.get(source);
148
+ if (cached) return cached;
149
+ if (Array.isArray(source)) {
150
+ const result = [];
151
+ refs.set(source, result);
152
+ source.forEach((value, index) => {
153
+ result[index] = Reflect.apply(clone, null, [value, refs]);
154
+ });
155
+ return result;
156
+ }
157
+ const result = Object.create(Object.getPrototypeOf(source));
158
+ refs.set(source, result);
159
+ for (const key of Reflect.ownKeys(source)) {
160
+ const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
161
+ if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
162
+ Reflect.defineProperty(result, key, descriptor);
163
+ }
164
+ return result;
165
+ }
166
+ /** Deeply compare arrays, dates, regexps, buffers, and plain object fields. */
167
+ function deepEqual(a, b, strict) {
168
+ if (a === b) return true;
169
+ if (!strict && isNullable(a) && isNullable(b)) return true;
170
+ if (typeof a !== typeof b) return false;
171
+ if (typeof a !== "object") return false;
172
+ if (!a || !b) return false;
173
+ function check(test, then) {
174
+ return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
175
+ }
176
+ return check(Array.isArray, (a, b) => a.length === b.length && a.every((item, index) => deepEqual(item, b[index]))) ?? check(is("Date"), (a, b) => a.valueOf() === b.valueOf()) ?? check(is("RegExp"), (a, b) => a.source === b.source && a.flags === b.flags) ?? check(isArrayBufferLike, (a, b) => {
177
+ if (a.byteLength !== b.byteLength) return false;
178
+ const viewA = new Uint8Array(a);
179
+ const viewB = new Uint8Array(b);
180
+ for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
181
+ return true;
182
+ }) ?? Object.keys({
183
+ ...a,
184
+ ...b
185
+ }).every((key) => deepEqual(a[key], b[key], strict));
186
+ }
187
+ //#endregion
188
+ //#region lib/types/string.js
189
+ /** Uppercase the first character of a string. */
190
+ function capitalize(source) {
191
+ return source.charAt(0).toUpperCase() + source.slice(1);
192
+ }
193
+ /** Lowercase the first character of a string. */
194
+ function uncapitalize(source) {
195
+ return source.charAt(0).toLowerCase() + source.slice(1);
196
+ }
197
+ /** Convert dash or underscore delimited text to camelCase. */
198
+ function camelCase(source) {
199
+ return source.replace(/[_-][a-z]/g, (str) => str.slice(1).toUpperCase());
200
+ }
201
+ function tokenize(source, delimiters, delimiter) {
202
+ const output = [];
203
+ let state = 0;
204
+ for (let i = 0; i < source.length; i++) {
205
+ const code = source.charCodeAt(i);
206
+ if (code >= 65 && code <= 90) {
207
+ if (state === 1) {
208
+ const next = source.charCodeAt(i + 1);
209
+ if (next >= 97 && next <= 122) output.push(delimiter);
210
+ output.push(code + 32);
211
+ } else {
212
+ if (state !== 0) output.push(delimiter);
213
+ output.push(code + 32);
214
+ }
215
+ state = 1;
216
+ } else if (code >= 97 && code <= 122) {
217
+ output.push(code);
218
+ state = 2;
219
+ } else if (delimiters.includes(code)) {
220
+ if (state !== 0) output.push(delimiter);
221
+ state = 0;
222
+ } else output.push(code);
223
+ }
224
+ return String.fromCharCode(...output);
225
+ }
226
+ /** Convert text to dash-delimited parameter case. */
227
+ function paramCase(source) {
228
+ return tokenize(source, [45, 95], 45);
229
+ }
230
+ /** Convert text to underscore-delimited snake case. */
231
+ function snakeCase(source) {
232
+ return tokenize(source, [45, 95], 95);
233
+ }
234
+ /** Runtime alias for `camelCase`. */
235
+ const camelize = camelCase;
236
+ /** Runtime alias for `paramCase`. */
237
+ const hyphenate = paramCase;
238
+ /** Format a property key as a JavaScript member access suffix. */
239
+ function formatProperty(key) {
240
+ if (typeof key !== "string") return `[${key.toString()}]`;
241
+ return /^[a-z_$][\w$]*$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
242
+ }
243
+ /** Remove one trailing slash from a path string. */
244
+ function trimSlash(source) {
245
+ return source.replace(/\/$/, "");
246
+ }
247
+ /** Ensure a path starts with `/` and has no trailing slash. */
248
+ function sanitize(source) {
249
+ if (!source.startsWith("/")) source = "/" + source;
250
+ return trimSlash(source);
251
+ }
252
+ //#endregion
253
+ //#region lib/types/time.js
254
+ /** Time constants plus parsing and formatting helpers. */
255
+ var Time;
256
+ (function(Time) {
257
+ Time.millisecond = 1;
258
+ Time.second = 1e3;
259
+ Time.minute = Time.second * 60;
260
+ Time.hour = Time.minute * 60;
261
+ Time.day = Time.hour * 24;
262
+ Time.week = Time.day * 7;
263
+ let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
264
+ function setTimezoneOffset(offset) {
265
+ timezoneOffset = offset;
266
+ }
267
+ Time.setTimezoneOffset = setTimezoneOffset;
268
+ function getTimezoneOffset() {
269
+ return timezoneOffset;
270
+ }
271
+ Time.getTimezoneOffset = getTimezoneOffset;
272
+ function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
273
+ if (typeof date === "number") date = new Date(date);
274
+ if (offset === void 0) offset = timezoneOffset;
275
+ return Math.floor((date.valueOf() / Time.minute - offset) / 1440);
276
+ }
277
+ Time.getDateNumber = getDateNumber;
278
+ function fromDateNumber(value, offset) {
279
+ const date = new Date(value * Time.day);
280
+ if (offset === void 0) offset = timezoneOffset;
281
+ return new Date(+date + offset * Time.minute);
282
+ }
283
+ Time.fromDateNumber = fromDateNumber;
284
+ const numeric = /\d+(?:\.\d+)?/.source;
285
+ const timeRegExp = new RegExp(`^${[
286
+ "w(?:eek(?:s)?)?",
287
+ "d(?:ay(?:s)?)?",
288
+ "h(?:our(?:s)?)?",
289
+ "m(?:in(?:ute)?(?:s)?)?",
290
+ "s(?:ec(?:ond)?(?:s)?)?"
291
+ ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
292
+ function parseTime(source) {
293
+ const capture = timeRegExp.exec(source);
294
+ if (!capture) return 0;
295
+ 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);
296
+ }
297
+ Time.parseTime = parseTime;
298
+ function parseDate(date) {
299
+ const parsed = parseTime(date);
300
+ if (parsed) date = Date.now() + parsed;
301
+ else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
302
+ else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
303
+ return date ? new Date(date) : /* @__PURE__ */ new Date();
304
+ }
305
+ Time.parseDate = parseDate;
306
+ function format(ms) {
307
+ const abs = Math.abs(ms);
308
+ if (abs >= Time.day - Time.hour / 2) return Math.round(ms / Time.day) + "d";
309
+ else if (abs >= Time.hour - Time.minute / 2) return Math.round(ms / Time.hour) + "h";
310
+ else if (abs >= Time.minute - Time.second / 2) return Math.round(ms / Time.minute) + "m";
311
+ else if (abs >= Time.second) return Math.round(ms / Time.second) + "s";
312
+ return ms + "ms";
313
+ }
314
+ Time.format = format;
315
+ function toDigits(source, length = 2) {
316
+ return source.toString().padStart(length, "0");
317
+ }
318
+ Time.toDigits = toDigits;
319
+ function template(template, time = /* @__PURE__ */ new Date()) {
320
+ 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));
321
+ }
322
+ Time.template = template;
323
+ })(Time || (Time = {}));
324
+ //#endregion
325
+ export { Binary, Time, arrayBufferToBase64, arrayBufferToHex, base64ToArrayBuffer, camelCase, camelize, capitalize, clone, contain, deduplicate, deepEqual, defineProperty, difference, filterKeys, formatProperty, hexToArrayBuffer, hyphenate, intersection, is, isNonNullable, isNullable, isPlainObject, makeArray, mapValues, mapValues as valueMap, noop, omit, paramCase, pick, remove, sanitize, snakeCase, trimSlash, uncapitalize, union };
@@ -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,11 @@
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
+ //# 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"}
@@ -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,MAAM,MAAM,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI;KAAG,GAAG,IAAI,CAAC,GAAG,CAAC;CAAE,CAAA;AACjF,0EAA0E;AAC1E,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,MAAM,CA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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":[],"mappings":"AAAA,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,UAExC;AAED,iDAAiD;AACjD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,UAE1C;AAED,8DAA8D;AAC9D,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,UAEvC;AA0CD,qDAAqD;AACrD,wBAAgB,SAAS,CA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AAC,CAAC,EAAE,GAAG,CAAC,CAAA;AACnI,wEAAwE;AACxE,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAG3H,kEAAkE;AAClE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,UAG5C;AAED,oDAAoD;AACpD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,UAEvC;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,UAGtC"}
@@ -0,0 +1,19 @@
1
+ /** Time constants plus parsing and formatting helpers. */
2
+ export declare namespace Time {
3
+ const millisecond = 1;
4
+ const second = 1000;
5
+ const minute: number;
6
+ const hour: number;
7
+ const day: number;
8
+ const week: number;
9
+ function setTimezoneOffset(offset: number): void;
10
+ function getTimezoneOffset(): number;
11
+ function getDateNumber(date?: number | Date, offset?: number): number;
12
+ function fromDateNumber(value: number, offset?: number): Date;
13
+ function parseTime(source: string): number;
14
+ function parseDate(date: string): Date;
15
+ function format(ms: number): string;
16
+ function toDigits(source: number, length?: number): string;
17
+ function template(template: string, time?: Date): string;
18
+ }
19
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/time.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,yBAAiB,IAAI,CAAC;IACb,MAAM,WAAW,IAAI,CAAA;IACrB,MAAM,MAAM,OAAO,CAAA;IACnB,MAAM,MAAM,QAAc,CAAA;IAC1B,MAAM,IAAI,QAAc,CAAA;IACxB,MAAM,GAAG,QAAY,CAAA;IACrB,MAAM,IAAI,QAAU,CAAA;IAI3B,SAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,QAE/C;IAED,SAAgB,iBAAiB,WAEhC;IAED,SAAgB,aAAa,CAAC,IAAI,GAAE,MAAM,GAAG,IAAiB,EAAE,MAAM,CAAC,EAAE,MAAM,UAI9E;IAED,SAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,QAI5D;IAWD,SAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,UAQvC;IAED,SAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,QAUrC;IAED,SAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,UAYhC;IAED,SAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,SAAI,UAElD;IAED,SAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,OAAa,UAU3D;CACF"}
@@ -0,0 +1,34 @@
1
+ type GlobalConstructorNames = keyof {
2
+ [K in keyof typeof globalThis as typeof globalThis[K] extends abstract new (...args: any) => any ? K : never]: K;
3
+ };
4
+ /** Create a predicate for a global constructor name. */
5
+ export declare function is<K extends GlobalConstructorNames>(type: K): (value: any) => value is InstanceType<typeof globalThis[K]>;
6
+ /** Test whether a value matches a global constructor name. */
7
+ export declare function is<K extends GlobalConstructorNames>(type: K, value: any): value is InstanceType<typeof globalThis[K]>;
8
+ declare function isArrayBufferLike(value: any): value is ArrayBufferLike;
9
+ declare function isArrayBufferSource(value: any): value is Binary.Source;
10
+ /** Binary source detection and base64/hex conversion helpers. */
11
+ export declare namespace Binary {
12
+ type Source<T extends ArrayBufferLike = ArrayBufferLike> = T | ArrayBufferView<T>;
13
+ const is: typeof isArrayBufferLike;
14
+ const isSource: typeof isArrayBufferSource;
15
+ function fromSource<T extends ArrayBufferLike>(source: Source<T>): T;
16
+ function toBase64(source: Source): string;
17
+ function fromBase64(source: string): ArrayBuffer | Uint8Array<ArrayBuffer>;
18
+ function toHex(source: Source): string;
19
+ function fromHex(source: string): ArrayBuffer;
20
+ }
21
+ /** Decode a base64 string into binary data. */
22
+ export declare const base64ToArrayBuffer: typeof Binary.fromBase64;
23
+ /** Encode binary data as base64. */
24
+ export declare const arrayBufferToBase64: typeof Binary.toBase64;
25
+ /** Decode a hex string into binary data. */
26
+ export declare const hexToArrayBuffer: typeof Binary.fromHex;
27
+ /** Encode binary data as hex. */
28
+ export declare const arrayBufferToHex: typeof Binary.toHex;
29
+ /** Deep-clone common JavaScript values while preserving prototypes. */
30
+ export declare function clone<T>(source: T): T;
31
+ /** Deeply compare arrays, dates, regexps, buffers, and plain object fields. */
32
+ export declare function deepEqual(a: any, b: any, strict?: boolean): boolean;
33
+ export {};
34
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA,KAAK,sBAAsB,GAAG,MAAM;KACjC,CAAC,IAAI,MAAM,OAAO,UAAU,IAAI,OAAO,UAAU,CAAC,CAAC,CAAC,SAAS,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC;CACjH,CAAA;AAED,wDAAwD;AACxD,wBAAgB,EAAE,CAAC,CAAC,SAAS,sBAAsB,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,KAAK,IAAI,YAAY,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AAC1H,8DAA8D;AAC9D,wBAAgB,EAAE,CAAC,CAAC,SAAS,sBAAsB,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,YAAY,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AAQtH,iBAAS,iBAAiB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,eAAe,CAE/D;AAED,iBAAS,mBAAmB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,CAE/D;AAED,iEAAiE;AACjE,yBAAiB,MAAM,CAAC;IACtB,KAAY,MAAM,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA;IAEjF,MAAM,EAAE,0BAAoB,CAAA;IAC5B,MAAM,QAAQ,4BAAsB,CAAA;IAE3C,SAAgB,UAAU,CAAC,CAAC,SAAS,eAAe,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAO1E;IAED,SAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,UAWtC;IAED,SAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,yCAGxC;IAED,SAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,UAInC;IAED,SAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,eAQrC;CACF;AAED,+CAA+C;AAC/C,eAAO,MAAM,mBAAmB,0BAAoB,CAAA;AACpD,oCAAoC;AACpC,eAAO,MAAM,mBAAmB,wBAAkB,CAAA;AAClD,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB,uBAAiB,CAAA;AAC9C,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,qBAAe,CAAA;AAE5C,uEAAuE;AACvE,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAA;AA8BtC,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAwBnE"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@unieai/cosmokit",
3
+ "description": "A collection of common utilities",
4
+ "version": "1.8.2",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/UnieAI/UnieAI-Agent-Desktop.git",
11
+ "directory": "vendor/cosmokit"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./src/*": "./src/*",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "lib/index.js",
26
+ "lib/types/**/*.d.ts",
27
+ "lib/types/**/*.d.ts.map",
28
+ "src"
29
+ ],
30
+ "author": "Shigma <shigma10826@gmail.com>",
31
+ "license": "MIT"
32
+ }
package/src/array.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { isNullable } from './misc.ts'
2
+
3
+ /** Return true when every item in `array2` is present in `array1`. */
4
+ export function contain(array1: readonly any[], array2: readonly any[]) {
5
+ return array2.every(item => array1.includes(item))
6
+ }
7
+
8
+ /** Return items that appear in both arrays. */
9
+ export function intersection<T>(array1: readonly T[], array2: readonly T[]) {
10
+ return array1.filter(item => array2.includes(item))
11
+ }
12
+
13
+ /** Return items from `array1` that do not appear in `array2`. */
14
+ export function difference<S>(array1: readonly S[], array2: readonly any[]) {
15
+ return array1.filter(item => !array2.includes(item))
16
+ }
17
+
18
+ /** Return the set-union of two arrays while preserving first occurrence order. */
19
+ export function union<T>(array1: readonly T[], array2: readonly T[]) {
20
+ return Array.from(new Set([...array1, ...array2]))
21
+ }
22
+
23
+ /** Remove duplicate values while preserving first occurrence order. */
24
+ export function deduplicate<T>(array: readonly T[]) {
25
+ return [...new Set(array)]
26
+ }
27
+
28
+ /** Remove one item from an array and report whether it was found. */
29
+ export function remove<T>(list: T[], item: T) {
30
+ const index = list?.indexOf(item)
31
+ if (index >= 0) {
32
+ list.splice(index, 1)
33
+ return true
34
+ } else {
35
+ return false
36
+ }
37
+ }
38
+
39
+ /** Normalize nullish, scalar, or array input to an array. */
40
+ export function makeArray<T>(source: null | undefined | T | T[]) {
41
+ return Array.isArray(source) ? source : isNullable(source) ? [] : [source]
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
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'
package/src/misc.ts ADDED
@@ -0,0 +1,78 @@
1
+ /** String/symbol keyed dictionary type. */
2
+ export type Dict<T = any, K extends string | symbol = string> = { [key in K]: T }
3
+ /** Safely read `T[K]`, returning `never` when `K` is not a key of `T`. */
4
+ export type Get<T extends {}, K> = K extends keyof T ? T[K] : never
5
+ /** Conditional extraction helper with a configurable return type. */
6
+ export type Extract<S, T, U = S> = S extends T ? U : never
7
+ /** Accept a value or an array, unless the value is already an array type. */
8
+ export type MaybeArray<T> = [T] extends [unknown[]] ? T : T | T[]
9
+ /** Wrap a value in `Promise`, preserving the resolved type of existing promises. */
10
+ export type Promisify<T> = Promise<T extends Promise<infer S> ? S : T>
11
+ /** Accept a value or promise unless the value type is already promise-like. */
12
+ export type Awaitable<T> = [T] extends [Promise<unknown>] ? T : T | Promise<T>
13
+ /** Convert a union type to an intersection type. */
14
+ export type Intersect<U> = (U extends any ? (arg: U) => void : never) extends ((arg: infer I) => void) ? I : never
15
+
16
+ /** No-op callback returning `undefined` at runtime and `any` at type level. */
17
+ export function noop(): any {}
18
+
19
+ /** Return true when a value is `null` or `undefined`. */
20
+ export function isNullable(value: any): value is null | undefined | void {
21
+ return value === null || value === undefined
22
+ }
23
+
24
+ /** Return true when a value is neither `null` nor `undefined`. */
25
+ export function isNonNullable<T>(value: T): value is NonNullable<T> {
26
+ return !isNullable(value)
27
+ }
28
+
29
+ /** Return true for non-array object values. */
30
+ export function isPlainObject(data: any) {
31
+ return data && typeof data === 'object' && !Array.isArray(data)
32
+ }
33
+
34
+ /** Filter object entries with a key type guard. */
35
+ export function filterKeys<T, K extends string, U extends K>(object: Dict<T, K>, filter: (key: K, value: T) => key is U): Dict<T, U>
36
+ /** Filter object entries with a boolean predicate. */
37
+ export function filterKeys<T, K extends string>(object: Dict<T, K>, filter: (key: K, value: T) => boolean): Dict<T, K>
38
+ /** Filter object entries and return a new object. */
39
+ export function filterKeys(object: {}, filter: (key: string, value: any) => boolean) {
40
+ return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)))
41
+ }
42
+
43
+ /** Map object values while preserving the original key set. */
44
+ export function mapValues<U, T, K extends string>(object: Dict<T, K>, transform: (value: T, key: K) => U) {
45
+ return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, (transform as any)(value, key)])) as Dict<U, K>
46
+ }
47
+
48
+ /** Alias for `mapValues`. */
49
+ export { mapValues as valueMap }
50
+
51
+ /** Pick selected keys from an object, optionally including `undefined` values. */
52
+ export function pick<T extends object, K extends keyof T>(source: T, keys?: Iterable<K>, forced?: boolean) {
53
+ if (!keys) return { ...source }
54
+ const result = {} as Pick<T, K>
55
+ for (const key of keys) {
56
+ if (forced || source[key] !== undefined) result[key] = source[key]
57
+ }
58
+ return result
59
+ }
60
+
61
+ /** Omit selected keys from a shallow object copy. */
62
+ export function omit<T, K extends keyof T>(source: T, keys?: Iterable<K>) {
63
+ if (!keys) return { ...source }
64
+ const result = { ...source } as Omit<T, K>
65
+ for (const key of keys) {
66
+ Reflect.deleteProperty(result, key)
67
+ }
68
+ return result
69
+ }
70
+
71
+ /** Define a non-enumerable writable property with a typed key. */
72
+ export function defineProperty<T, K extends keyof T>(object: T, key: K, value: T[K]): T
73
+ /** Define a non-enumerable writable property with an arbitrary key. */
74
+ export function defineProperty<T, K extends keyof any>(object: T, key: K, value: any): T
75
+ /** Define a non-enumerable writable property and return the object. */
76
+ export function defineProperty<T, K extends keyof any>(object: T, key: K, value: any) {
77
+ return Object.defineProperty(object, key, { writable: true, value, enumerable: false })
78
+ }
package/src/string.ts ADDED
@@ -0,0 +1,113 @@
1
+ /** Uppercase the first character of a string. */
2
+ export function capitalize(source: string) {
3
+ return source.charAt(0).toUpperCase() + source.slice(1)
4
+ }
5
+
6
+ /** Lowercase the first character of a string. */
7
+ export function uncapitalize(source: string) {
8
+ return source.charAt(0).toLowerCase() + source.slice(1)
9
+ }
10
+
11
+ /** Convert dash or underscore delimited text to camelCase. */
12
+ export function camelCase(source: string) {
13
+ return source.replace(/[_-][a-z]/g, str => str.slice(1).toUpperCase())
14
+ }
15
+
16
+ const enum State {
17
+ DELIM,
18
+ UPPER,
19
+ LOWER,
20
+ }
21
+
22
+ function tokenize(source: string, delimiters: number[], delimiter: number) {
23
+ const output: number[] = []
24
+ let state = State.DELIM
25
+ for (let i = 0; i < source.length; i++) {
26
+ const code = source.charCodeAt(i)
27
+ if (code >= 65 && code <= 90) {
28
+ if (state === State.UPPER) {
29
+ const next = source.charCodeAt(i + 1)
30
+ if (next >= 97 && next <= 122) {
31
+ output.push(delimiter)
32
+ }
33
+ output.push(code + 32)
34
+ } else {
35
+ if (state !== State.DELIM) {
36
+ output.push(delimiter)
37
+ }
38
+ output.push(code + 32)
39
+ }
40
+ state = State.UPPER
41
+ } else if (code >= 97 && code <= 122) {
42
+ output.push(code)
43
+ state = State.LOWER
44
+ } else if (delimiters.includes(code)) {
45
+ if (state !== State.DELIM) {
46
+ output.push(delimiter)
47
+ }
48
+ state = State.DELIM
49
+ } else {
50
+ output.push(code)
51
+ }
52
+ }
53
+ return String.fromCharCode(...output)
54
+ }
55
+
56
+ /** Convert text to dash-delimited parameter case. */
57
+ export function paramCase(source: string) {
58
+ return tokenize(source, [45, 95], 45)
59
+ }
60
+
61
+ /** Convert text to underscore-delimited snake case. */
62
+ export function snakeCase(source: string) {
63
+ return tokenize(source, [45, 95], 95)
64
+ }
65
+
66
+ /** Runtime alias for `camelCase`. */
67
+ export const camelize = camelCase
68
+ /** Runtime alias for `paramCase`. */
69
+ export const hyphenate = paramCase
70
+
71
+ namespace Letter {
72
+ /* eslint-disable @typescript-eslint/member-delimiter-style */
73
+ interface LowerToUpper {
74
+ a: 'A', b: 'B', c: 'C', d: 'D', e: 'E', f: 'F', g: 'G', h: 'H', i: 'I', j: 'J', k: 'K', l: 'L', m: 'M',
75
+ n: 'N', o: 'O', p: 'P', q: 'Q', r: 'R', s: 'S', t: 'T', u: 'U', v: 'V', w: 'W', x: 'X', y: 'Y', z: 'Z',
76
+ }
77
+
78
+ interface UpperToLower {
79
+ A: 'a', B: 'b', C: 'c', D: 'd', E: 'e', F: 'f', G: 'g', H: 'h', I: 'i', J: 'j', K: 'k', L: 'l', M: 'm',
80
+ N: 'n', O: 'o', P: 'p', Q: 'q', R: 'r', S: 's', T: 't', U: 'u', V: 'v', W: 'w', X: 'x', Y: 'y', Z: 'z',
81
+ }
82
+ /* eslint-enable @typescript-eslint/member-delimiter-style */
83
+
84
+ export type Upper = keyof UpperToLower
85
+ export type Lower = keyof LowerToUpper
86
+
87
+ export type ToUpper<S extends string> = S extends Lower ? LowerToUpper[S] : S
88
+ export type ToLower<S extends string, P extends string = ''> = S extends Upper ? `${P}${UpperToLower[S]}` : S
89
+ }
90
+
91
+ /* eslint-disable @typescript-eslint/naming-convention */
92
+ /** Type-level conversion from dash-delimited text to camelCase. */
93
+ export type camelize<S extends string> = S extends `${infer L}-${infer M}${infer R}` ? `${L}${Letter.ToUpper<M>}${camelize<R>}` : S
94
+ /** Type-level conversion from camelCase text to dash-delimited text. */
95
+ export type hyphenate<S extends string> = S extends `${infer L}${infer R}` ? `${Letter.ToLower<L, '-'>}${hyphenate<R>}` : S
96
+ /* eslint-enable @typescript-eslint/naming-convention */
97
+
98
+ /** Format a property key as a JavaScript member access suffix. */
99
+ export function formatProperty(key: keyof any) {
100
+ if (typeof key !== 'string') return `[${key.toString()}]`
101
+ return /^[a-z_$][\w$]*$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`
102
+ }
103
+
104
+ /** Remove one trailing slash from a path string. */
105
+ export function trimSlash(source: string) {
106
+ return source.replace(/\/$/, '')
107
+ }
108
+
109
+ /** Ensure a path starts with `/` and has no trailing slash. */
110
+ export function sanitize(source: string) {
111
+ if (!source.startsWith('/')) source = '/' + source
112
+ return trimSlash(source)
113
+ }
package/src/time.ts ADDED
@@ -0,0 +1,92 @@
1
+ /** Time constants plus parsing and formatting helpers. */
2
+ export namespace Time {
3
+ export const millisecond = 1
4
+ export const second = 1000
5
+ export const minute = second * 60
6
+ export const hour = minute * 60
7
+ export const day = hour * 24
8
+ export const week = day * 7
9
+
10
+ let timezoneOffset = new Date().getTimezoneOffset()
11
+
12
+ export function setTimezoneOffset(offset: number) {
13
+ timezoneOffset = offset
14
+ }
15
+
16
+ export function getTimezoneOffset() {
17
+ return timezoneOffset
18
+ }
19
+
20
+ export function getDateNumber(date: number | Date = new Date(), offset?: number) {
21
+ if (typeof date === 'number') date = new Date(date)
22
+ if (offset === undefined) offset = timezoneOffset
23
+ return Math.floor((date.valueOf() / minute - offset) / 1440)
24
+ }
25
+
26
+ export function fromDateNumber(value: number, offset?: number) {
27
+ const date = new Date(value * day)
28
+ if (offset === undefined) offset = timezoneOffset
29
+ return new Date(+date + offset * minute)
30
+ }
31
+
32
+ const numeric = /\d+(?:\.\d+)?/.source
33
+ const timeRegExp = new RegExp(`^${[
34
+ 'w(?:eek(?:s)?)?',
35
+ 'd(?:ay(?:s)?)?',
36
+ 'h(?:our(?:s)?)?',
37
+ 'm(?:in(?:ute)?(?:s)?)?',
38
+ 's(?:ec(?:ond)?(?:s)?)?',
39
+ ].map(unit => `(${numeric}${unit})?`).join('')}$`)
40
+
41
+ export function parseTime(source: string) {
42
+ const capture = timeRegExp.exec(source)
43
+ if (!capture) return 0
44
+ return (parseFloat(capture[1]) * week || 0)
45
+ + (parseFloat(capture[2]) * day || 0)
46
+ + (parseFloat(capture[3]) * hour || 0)
47
+ + (parseFloat(capture[4]) * minute || 0)
48
+ + (parseFloat(capture[5]) * second || 0)
49
+ }
50
+
51
+ export function parseDate(date: string) {
52
+ const parsed = parseTime(date)
53
+ if (parsed) {
54
+ date = Date.now() + parsed as any
55
+ } else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) {
56
+ date = `${new Date().toLocaleDateString()}-${date}`
57
+ } else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) {
58
+ date = `${new Date().getFullYear()}-${date}`
59
+ }
60
+ return date ? new Date(date) : new Date()
61
+ }
62
+
63
+ export function format(ms: number) {
64
+ const abs = Math.abs(ms)
65
+ if (abs >= day - hour / 2) {
66
+ return Math.round(ms / day) + 'd'
67
+ } else if (abs >= hour - minute / 2) {
68
+ return Math.round(ms / hour) + 'h'
69
+ } else if (abs >= minute - second / 2) {
70
+ return Math.round(ms / minute) + 'm'
71
+ } else if (abs >= second) {
72
+ return Math.round(ms / second) + 's'
73
+ }
74
+ return ms + 'ms'
75
+ }
76
+
77
+ export function toDigits(source: number, length = 2) {
78
+ return source.toString().padStart(length, '0')
79
+ }
80
+
81
+ export function template(template: string, time = new Date()) {
82
+ return template
83
+ .replace('yyyy', time.getFullYear().toString())
84
+ .replace('yy', time.getFullYear().toString().slice(2))
85
+ .replace('MM', toDigits(time.getMonth() + 1))
86
+ .replace('dd', toDigits(time.getDate()))
87
+ .replace('hh', toDigits(time.getHours()))
88
+ .replace('mm', toDigits(time.getMinutes()))
89
+ .replace('ss', toDigits(time.getSeconds()))
90
+ .replace('SSS', toDigits(time.getMilliseconds(), 3))
91
+ }
92
+ }
package/src/types.ts ADDED
@@ -0,0 +1,142 @@
1
+ import { isNullable } from './misc.ts'
2
+
3
+ type GlobalConstructorNames = keyof {
4
+ [K in keyof typeof globalThis as typeof globalThis[K] extends abstract new (...args: any) => any ? K : never]: K
5
+ }
6
+
7
+ /** Create a predicate for a global constructor name. */
8
+ export function is<K extends GlobalConstructorNames>(type: K): (value: any) => value is InstanceType<typeof globalThis[K]>
9
+ /** Test whether a value matches a global constructor name. */
10
+ export function is<K extends GlobalConstructorNames>(type: K, value: any): value is InstanceType<typeof globalThis[K]>
11
+ /** Test values using `instanceof` with a `toStringTag` fallback. */
12
+ export function is<K extends GlobalConstructorNames>(type: K, value?: any): any {
13
+ if (arguments.length === 1) return (value: any) => is(type, value)
14
+ return type in globalThis && value instanceof (globalThis[type] as any)
15
+ || Object.prototype.toString.call(value).slice(8, -1) === type
16
+ }
17
+
18
+ function isArrayBufferLike(value: any): value is ArrayBufferLike {
19
+ return is('ArrayBuffer', value) || is('SharedArrayBuffer', value)
20
+ }
21
+
22
+ function isArrayBufferSource(value: any): value is Binary.Source {
23
+ return isArrayBufferLike(value) || ArrayBuffer.isView(value)
24
+ }
25
+
26
+ /** Binary source detection and base64/hex conversion helpers. */
27
+ export namespace Binary {
28
+ export type Source<T extends ArrayBufferLike = ArrayBufferLike> = T | ArrayBufferView<T>
29
+
30
+ export const is = isArrayBufferLike
31
+ export const isSource = isArrayBufferSource
32
+
33
+ export function fromSource<T extends ArrayBufferLike>(source: Source<T>): T {
34
+ if (ArrayBuffer.isView(source)) {
35
+ // https://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer#answer-31394257
36
+ return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength) as T
37
+ } else {
38
+ return source
39
+ }
40
+ }
41
+
42
+ export function toBase64(source: Source) {
43
+ source = fromSource(source)
44
+ if (typeof Buffer !== 'undefined') {
45
+ return Buffer.from(source).toString('base64')
46
+ }
47
+ let binary = ''
48
+ const bytes = new Uint8Array(source)
49
+ for (let i = 0; i < bytes.byteLength; i++) {
50
+ binary += String.fromCharCode(bytes[i])
51
+ }
52
+ return btoa(binary)
53
+ }
54
+
55
+ export function fromBase64(source: string) {
56
+ if (typeof Buffer !== 'undefined') return fromSource(Buffer.from(source, 'base64'))
57
+ return Uint8Array.from(atob(source), c => c.charCodeAt(0))
58
+ }
59
+
60
+ export function toHex(source: Source) {
61
+ source = fromSource(source)
62
+ if (typeof Buffer !== 'undefined') return Buffer.from(source).toString('hex')
63
+ return Array.from(new Uint8Array(source), byte => byte.toString(16).padStart(2, '0')).join('')
64
+ }
65
+
66
+ export function fromHex(source: string) {
67
+ if (typeof Buffer !== 'undefined') return fromSource(Buffer.from(source, 'hex'))
68
+ const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1)
69
+ const buffer: number[] = []
70
+ for (let i = 0; i < hex.length; i += 2) {
71
+ buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16))
72
+ }
73
+ return Uint8Array.from(buffer).buffer
74
+ }
75
+ }
76
+
77
+ /** Decode a base64 string into binary data. */
78
+ export const base64ToArrayBuffer = Binary.fromBase64
79
+ /** Encode binary data as base64. */
80
+ export const arrayBufferToBase64 = Binary.toBase64
81
+ /** Decode a hex string into binary data. */
82
+ export const hexToArrayBuffer = Binary.fromHex
83
+ /** Encode binary data as hex. */
84
+ export const arrayBufferToHex = Binary.toHex
85
+
86
+ /** Deep-clone common JavaScript values while preserving prototypes. */
87
+ export function clone<T>(source: T): T
88
+ /** Deep-clone common JavaScript values while preserving prototypes and cycles. */
89
+ export function clone(source: any, refs = new Map<any, any>()) {
90
+ if (!source || typeof source !== 'object') return source
91
+ if (is('Date', source)) return new Date(source.valueOf())
92
+ if (is('RegExp', source)) return new RegExp(source.source, source.flags)
93
+ if (isArrayBufferLike(source)) return source.slice(0)
94
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength)
95
+ const cached = refs.get(source)
96
+ if (cached) return cached
97
+ if (Array.isArray(source)) {
98
+ const result: any[] = []
99
+ refs.set(source, result)
100
+ source.forEach((value, index) => {
101
+ result[index] = Reflect.apply(clone, null, [value, refs])
102
+ })
103
+ return result
104
+ }
105
+ const result = Object.create(Object.getPrototypeOf(source))
106
+ refs.set(source, result)
107
+ for (const key of Reflect.ownKeys(source)) {
108
+ const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) }
109
+ if ('value' in descriptor) {
110
+ descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs])
111
+ }
112
+ Reflect.defineProperty(result, key, descriptor)
113
+ }
114
+ return result
115
+ }
116
+
117
+ /** Deeply compare arrays, dates, regexps, buffers, and plain object fields. */
118
+ export function deepEqual(a: any, b: any, strict?: boolean): boolean {
119
+ if (a === b) return true
120
+ if (!strict && isNullable(a) && isNullable(b)) return true
121
+ if (typeof a !== typeof b) return false
122
+ if (typeof a !== 'object') return false
123
+ if (!a || !b) return false
124
+
125
+ function check<T>(test: (x: any) => x is T, then: (a: T, b: T) => boolean) {
126
+ return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : undefined
127
+ }
128
+
129
+ return check(Array.isArray, (a, b) => a.length === b.length && a.every((item, index) => deepEqual(item, b[index])))
130
+ ?? check(is('Date'), (a, b) => a.valueOf() === b.valueOf())
131
+ ?? check(is('RegExp'), (a, b) => a.source === b.source && a.flags === b.flags)
132
+ ?? check(isArrayBufferLike, (a, b) => {
133
+ if (a.byteLength !== b.byteLength) return false
134
+ const viewA = new Uint8Array(a)
135
+ const viewB = new Uint8Array(b)
136
+ for (let i = 0; i < viewA.length; i++) {
137
+ if (viewA[i] !== viewB[i]) return false
138
+ }
139
+ return true
140
+ })
141
+ ?? Object.keys({ ...a, ...b }).every(key => deepEqual(a[key], b[key], strict))
142
+ }