@wener/utils 1.1.25 → 1.1.27
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/README.md +4 -0
- package/dist/cjs/createFetchWith-qhRObsE4.js +2 -0
- package/dist/cjs/createFetchWith-qhRObsE4.js.map +1 -0
- package/dist/cjs/{getGlobalThis-304f74e0.js → getGlobalThis-GhffAgiG.js} +1 -1
- package/dist/cjs/{getGlobalThis-304f74e0.js.map → getGlobalThis-GhffAgiG.js.map} +1 -1
- package/dist/cjs/index.cjs +12 -12
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/schema/typebox/gen/index.cjs +118 -0
- package/dist/cjs/schema/typebox/gen/index.cjs.map +1 -0
- package/dist/cjs/schema/typebox/index.cjs +2 -0
- package/dist/cjs/schema/typebox/index.cjs.map +1 -0
- package/dist/cjs/server.cjs +1 -1
- package/dist/cjs/server.cjs.map +1 -1
- package/dist/cjs/servers/jsdom.cjs +1 -1
- package/dist/cjs/servers/jsdom.cjs.map +1 -1
- package/dist/cjs/servers/node-fetch.cjs +1 -1
- package/dist/cjs/servers/ws.cjs +1 -1
- package/dist/esm/createFetchWith-1q1S-Xro.js +2 -0
- package/dist/esm/createFetchWith-1q1S-Xro.js.map +1 -0
- package/dist/esm/{getGlobalThis-b7ad0cf9.js → getGlobalThis-A8F-nU7J.js} +1 -1
- package/dist/esm/{getGlobalThis-b7ad0cf9.js.map → getGlobalThis-A8F-nU7J.js.map} +1 -1
- package/dist/esm/index.js +9 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schema/typebox/gen.js +118 -0
- package/dist/esm/schema/typebox/gen.js.map +1 -0
- package/dist/esm/schema/typebox.js +2 -0
- package/dist/esm/schema/typebox.js.map +1 -0
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/servers/jsdom.js +1 -1
- package/dist/esm/servers/jsdom.js.map +1 -1
- package/dist/esm/servers/node-fetch.js +1 -1
- package/dist/esm/servers/ws.js +1 -1
- package/dist/system/createFetchWith-TjUle-dI.js +2 -0
- package/dist/system/createFetchWith-TjUle-dI.js.map +1 -0
- package/dist/system/{getGlobalThis-8951eb0e.js → getGlobalThis-X5ifUXDI.js} +1 -1
- package/dist/system/{getGlobalThis-8951eb0e.js.map → getGlobalThis-X5ifUXDI.js.map} +1 -1
- package/dist/system/index.js +12 -12
- package/dist/system/index.js.map +1 -1
- package/dist/system/schema/typebox/gen.js +118 -0
- package/dist/system/schema/typebox/gen.js.map +1 -0
- package/dist/system/schema/typebox.js +2 -0
- package/dist/system/schema/typebox.js.map +1 -0
- package/dist/system/server.js +1 -1
- package/dist/system/server.js.map +1 -1
- package/dist/system/servers/jsdom.js +1 -1
- package/dist/system/servers/jsdom.js.map +1 -1
- package/dist/system/servers/node-fetch.js +1 -1
- package/dist/system/servers/ws.js +1 -1
- package/lib/crypto/hashing.js +1 -1
- package/lib/crypto/hashing.js.map +1 -1
- package/lib/fetch/createFetchWith.js.map +1 -1
- package/lib/{servers/fetch → fetch}/createFetchWithRetry.js +1 -1
- package/lib/fetch/createFetchWithRetry.js.map +1 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/langs/deepFreeze.js +16 -0
- package/lib/langs/deepFreeze.js.map +1 -0
- package/lib/maths/clamp.js +21 -0
- package/lib/maths/clamp.js.map +1 -0
- package/lib/objects/get.js.map +1 -1
- package/lib/objects/set.js.map +1 -1
- package/lib/schema/typebox/gen/codegen/common/encoder.js +74 -0
- package/lib/schema/typebox/gen/codegen/common/encoder.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/common/formatter.js +10 -0
- package/lib/schema/typebox/gen/codegen/common/formatter.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/common/jsdoc.js +68 -0
- package/lib/schema/typebox/gen/codegen/common/jsdoc.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/expression/compiler.js +325 -0
- package/lib/schema/typebox/gen/codegen/expression/compiler.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/expression/errors.js +237 -0
- package/lib/schema/typebox/gen/codegen/expression/errors.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/expression/evaluator.js +241 -0
- package/lib/schema/typebox/gen/codegen/expression/evaluator.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/expression/expression.js +200 -0
- package/lib/schema/typebox/gen/codegen/expression/expression.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/index.js +19 -0
- package/lib/schema/typebox/gen/codegen/index.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-arktype.js +263 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-arktype.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-expression.js +363 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-expression.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-grpc.js +245 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-grpc.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-io-ts.js +316 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-io-ts.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-javascript.js +20 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-javascript.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-json-schema.js +171 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-json-schema.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-typebox.js +10 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-typebox.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-typescript.js +198 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-typescript.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-valibot.js +252 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-valibot.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-value.js +19 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-value.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-yrel.js +247 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-yrel.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-yup.js +249 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-yup.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-zod.js +272 -0
- package/lib/schema/typebox/gen/codegen/model/model-to-zod.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js +45 -0
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js.map +1 -0
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-typebox.js +620 -0
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-typebox.js.map +1 -0
- package/lib/schema/typebox/gen/index.js +3 -0
- package/lib/schema/typebox/gen/index.js.map +1 -0
- package/lib/schema/typebox/index.js +3 -0
- package/lib/schema/typebox/index.js.map +1 -0
- package/lib/schema/typebox/typebox.js +34 -0
- package/lib/schema/typebox/typebox.js.map +1 -0
- package/lib/server.js +0 -1
- package/lib/server.js.map +1 -1
- package/lib/servers/fetch/createFetchWithProxyByUndici.js +15 -0
- package/lib/servers/fetch/createFetchWithProxyByUndici.js.map +1 -1
- package/package.json +21 -6
- package/src/crypto/hashing.ts +1 -1
- package/src/fetch/createFetchWith.ts +1 -1
- package/src/{servers/fetch → fetch}/createFetchWithRetry.ts +3 -3
- package/src/fetch/index.ts +1 -0
- package/src/index.ts +12 -4
- package/src/langs/deepFreeze.ts +19 -0
- package/src/langs/hashCode.ignored.ts +125 -0
- package/src/libs/README.md +2 -0
- package/src/logging/slog.ts +121 -0
- package/src/maths/clamp.test.ts +19 -0
- package/src/maths/clamp.ts +23 -1
- package/src/objects/get.ts +14 -14
- package/src/objects/set.ts +5 -5
- package/src/schema/typebox/gen/codegen/common/encoder.ts +99 -0
- package/src/schema/typebox/gen/codegen/common/formatter.ts +31 -0
- package/src/schema/typebox/gen/codegen/common/index.ts +29 -0
- package/src/schema/typebox/gen/codegen/common/jsdoc.ts +93 -0
- package/src/schema/typebox/gen/codegen/expression/compiler.ts +377 -0
- package/src/schema/typebox/gen/codegen/expression/errors.ts +302 -0
- package/src/schema/typebox/gen/codegen/expression/evaluator.ts +268 -0
- package/src/schema/typebox/gen/codegen/expression/expression.ts +538 -0
- package/src/schema/typebox/gen/codegen/expression/index.ts +32 -0
- package/src/schema/typebox/gen/codegen/index.ts +29 -0
- package/src/schema/typebox/gen/codegen/model/index.ts +40 -0
- package/src/schema/typebox/gen/codegen/model/model-to-arktype.ts +266 -0
- package/src/schema/typebox/gen/codegen/model/model-to-expression.ts +378 -0
- package/src/schema/typebox/gen/codegen/model/model-to-grpc.ts +244 -0
- package/src/schema/typebox/gen/codegen/model/model-to-io-ts.ts +294 -0
- package/src/schema/typebox/gen/codegen/model/model-to-javascript.ts +42 -0
- package/src/schema/typebox/gen/codegen/model/model-to-json-schema.ts +166 -0
- package/src/schema/typebox/gen/codegen/model/model-to-typebox.ts +32 -0
- package/src/schema/typebox/gen/codegen/model/model-to-typescript.ts +189 -0
- package/src/schema/typebox/gen/codegen/model/model-to-valibot.ts +236 -0
- package/src/schema/typebox/gen/codegen/model/model-to-value.ts +42 -0
- package/src/schema/typebox/gen/codegen/model/model-to-yrel.ts +232 -0
- package/src/schema/typebox/gen/codegen/model/model-to-yup.ts +226 -0
- package/src/schema/typebox/gen/codegen/model/model-to-zod.ts +251 -0
- package/src/schema/typebox/gen/codegen/model/model.ts +33 -0
- package/src/schema/typebox/gen/codegen/typescript/index.ts +28 -0
- package/src/schema/typebox/gen/codegen/typescript/typescript-to-model.ts +61 -0
- package/src/schema/typebox/gen/codegen/typescript/typescript-to-typebox.ts +647 -0
- package/src/schema/typebox/gen/gen.test.ts +12 -0
- package/src/schema/typebox/gen/index.ts +1 -0
- package/src/schema/typebox/index.ts +1 -0
- package/src/schema/typebox/typebox.ts +34 -0
- package/src/server.ts +0 -1
- package/src/servers/fetch/createFetchWithProxyByUndici.ts +16 -1
- package/src/typedoc.ts +2 -1
- package/src/types/index.d.ts +1 -0
- package/lib/servers/fetch/createFetchWithRetry.js.map +0 -1
- package/src/langs/hashCode.ts +0 -37
package/src/logging/slog.ts
CHANGED
|
@@ -98,3 +98,124 @@ createLogger.writer = (record: LogRecord) => {
|
|
|
98
98
|
const { level } = record;
|
|
99
99
|
console[level || 'info'](stringify(record));
|
|
100
100
|
};
|
|
101
|
+
|
|
102
|
+
// https://github.com/alexeyraspopov/picocolors/blob/main/picocolors.js
|
|
103
|
+
/*
|
|
104
|
+
MDN: Styling console output
|
|
105
|
+
https://developer.mozilla.org/en-US/docs/Web/API/console#Usage
|
|
106
|
+
|
|
107
|
+
Chrome: Console API Reference
|
|
108
|
+
https://developers.google.com/web/tools/chrome-devtools/console/console-write#styling_console_output_with_css
|
|
109
|
+
|
|
110
|
+
WebKit: Console Object API
|
|
111
|
+
https://webkit.org/web-inspector/console-object-api/
|
|
112
|
+
|
|
113
|
+
https://stackoverflow.com/questions/7505623
|
|
114
|
+
|
|
115
|
+
console.log('\x1b[36m Hello \x1b[34m Colored \x1b[35m World!');
|
|
116
|
+
console.log('\x1B[31mHello\x1B[34m World');
|
|
117
|
+
console.log('\x1b[43mHighlighted');
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
NestJS Formatter
|
|
121
|
+
https://github.com/nestjs/nest/blob/d4bda940fc10238eb18f14ebf66d66b7ef8bff41/packages/common/services/console-logger.service.ts#L201-L227
|
|
122
|
+
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
export type Formatter = (input: string | number | null | undefined) => string;
|
|
126
|
+
|
|
127
|
+
export interface Colors {
|
|
128
|
+
isColorSupported: boolean;
|
|
129
|
+
reset: Formatter;
|
|
130
|
+
bold: Formatter;
|
|
131
|
+
dim: Formatter;
|
|
132
|
+
italic: Formatter;
|
|
133
|
+
underline: Formatter;
|
|
134
|
+
inverse: Formatter;
|
|
135
|
+
hidden: Formatter;
|
|
136
|
+
strikethrough: Formatter;
|
|
137
|
+
black: Formatter;
|
|
138
|
+
red: Formatter;
|
|
139
|
+
green: Formatter;
|
|
140
|
+
yellow: Formatter;
|
|
141
|
+
blue: Formatter;
|
|
142
|
+
magenta: Formatter;
|
|
143
|
+
cyan: Formatter;
|
|
144
|
+
white: Formatter;
|
|
145
|
+
gray: Formatter;
|
|
146
|
+
bgBlack: Formatter;
|
|
147
|
+
bgRed: Formatter;
|
|
148
|
+
bgGreen: Formatter;
|
|
149
|
+
bgYellow: Formatter;
|
|
150
|
+
bgBlue: Formatter;
|
|
151
|
+
bgMagenta: Formatter;
|
|
152
|
+
bgCyan: Formatter;
|
|
153
|
+
bgWhite: Formatter;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let formatter =
|
|
157
|
+
(open: string, close: string, replace: string = open) =>
|
|
158
|
+
(input: string) => {
|
|
159
|
+
let string = '' + input;
|
|
160
|
+
let index = string.indexOf(close, open.length);
|
|
161
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
let replaceClose = (string: string, close: string, replace: string, index: number): string => {
|
|
165
|
+
let start = string.substring(0, index) + replace;
|
|
166
|
+
let end = string.substring(index + close.length);
|
|
167
|
+
let nextIndex = end.indexOf(close);
|
|
168
|
+
return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
function getEnv(): Record<string, string | undefined> {
|
|
172
|
+
if (typeof process === 'object') {
|
|
173
|
+
return process.env;
|
|
174
|
+
}
|
|
175
|
+
return {};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function isColorSupported() {
|
|
179
|
+
if (typeof window === 'object') {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
const env = getEnv();
|
|
183
|
+
if ('NO_COLOR' in env) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
if ('FORCE_COLOR' in env || 'CI' in env) {
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function createConsoleColors(enabled = isColorSupported()) {
|
|
193
|
+
return {
|
|
194
|
+
isColorSupported: enabled,
|
|
195
|
+
reset: enabled ? (s: string) => `\x1b[0m${s}\x1b[0m` : String,
|
|
196
|
+
bold: enabled ? formatter('\x1b[1m', '\x1b[22m', '\x1b[22m\x1b[1m') : String,
|
|
197
|
+
dim: enabled ? formatter('\x1b[2m', '\x1b[22m', '\x1b[22m\x1b[2m') : String,
|
|
198
|
+
italic: enabled ? formatter('\x1b[3m', '\x1b[23m') : String,
|
|
199
|
+
underline: enabled ? formatter('\x1b[4m', '\x1b[24m') : String,
|
|
200
|
+
inverse: enabled ? formatter('\x1b[7m', '\x1b[27m') : String,
|
|
201
|
+
hidden: enabled ? formatter('\x1b[8m', '\x1b[28m') : String,
|
|
202
|
+
strikethrough: enabled ? formatter('\x1b[9m', '\x1b[29m') : String,
|
|
203
|
+
black: enabled ? formatter('\x1b[30m', '\x1b[39m') : String,
|
|
204
|
+
red: enabled ? formatter('\x1b[31m', '\x1b[39m') : String,
|
|
205
|
+
green: enabled ? formatter('\x1b[32m', '\x1b[39m') : String,
|
|
206
|
+
yellow: enabled ? formatter('\x1b[33m', '\x1b[39m') : String,
|
|
207
|
+
blue: enabled ? formatter('\x1b[34m', '\x1b[39m') : String,
|
|
208
|
+
magenta: enabled ? formatter('\x1b[35m', '\x1b[39m') : String,
|
|
209
|
+
cyan: enabled ? formatter('\x1b[36m', '\x1b[39m') : String,
|
|
210
|
+
white: enabled ? formatter('\x1b[37m', '\x1b[39m') : String,
|
|
211
|
+
gray: enabled ? formatter('\x1b[90m', '\x1b[39m') : String,
|
|
212
|
+
bgBlack: enabled ? formatter('\x1b[40m', '\x1b[49m') : String,
|
|
213
|
+
bgRed: enabled ? formatter('\x1b[41m', '\x1b[49m') : String,
|
|
214
|
+
bgGreen: enabled ? formatter('\x1b[42m', '\x1b[49m') : String,
|
|
215
|
+
bgYellow: enabled ? formatter('\x1b[43m', '\x1b[49m') : String,
|
|
216
|
+
bgBlue: enabled ? formatter('\x1b[44m', '\x1b[49m') : String,
|
|
217
|
+
bgMagenta: enabled ? formatter('\x1b[45m', '\x1b[49m') : String,
|
|
218
|
+
bgCyan: enabled ? formatter('\x1b[46m', '\x1b[49m') : String,
|
|
219
|
+
bgWhite: enabled ? formatter('\x1b[47m', '\x1b[49m') : String,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { expect, test } from 'vitest';
|
|
2
|
+
import { clamp } from './clamp';
|
|
3
|
+
|
|
4
|
+
test('clamp', () => {
|
|
5
|
+
for (const [a, b] of [
|
|
6
|
+
[[null, 0, 0], 0],
|
|
7
|
+
[[null, 1, 10], 1],
|
|
8
|
+
[[undefined, 1, 10], 1],
|
|
9
|
+
[[undefined, 1, 10, 5], 5],
|
|
10
|
+
[[2, 1, 10, 5], 2],
|
|
11
|
+
[[11, 1, 10, 5], 10],
|
|
12
|
+
[[11, { min: 1, max: 10 }], 10],
|
|
13
|
+
[[null, { min: 1, max: 10 }], 1],
|
|
14
|
+
[[null, { min: 1, max: 10, default: 5 }], 5],
|
|
15
|
+
[[2n, 1, 10, 5], 2n],
|
|
16
|
+
]) {
|
|
17
|
+
expect(clamp.apply(null, a as any)).toBe(b);
|
|
18
|
+
}
|
|
19
|
+
});
|
package/src/maths/clamp.ts
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
export function clamp(
|
|
1
|
+
// export function clamp<T>(value: T | null | undefined, o: { min: T; max: T; default?: T }): T;
|
|
2
|
+
|
|
3
|
+
export function clamp<T>(value: T | null | undefined, min: T, max: T, def?: T): T;
|
|
4
|
+
export function clamp<T>(value: T | null | undefined, ...o: any[]): T {
|
|
5
|
+
let min: T, max: T, def: T;
|
|
6
|
+
if (o.length === 1) {
|
|
7
|
+
({ min, max, default: def = min! } = o[0]);
|
|
8
|
+
} else {
|
|
9
|
+
[min, max, def = min!] = o;
|
|
10
|
+
}
|
|
11
|
+
if (value === null || value === undefined) {
|
|
12
|
+
return def;
|
|
13
|
+
}
|
|
14
|
+
if (value < min) {
|
|
15
|
+
return min;
|
|
16
|
+
}
|
|
17
|
+
if (value > max) {
|
|
18
|
+
return max;
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// type Comparable = number | string | Date | BigInt;
|
package/src/objects/get.ts
CHANGED
|
@@ -32,19 +32,19 @@ export type ResolveObjectPathType<
|
|
|
32
32
|
> = Path extends keyof ObjectType
|
|
33
33
|
? ObjectType[Path]
|
|
34
34
|
: Path extends `${infer LeftSide}.${infer RightSide}`
|
|
35
|
-
? LeftSide extends keyof ObjectType
|
|
36
|
-
? ResolveObjectPathType<ObjectType[LeftSide], RightSide, OrElse>
|
|
37
|
-
: Path extends `${infer LeftSide}[${number}].${infer RightSide}`
|
|
38
35
|
? LeftSide extends keyof ObjectType
|
|
39
|
-
? ObjectType[LeftSide]
|
|
40
|
-
|
|
36
|
+
? ResolveObjectPathType<ObjectType[LeftSide], RightSide, OrElse>
|
|
37
|
+
: Path extends `${infer LeftSide}[${number}].${infer RightSide}`
|
|
38
|
+
? LeftSide extends keyof ObjectType
|
|
39
|
+
? ObjectType[LeftSide] extends Array<infer U>
|
|
40
|
+
? ResolveObjectPathType<U, RightSide, OrElse>
|
|
41
|
+
: OrElse
|
|
42
|
+
: OrElse
|
|
41
43
|
: OrElse
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
: OrElse
|
|
49
|
-
: OrElse
|
|
50
|
-
: OrElse;
|
|
44
|
+
: Path extends `${infer LeftSide}[${number}]`
|
|
45
|
+
? LeftSide extends keyof ObjectType
|
|
46
|
+
? ObjectType[LeftSide] extends Array<infer U>
|
|
47
|
+
? U
|
|
48
|
+
: OrElse
|
|
49
|
+
: OrElse
|
|
50
|
+
: OrElse;
|
package/src/objects/set.ts
CHANGED
|
@@ -22,11 +22,11 @@ export function set<T extends object, V>(obj: T, key: ObjectKey | ObjectPath, va
|
|
|
22
22
|
? merge(current[k], val)
|
|
23
23
|
: val
|
|
24
24
|
: typeof (x = current[k]) === typeof path
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
? x
|
|
26
|
+
: // @ts-expect-error hacky type check
|
|
27
|
+
path[i] * 0 !== 0 || !!~('' + path[i]).indexOf('.') // eslint-disable-line
|
|
28
|
+
? {}
|
|
29
|
+
: [];
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*--------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
@sinclair/typebox-codegen
|
|
4
|
+
|
|
5
|
+
The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
---------------------------------------------------------------------------*/
|
|
26
|
+
|
|
27
|
+
// --------------------------------------------------------------------------
|
|
28
|
+
// Character
|
|
29
|
+
// --------------------------------------------------------------------------
|
|
30
|
+
namespace Character {
|
|
31
|
+
export function DollarSign(code: number) {
|
|
32
|
+
return code === 36;
|
|
33
|
+
}
|
|
34
|
+
export function IsUnderscore(code: number) {
|
|
35
|
+
return code === 95;
|
|
36
|
+
}
|
|
37
|
+
export function IsAlpha(code: number) {
|
|
38
|
+
return (code >= 64 && code <= 90) || (code >= 97 && code <= 122);
|
|
39
|
+
}
|
|
40
|
+
export function IsNumeric(code: number) {
|
|
41
|
+
return code >= 48 && code <= 57;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// --------------------------------------------------------------------------
|
|
45
|
+
// MemberExpressionEncoder
|
|
46
|
+
// --------------------------------------------------------------------------
|
|
47
|
+
export namespace MemberExpressionEncoder {
|
|
48
|
+
function IsFirstCharacterNumeric(value: string) {
|
|
49
|
+
if (value.length === 0) return false;
|
|
50
|
+
return Character.IsNumeric(value.charCodeAt(0));
|
|
51
|
+
}
|
|
52
|
+
function IsAccessor(value: string) {
|
|
53
|
+
if (IsFirstCharacterNumeric(value)) return false;
|
|
54
|
+
for (let i = 0; i < value.length; i++) {
|
|
55
|
+
const code = value.charCodeAt(i);
|
|
56
|
+
const check =
|
|
57
|
+
Character.IsAlpha(code) ||
|
|
58
|
+
Character.IsNumeric(code) ||
|
|
59
|
+
Character.DollarSign(code) ||
|
|
60
|
+
Character.IsUnderscore(code);
|
|
61
|
+
if (!check) return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
function EscapeHyphen(key: string) {
|
|
66
|
+
return key.replace(/'/g, "\\'");
|
|
67
|
+
}
|
|
68
|
+
export function Encode(object: string, key: string) {
|
|
69
|
+
return IsAccessor(key) ? `${object}.${key}` : `${object}['${EscapeHyphen(key)}']`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// --------------------------------------------------------------------------
|
|
73
|
+
// PropertyEncoder
|
|
74
|
+
// --------------------------------------------------------------------------
|
|
75
|
+
export namespace PropertyEncoder {
|
|
76
|
+
function IsFirstCharacterNumeric(value: string) {
|
|
77
|
+
if (value.length === 0) return false;
|
|
78
|
+
return Character.IsNumeric(value.charCodeAt(0));
|
|
79
|
+
}
|
|
80
|
+
function IsSafeProperty(value: string) {
|
|
81
|
+
if (IsFirstCharacterNumeric(value)) return false;
|
|
82
|
+
for (let i = 0; i < value.length; i++) {
|
|
83
|
+
const code = value.charCodeAt(i);
|
|
84
|
+
const check =
|
|
85
|
+
Character.IsAlpha(code) ||
|
|
86
|
+
Character.IsNumeric(code) ||
|
|
87
|
+
Character.DollarSign(code) ||
|
|
88
|
+
Character.IsUnderscore(code);
|
|
89
|
+
if (!check) return false;
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
function Quoted(value: string) {
|
|
94
|
+
return `'${value}'`;
|
|
95
|
+
}
|
|
96
|
+
export function Encode(value: string) {
|
|
97
|
+
return IsSafeProperty(value) ? value : Quoted(value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*--------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
@sinclair/typebox-codegen
|
|
4
|
+
|
|
5
|
+
The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
---------------------------------------------------------------------------*/
|
|
26
|
+
|
|
27
|
+
export namespace Formatter {
|
|
28
|
+
export function Format(code: string): string {
|
|
29
|
+
return code;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*--------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
@sinclair/typebox-codegen
|
|
4
|
+
|
|
5
|
+
The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
---------------------------------------------------------------------------*/
|
|
26
|
+
|
|
27
|
+
export * from './encoder';
|
|
28
|
+
export * from './formatter';
|
|
29
|
+
export * from './jsdoc';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*--------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
@sinclair/typebox-codegen
|
|
4
|
+
|
|
5
|
+
The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
---------------------------------------------------------------------------*/
|
|
26
|
+
|
|
27
|
+
/** JSDoc Property Parser */
|
|
28
|
+
export namespace JsDoc {
|
|
29
|
+
// ----------------------------------------------------------------
|
|
30
|
+
// Quotes
|
|
31
|
+
// ----------------------------------------------------------------
|
|
32
|
+
function ConsumeQuote(content: string): [consumed: string, rest: string] {
|
|
33
|
+
if (!IsQuote(content)) return ['', content];
|
|
34
|
+
const quote = content[0];
|
|
35
|
+
for (let i = 1; i < content.length; i++) {
|
|
36
|
+
if (content[i] === quote) return [content.slice(1, i), content.slice(i)];
|
|
37
|
+
if (content[i] === '\n') return [content.slice(1, i), content.slice(i)];
|
|
38
|
+
}
|
|
39
|
+
return [content.slice(1), ''];
|
|
40
|
+
}
|
|
41
|
+
function IsQuote(content: string) {
|
|
42
|
+
return content[0] === '"' || content[0] === "'";
|
|
43
|
+
}
|
|
44
|
+
// ----------------------------------------------------------------
|
|
45
|
+
// Decode
|
|
46
|
+
// ----------------------------------------------------------------
|
|
47
|
+
function DecodeWithNonQuotedProperties(content: string): any {
|
|
48
|
+
const parseFunction = new Function(`return (${content});`);
|
|
49
|
+
return parseFunction();
|
|
50
|
+
}
|
|
51
|
+
function Decode(content: string) {
|
|
52
|
+
try {
|
|
53
|
+
return DecodeWithNonQuotedProperties(content);
|
|
54
|
+
} catch {
|
|
55
|
+
return content;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function* ParseValue(key: string, content: string): IterableIterator<[string, any]> {
|
|
59
|
+
if (IsQuote(content)) {
|
|
60
|
+
const [consumed, rest] = ConsumeQuote(content);
|
|
61
|
+
yield [key, Decode(consumed)];
|
|
62
|
+
return yield* ParseContent(rest);
|
|
63
|
+
}
|
|
64
|
+
for (let i = 0; i < content.length; i++) {
|
|
65
|
+
if (content[i] === '\n' || content[i] === '-') {
|
|
66
|
+
const value = content.slice(0, i).trim();
|
|
67
|
+
const rest = content.slice(i);
|
|
68
|
+
yield [key, Decode(value)];
|
|
69
|
+
return yield* ParseContent(rest);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function* ParseKey(content: string): IterableIterator<[string, any]> {
|
|
74
|
+
for (let i = 1; i < content.length; i++) {
|
|
75
|
+
if (content[i] === ' ') {
|
|
76
|
+
const key = content.slice(1, i);
|
|
77
|
+
const rest = content.slice(i).trimStart();
|
|
78
|
+
return yield* ParseValue(key, rest);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function* ParseContent(content: string): IterableIterator<[string, any]> {
|
|
83
|
+
for (let i = 0; i < content.length; i++) {
|
|
84
|
+
if (content[i] === '@') {
|
|
85
|
+
return yield* ParseKey(content.slice(i));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export function Parse(content: string): Record<string, any> {
|
|
90
|
+
const properties = [...ParseContent(content)];
|
|
91
|
+
return properties.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
92
|
+
}
|
|
93
|
+
}
|