@banbolee/dsh-fish-shell 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -0
- package/README.md +310 -13
- package/README.zh.md +99 -4
- package/THIRD-PARTY-NOTICES.md +91 -0
- package/cordis.patch.yml +56 -0
- package/node_modules/@deepseek-ai/cosmokit/LICENSE +21 -0
- package/node_modules/@deepseek-ai/cosmokit/README.md +30 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/index.js +418 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/array.d.ts +15 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/array.d.ts.map +1 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/index.d.ts +13 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/index.d.ts.map +1 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/misc.d.ts +41 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/misc.d.ts.map +1 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/string.d.ts +89 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/string.d.ts.map +1 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/time.d.ts +19 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/time.d.ts.map +1 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/types.d.ts +42 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/types.d.ts.map +1 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/volatile.d.ts +40 -0
- package/node_modules/@deepseek-ai/cosmokit/lib/types/volatile.d.ts.map +1 -0
- package/node_modules/@deepseek-ai/cosmokit/package.json +32 -0
- package/node_modules/@deepseek-ai/cosmokit/src/array.ts +42 -0
- package/node_modules/@deepseek-ai/cosmokit/src/index.ts +12 -0
- package/node_modules/@deepseek-ai/cosmokit/src/misc.ts +78 -0
- package/node_modules/@deepseek-ai/cosmokit/src/string.ts +113 -0
- package/node_modules/@deepseek-ai/cosmokit/src/time.ts +92 -0
- package/node_modules/@deepseek-ai/cosmokit/src/types.ts +168 -0
- package/node_modules/@deepseek-ai/cosmokit/src/volatile.ts +86 -0
- package/node_modules/@deepseek-ai/dsh-tool-terminal/LICENSE +21 -0
- package/node_modules/@deepseek-ai/dsh-tool-terminal/README.i18n.yaml +100 -0
- package/node_modules/@deepseek-ai/dsh-tool-terminal/README.md +186 -0
- package/node_modules/@deepseek-ai/dsh-tool-terminal/README.zh.md +186 -0
- package/node_modules/@deepseek-ai/dsh-tool-terminal/lib/index.js +646 -0
- package/node_modules/@deepseek-ai/dsh-tool-terminal/lib/types/background.d.ts +20 -0
- package/node_modules/@deepseek-ai/dsh-tool-terminal/lib/types/index.d.ts +32 -0
- package/node_modules/@deepseek-ai/dsh-tool-terminal/lib/types/render.d.ts +81 -0
- package/node_modules/@deepseek-ai/dsh-tool-terminal/package.json +63 -0
- package/node_modules/@deepseek-ai/schemastery/LICENSE +21 -0
- package/node_modules/@deepseek-ai/schemastery/README.md +393 -0
- package/node_modules/@deepseek-ai/schemastery/lib/index.cjs +635 -0
- package/node_modules/@deepseek-ai/schemastery/lib/index.mjs +635 -0
- package/node_modules/@deepseek-ai/schemastery/lib/types/index.d.ts +211 -0
- package/node_modules/@deepseek-ai/schemastery/lib/types/index.d.ts.map +1 -0
- package/node_modules/@deepseek-ai/schemastery/package.json +39 -0
- package/node_modules/@deepseek-ai/schemastery/src/index.ts +962 -0
- package/node_modules/@standard-schema/spec/LICENSE +21 -0
- package/node_modules/@standard-schema/spec/README.md +198 -0
- package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
- package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.js +0 -0
- package/node_modules/@standard-schema/spec/package.json +52 -0
- package/package.json +17 -3
- package/terminal-tools.js +259 -0
- package/terminal.js +297 -0
|
@@ -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,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;AACnE,qEAAqE;AACrE,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAC1D,6EAA6E;AAC7E,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E;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,CAAC,MAAM,EAAE,MAAM,UAEvC;AAED,uDAAuD;AACvD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,UAEvC;AAED,qCAAqC;AACrC,eAAO,MAAM,QAAQ,kBAAY,CAAA;AACjC,qCAAqC;AACrC,eAAO,MAAM,SAAS,kBAAY,CAAA;AAElC,kBAAU,MAAM,CAAC;IAEf,UAAU,YAAY;QACpB,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QACvG,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;QAAC,CAAC,EAAE,GAAG,CAAC;Q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CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IAC7E,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,GAAG,EAAE,IAAI,CAAC,SAAS,KAAK,GAAG,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;;CAC9G;AAGD,mEAAmE;AACnE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,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,42 @@
|
|
|
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
|
+
/**
|
|
32
|
+
* Compare values recursively, treating two volatile references as equal regardless of value.
|
|
33
|
+
* Strict comparison distinguishes null/undefined, treats opaque objects by identity,
|
|
34
|
+
* compares URLs by normalized href, treats array holes as undefined, and considers distinct cyclic structures unequal.
|
|
35
|
+
* @param a - first value.
|
|
36
|
+
* @param b - second value.
|
|
37
|
+
* @param strict - whether to require strict data equality outside volatile references.
|
|
38
|
+
* @returns whether the values compare equal.
|
|
39
|
+
*/
|
|
40
|
+
export declare function deepEqual(a: any, b: any, strict?: boolean): boolean;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAGA,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;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAyCnE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Shared config references used by schema validators and plugin runtimes. */
|
|
2
|
+
/** Recursively readonly data returned by a volatile config reference. */
|
|
3
|
+
export type VolatileSnapshot<T> = T extends object ? {
|
|
4
|
+
readonly [K in keyof T]: VolatileSnapshot<T[K]>;
|
|
5
|
+
} : T;
|
|
6
|
+
/** A stable reference; keep the reference, or capture its value for one operation only. */
|
|
7
|
+
export interface Volatile<T> {
|
|
8
|
+
/** @returns the current immutable snapshot, including undefined for an absent value. */
|
|
9
|
+
get(): VolatileSnapshot<T>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create a detached reference containing an immutable copy of the supplied data.
|
|
13
|
+
* @param value - validated config data; class instances and functions are unsupported.
|
|
14
|
+
* @returns a reference whose value is updated only by its owning runtime.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createVolatile<T>(value: T): Volatile<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Identify references across ESM/CJS copies of the shared library.
|
|
19
|
+
* @param value - a parsed config value.
|
|
20
|
+
* @returns whether the value implements the shared reference protocol.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isVolatile(value: unknown): value is Volatile<unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Collect config references without descending into their snapshots or opaque objects.
|
|
25
|
+
* @internal
|
|
26
|
+
* @param value - parsed config; cyclic ordinary fields are visited once per path.
|
|
27
|
+
* @returns references and their object-key paths, including an empty path for a root reference.
|
|
28
|
+
*/
|
|
29
|
+
export declare function volatileEntries(value: unknown): {
|
|
30
|
+
path: string[];
|
|
31
|
+
ref: Volatile<unknown>;
|
|
32
|
+
}[];
|
|
33
|
+
/**
|
|
34
|
+
* Commit an already validated immutable snapshot from another reference.
|
|
35
|
+
* @internal
|
|
36
|
+
* @param target - the owning plugin's stable reference.
|
|
37
|
+
* @param source - a newly parsed candidate reference.
|
|
38
|
+
*/
|
|
39
|
+
export declare function updateVolatile(target: Volatile<unknown>, source: Volatile<unknown>): void;
|
|
40
|
+
//# sourceMappingURL=volatile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volatile.d.ts","sourceRoot":"","sources":["../../src/volatile.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAI9E,yEAAyE;AACzE,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,CAAC,CAAA;AAE5G,2FAA2F;AAC3F,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,wFAAwF;IACxF,GAAG,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAA;CAC3B;AAsBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAMvD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,OAAO,CAAC,CAErE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;CAAE,EAAE,CAc5F;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAEzF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deepseek-ai/cosmokit",
|
|
3
|
+
"description": "A collection of common utilities",
|
|
4
|
+
"version": "1.8.5",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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'
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|