@wener/common 2.0.5 → 2.0.6
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/lib/ai/qwen3vl/index.js +1 -1
- package/lib/ai/qwen3vl/utils.js +15 -15
- package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
- package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
- package/lib/ai/vision/index.js +2 -2
- package/lib/ai/vision/resolveImageAnnotation.js +81 -95
- package/lib/cn/ChineseResidentIdNo.js +55 -41
- package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
- package/lib/cn/ChineseResidentIdNo.test.js +22 -21
- package/lib/cn/DivisionCode.js +220 -235
- package/lib/cn/DivisionCode.mod.js +6 -1
- package/lib/cn/DivisionCode.test.js +92 -121
- package/lib/cn/Mod11.js +18 -37
- package/lib/cn/Mod31.js +23 -41
- package/lib/cn/UnifiedSocialCreditCode.js +143 -137
- package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
- package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
- package/lib/cn/formatChineseAmount.js +46 -71
- package/lib/cn/index.js +6 -6
- package/lib/cn/mod.js +5 -3
- package/lib/cn/parseChineseNumber.js +81 -85
- package/lib/cn/parseChineseNumber.test.js +183 -261
- package/lib/cn/pinyin/cartesianProduct.js +19 -19
- package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
- package/lib/cn/pinyin/loader.js +13 -11
- package/lib/cn/pinyin/preload.js +2 -1
- package/lib/cn/pinyin/toPinyin.test.js +149 -161
- package/lib/cn/pinyin/toPinyinPure.js +28 -23
- package/lib/cn/pinyin/transform.js +11 -11
- package/lib/cn/types.d.js +2 -2
- package/lib/consola/createStandardConsolaReporter.js +14 -15
- package/lib/consola/formatLogObject.js +149 -133
- package/lib/consola/formatLogObject.test.js +167 -178
- package/lib/consola/index.js +2 -2
- package/lib/data/formatSort.js +14 -12
- package/lib/data/formatSort.test.js +33 -33
- package/lib/data/index.js +3 -3
- package/lib/data/maybeNumber.js +23 -23
- package/lib/data/parseSort.js +75 -68
- package/lib/data/parseSort.test.js +196 -187
- package/lib/data/resolvePagination.js +38 -39
- package/lib/data/resolvePagination.test.js +228 -218
- package/lib/data/types.d.js +2 -2
- package/lib/dayjs/dayjs.js +20 -20
- package/lib/dayjs/formatDuration.js +56 -56
- package/lib/dayjs/formatDuration.test.js +63 -77
- package/lib/dayjs/index.js +4 -4
- package/lib/dayjs/parseDuration.js +21 -26
- package/lib/dayjs/parseRelativeTime.js +65 -66
- package/lib/dayjs/parseRelativeTime.test.js +227 -243
- package/lib/dayjs/resolveRelativeTime.js +73 -72
- package/lib/dayjs/resolveRelativeTime.test.js +296 -307
- package/lib/decimal/index.js +1 -1
- package/lib/decimal/parseDecimal.js +12 -12
- package/lib/drain3/Drain.js +303 -338
- package/lib/drain3/LogCluster.js +25 -25
- package/lib/drain3/Node.js +24 -24
- package/lib/drain3/TemplateMiner.js +197 -196
- package/lib/drain3/index.js +5 -5
- package/lib/drain3/persistence/FilePersistence.js +19 -19
- package/lib/drain3/persistence/MemoryPersistence.js +8 -8
- package/lib/drain3/persistence/PersistenceHandler.js +2 -2
- package/lib/drain3/types.js +2 -2
- package/lib/emittery/emitter.js +7 -7
- package/lib/emittery/index.js +1 -1
- package/lib/foundation/schema/SexType.js +15 -12
- package/lib/foundation/schema/index.js +1 -1
- package/lib/foundation/schema/parseSexType.js +15 -16
- package/lib/foundation/schema/types.js +8 -6
- package/lib/fs/FileSystemError.js +18 -18
- package/lib/fs/IFileSystem.d.js +2 -2
- package/lib/fs/MemoryFileSystem.test.js +172 -181
- package/lib/fs/createBrowserFileSystem.js +222 -235
- package/lib/fs/createMemoryFileSystem.js +472 -510
- package/lib/fs/createSandboxFileSystem.js +102 -101
- package/lib/fs/createWebDavFileSystem.js +162 -149
- package/lib/fs/createWebFileSystem.js +197 -220
- package/lib/fs/findMimeType.js +14 -14
- package/lib/fs/index.js +7 -7
- package/lib/fs/minio/createMinioFileSystem.js +959 -956
- package/lib/fs/minio/index.js +1 -1
- package/lib/fs/orpc/FileSystemContract.js +57 -57
- package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
- package/lib/fs/orpc/index.js +2 -2
- package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
- package/lib/fs/orpc/server/index.js +1 -1
- package/lib/fs/s3/createS3MiniFileSystem.js +756 -737
- package/lib/fs/s3/index.js +1 -1
- package/lib/fs/s3/s3mini.test.js +524 -553
- package/lib/fs/scandir.js +56 -56
- package/lib/fs/server/createDatabaseFileSystem.js +834 -741
- package/lib/fs/server/createNodeFileSystem.js +407 -405
- package/lib/fs/server/dbfs.test.js +201 -214
- package/lib/fs/server/index.js +1 -1
- package/lib/fs/server/loadTestDatabase.js +40 -43
- package/lib/fs/tests/runFileSystemTest.js +352 -316
- package/lib/fs/types.js +17 -20
- package/lib/fs/utils/getFileUrl.js +24 -30
- package/lib/fs/utils.js +17 -17
- package/lib/fs/webdav/index.js +1 -1
- package/lib/index.js +2 -2
- package/lib/jsonschema/JsonSchema.js +216 -155
- package/lib/jsonschema/JsonSchema.test.js +123 -124
- package/lib/jsonschema/forEachJsonSchema.js +41 -41
- package/lib/jsonschema/index.js +2 -2
- package/lib/jsonschema/types.d.js +2 -2
- package/lib/meta/defineFileType.js +32 -38
- package/lib/meta/defineInit.js +39 -35
- package/lib/meta/defineMetadata.js +37 -34
- package/lib/meta/defineMetadata.test.js +13 -12
- package/lib/meta/index.js +3 -3
- package/lib/orpc/createOpenApiContractClient.js +26 -24
- package/lib/orpc/createRpcContractClient.js +37 -31
- package/lib/orpc/index.js +2 -2
- package/lib/orpc/resolveLinkPlugins.js +25 -25
- package/lib/password/PHC.js +187 -189
- package/lib/password/PHC.test.js +517 -535
- package/lib/password/Password.js +85 -80
- package/lib/password/Password.test.js +330 -364
- package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
- package/lib/password/createBase64PasswordAlgorithm.js +11 -11
- package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
- package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
- package/lib/password/createScryptPasswordAlgorithm.js +74 -63
- package/lib/password/index.js +5 -5
- package/lib/password/server/index.js +1 -1
- package/lib/resource/Identifiable.js +2 -2
- package/lib/resource/ListQuery.js +42 -42
- package/lib/resource/getTitleOfResource.js +5 -5
- package/lib/resource/index.js +2 -2
- package/lib/resource/schema/AnyResourceSchema.js +91 -89
- package/lib/resource/schema/BaseResourceSchema.js +26 -26
- package/lib/resource/schema/ResourceActionType.js +117 -115
- package/lib/resource/schema/ResourceStatus.js +94 -92
- package/lib/resource/schema/ResourceType.js +25 -23
- package/lib/resource/schema/index.js +5 -5
- package/lib/resource/schema/types.js +86 -55
- package/lib/resource/schema/types.test.js +16 -13
- package/lib/s3/formatS3Url.js +60 -60
- package/lib/s3/formatS3Url.test.js +238 -261
- package/lib/s3/index.js +2 -2
- package/lib/s3/parseS3Url.js +61 -60
- package/lib/s3/parseS3Url.test.js +270 -269
- package/lib/schema/SchemaRegistry.js +41 -42
- package/lib/schema/SchemaRegistry.mod.js +1 -1
- package/lib/schema/TypeSchema.d.js +2 -2
- package/lib/schema/createSchemaData.js +113 -67
- package/lib/schema/findJsonSchemaByPath.js +28 -23
- package/lib/schema/formatZodError.js +112 -131
- package/lib/schema/formatZodError.test.js +192 -195
- package/lib/schema/getSchemaCache.js +7 -7
- package/lib/schema/getSchemaOptions.js +17 -16
- package/lib/schema/index.js +6 -6
- package/lib/schema/toJsonSchema.js +195 -189
- package/lib/schema/toJsonSchema.test.js +34 -26
- package/lib/schema/validate.js +105 -96
- package/lib/tools/generateSchema.js +40 -40
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
- package/lib/utils/buildBaseUrl.js +8 -8
- package/lib/utils/buildRedactorFormSchema.js +54 -53
- package/lib/utils/getEstimateProcessTime.js +24 -19
- package/lib/utils/index.js +3 -3
- package/lib/utils/resolveFeatureOptions.js +9 -9
- package/package.json +14 -14
- package/src/ai/vision/index.ts +2 -2
- package/src/cn/index.ts +1 -2
- package/src/consola/index.ts +1 -1
- package/src/data/index.ts +3 -4
- package/src/data/resolvePagination.ts +2 -2
- package/src/dayjs/formatDuration.ts +8 -9
- package/src/dayjs/index.ts +1 -1
- package/src/dayjs/parseRelativeTime.ts +1 -1
- package/src/dayjs/resolveRelativeTime.ts +1 -1
- package/src/drain3/Drain.test.ts +2 -2
- package/src/drain3/index.ts +2 -4
- package/src/fs/createWebDavFileSystem.ts +2 -7
- package/src/fs/createWebFileSystem.ts +1 -1
- package/src/fs/index.ts +4 -4
- package/src/fs/minio/createMinioFileSystem.ts +2 -2
- package/src/fs/minio/index.ts +1 -1
- package/src/fs/s3/createS3MiniFileSystem.ts +1 -1
- package/src/fs/server/createDatabaseFileSystem.ts +84 -120
- package/src/fs/server/dbfs.test.ts +14 -10
- package/src/fs/server/index.ts +1 -0
- package/src/fs/server/loadTestDatabase.ts +8 -119
- package/src/jsonschema/index.ts +1 -1
- package/src/meta/index.ts +2 -3
- package/src/orm/createSqliteDialect.ts +17 -0
- package/src/orm/index.ts +1 -0
- package/src/orpc/createOpenApiContractClient.ts +1 -1
- package/src/orpc/index.ts +1 -1
- package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
- package/src/password/index.ts +2 -2
- package/src/resource/index.ts +3 -3
- package/src/resource/schema/index.ts +4 -4
- package/src/s3/index.ts +1 -1
- package/src/schema/SchemaRegistry.ts +1 -1
- package/src/schema/createSchemaData.ts +1 -1
- package/src/schema/findJsonSchemaByPath.ts +1 -1
- package/src/schema/index.ts +5 -5
- package/src/schema/validate.ts +1 -1
- package/src/utils/buildRedactorFormSchema.ts +1 -1
- package/src/utils/formatNumber.ts +18 -0
- package/src/utils/formatPercent.ts +17 -0
- package/src/utils/index.ts +3 -3
- package/src/utils/resolveFeatureOptions.ts +1 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export function transformData(input) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
let out = {};
|
|
3
|
+
for (let [py, chars] of Object.entries(input)) {
|
|
4
|
+
for (let c of chars) {
|
|
5
|
+
if (!out[c]) {
|
|
6
|
+
out[c] = [];
|
|
7
|
+
}
|
|
8
|
+
out[c].push(py);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return out;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
//# sourceMappingURL=transform.js.map
|
|
14
|
+
//# sourceMappingURL=transform.js.map
|
package/lib/cn/types.d.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { formatLogObject } from
|
|
1
|
+
import { formatLogObject } from './formatLogObject.js';
|
|
2
2
|
export function createStandardConsolaReporter({ format = formatLogObject } = {}) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
3
|
+
return {
|
|
4
|
+
log: (o, ctx) => {
|
|
5
|
+
let out = format(o, ctx);
|
|
6
|
+
let fn = console.log;
|
|
7
|
+
const { level } = o;
|
|
8
|
+
if (level < 1) {
|
|
9
|
+
fn = console.error;
|
|
10
|
+
} else if (level === 1) {
|
|
11
|
+
fn = console.warn;
|
|
12
|
+
}
|
|
13
|
+
fn(out);
|
|
14
|
+
},
|
|
15
|
+
};
|
|
17
16
|
}
|
|
18
17
|
//# sourceMappingURL=createStandardConsolaReporter.js.map
|
|
@@ -1,158 +1,174 @@
|
|
|
1
|
-
import colors, { Chalk } from
|
|
2
|
-
import dayjs from
|
|
3
|
-
import { isDevelopment } from
|
|
1
|
+
import colors, { Chalk } from 'chalk';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import { isDevelopment } from 'std-env';
|
|
4
|
+
|
|
4
5
|
const LevelColors = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
trace: colors.gray,
|
|
7
|
+
debug: colors.cyan,
|
|
8
|
+
info: colors.blueBright,
|
|
9
|
+
warn: colors.yellow,
|
|
10
|
+
error: colors.red,
|
|
11
|
+
fatal: colors.bgRed.white,
|
|
12
|
+
silent: colors.white,
|
|
13
|
+
log: colors.white,
|
|
14
|
+
success: colors.green,
|
|
15
|
+
fail: colors.red,
|
|
16
|
+
ready: colors.green,
|
|
17
|
+
start: colors.cyan,
|
|
18
|
+
box: colors.white,
|
|
19
|
+
verbose: colors.green,
|
|
19
20
|
};
|
|
20
21
|
const levelShort = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
trace: 'TRAC',
|
|
23
|
+
debug: 'DEBG',
|
|
24
|
+
info: 'INFO',
|
|
25
|
+
warn: 'WARN',
|
|
26
|
+
error: 'ERRO',
|
|
27
|
+
fatal: 'FATL',
|
|
28
|
+
silent: 'SLNT',
|
|
29
|
+
log: 'LOG ',
|
|
30
|
+
success: 'SUCC',
|
|
31
|
+
fail: 'FAIL',
|
|
32
|
+
ready: 'READ',
|
|
33
|
+
start: 'STRT',
|
|
34
|
+
box: 'BOX ',
|
|
35
|
+
verbose: 'VERB',
|
|
35
36
|
};
|
|
36
37
|
const start = Date.now();
|
|
37
38
|
const Colors = colors;
|
|
38
39
|
const NoColors = new Chalk({
|
|
39
|
-
|
|
40
|
+
level: 0,
|
|
40
41
|
});
|
|
41
42
|
export function formatLogObject(o, ctx) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
43
|
+
const shouldColor = Boolean(ctx.options?.formatOptions?.colors);
|
|
44
|
+
let { date, type, tag } = o;
|
|
45
|
+
type = type === 'log' ? 'info' : type;
|
|
46
|
+
const colors = shouldColor ? Colors : NoColors;
|
|
47
|
+
let color = LevelColors[type] || colors.white;
|
|
48
|
+
if (!shouldColor) {
|
|
49
|
+
color = (v) => v;
|
|
50
|
+
}
|
|
51
|
+
const levelText = levelShort[type] || type.toUpperCase().slice(0, 4); // Get first 4 chars, consistent uppercase
|
|
52
|
+
let line = '';
|
|
53
|
+
let out = [];
|
|
54
|
+
// Timestamp
|
|
55
|
+
if (isDevelopment) {
|
|
56
|
+
// process.hrtime.bigint()
|
|
57
|
+
let diff = (date.getTime() - start) / 1000;
|
|
58
|
+
out.push(colors.gray(diff.toFixed(3).padStart(7, ' ')));
|
|
59
|
+
} else {
|
|
60
|
+
out.push(colors.gray(dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS')));
|
|
61
|
+
}
|
|
62
|
+
// Log Level (colored)
|
|
63
|
+
// Pad to 4 characters
|
|
64
|
+
out.push(color(levelText.padEnd(4, ' ')));
|
|
65
|
+
if (tag) {
|
|
66
|
+
out.push(colors.yellow(`[${tag}]`)); // Added color for tag
|
|
67
|
+
}
|
|
68
|
+
{
|
|
69
|
+
const [message, ...additional] = formatArgs(o.args, {
|
|
70
|
+
colors: shouldColor,
|
|
71
|
+
}).split('\n');
|
|
72
|
+
out.push(characterFormat(message));
|
|
73
|
+
line = out.join(' ');
|
|
74
|
+
if (additional.length > 0) {
|
|
75
|
+
line += characterFormat(additional.join('\n'));
|
|
76
|
+
}
|
|
77
|
+
if (type === 'trace') {
|
|
78
|
+
const _err = new Error(`Trace: ${o.message}`);
|
|
79
|
+
line += formatStack(_err.stack || '', _err.message);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// if (!message && typeof args[0] === 'string') {
|
|
83
|
+
// message = args.shift();
|
|
84
|
+
// }
|
|
85
|
+
// if (message) {
|
|
86
|
+
// out.push(message);
|
|
87
|
+
// }
|
|
88
|
+
// if (args.length) {
|
|
89
|
+
// out.push(...args.map((a) => (typeof a === 'string' ? a : JSON.stringify(a)))); // Handle non-string args
|
|
90
|
+
// }
|
|
91
|
+
// todo format error
|
|
92
|
+
// https://github.com/unjs/consola/blob/main/src/reporters/fancy.ts
|
|
93
|
+
// return out.join(' '); // Increased spacing for better readability
|
|
94
|
+
return line;
|
|
94
95
|
}
|
|
95
96
|
function characterFormat(str) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
return str // highlight backticks
|
|
98
|
+
.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)) // underline underscores
|
|
99
|
+
.replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `);
|
|
99
100
|
}
|
|
100
101
|
function parseStack(stack, message) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
// const cwd = process.cwd() + sep;
|
|
103
|
+
const lines = stack
|
|
104
|
+
.split('\n')
|
|
105
|
+
.splice(message.split('\n').length)
|
|
106
|
+
.map((l) => l.trim().replace('file://', ''));
|
|
107
|
+
return lines;
|
|
104
108
|
}
|
|
105
109
|
function formatStack(stack, message, opts) {
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
const indent = ' '.repeat((opts?.errorLevel || 0) + 1);
|
|
111
|
+
return (
|
|
112
|
+
`\n${indent}` +
|
|
113
|
+
parseStack(stack, message)
|
|
114
|
+
.map(
|
|
115
|
+
(line) =>
|
|
116
|
+
` ${line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)}`,
|
|
117
|
+
)
|
|
118
|
+
.join(`\n${indent}`)
|
|
119
|
+
);
|
|
108
120
|
}
|
|
109
121
|
function formatArgs(args, opts) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
const _args = args.map((arg) => {
|
|
123
|
+
if (arg && typeof arg.stack === 'string') {
|
|
124
|
+
return formatError(arg, opts);
|
|
125
|
+
}
|
|
126
|
+
return arg;
|
|
127
|
+
});
|
|
128
|
+
// Only supported with Node >= 10
|
|
129
|
+
// https://nodejs.org/api/util.html#util_util_inspect_object_options
|
|
130
|
+
return formatWithOptions(Boolean(opts.colors), ..._args);
|
|
119
131
|
}
|
|
120
132
|
function formatWithOptions(shouldColor, ...params) {
|
|
121
|
-
|
|
133
|
+
return params.map((value) => formatValue(value, shouldColor)).join(' ');
|
|
122
134
|
}
|
|
123
135
|
function formatValue(value, shouldColor = false) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
136
|
+
const colors = shouldColor ? Colors : NoColors;
|
|
137
|
+
if (value === null) return 'null';
|
|
138
|
+
if (value === undefined) return 'undefined';
|
|
139
|
+
if (typeof value === 'string') return value;
|
|
140
|
+
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
|
|
141
|
+
if (typeof value === 'object' && value.constructor === Object) {
|
|
142
|
+
const entries = Object.entries(value);
|
|
143
|
+
if (entries.length === 0) return '{}';
|
|
144
|
+
return entries
|
|
145
|
+
.map(([key, val]) => {
|
|
146
|
+
const keyStr = shouldColor ? colors.blue(key) : key;
|
|
147
|
+
const valStr = shouldColor ? colors.green(JSON.stringify(val)) : JSON.stringify(val);
|
|
148
|
+
return `${keyStr}=${valStr}`;
|
|
149
|
+
})
|
|
150
|
+
.join(' ');
|
|
151
|
+
}
|
|
152
|
+
// For arrays and other objects, use JSON.stringify directly
|
|
153
|
+
try {
|
|
154
|
+
const result = JSON.stringify(value);
|
|
155
|
+
return shouldColor ? colors.green(result) : result;
|
|
156
|
+
} catch {
|
|
157
|
+
return String(value);
|
|
158
|
+
}
|
|
145
159
|
}
|
|
146
160
|
function formatError(err, opts) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
161
|
+
const message = err.message ?? formatWithOptions(Boolean(opts.colors), err);
|
|
162
|
+
const stack = err.stack ? formatStack(err.stack, message, opts) : '';
|
|
163
|
+
const level = opts?.errorLevel || 0;
|
|
164
|
+
const causedPrefix = level > 0 ? `${' '.repeat(level)}[cause]: ` : '';
|
|
165
|
+
const causedError = err.cause
|
|
166
|
+
? `\n\n${formatError(err.cause, {
|
|
167
|
+
...opts,
|
|
168
|
+
errorLevel: level + 1,
|
|
169
|
+
})}`
|
|
170
|
+
: '';
|
|
171
|
+
return `${causedPrefix + message}\n${stack}${causedError}`;
|
|
156
172
|
}
|
|
157
173
|
|
|
158
|
-
//# sourceMappingURL=formatLogObject.js.map
|
|
174
|
+
//# sourceMappingURL=formatLogObject.js.map
|