speexjs-core 0.7.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 +117 -0
- package/CONTRIBUTING.md +55 -0
- package/PUBLISH.md +45 -0
- package/README.md +174 -0
- package/ROADMAP.md +72 -0
- package/SECURITY.md +35 -0
- package/SUMMARY.md +321 -0
- package/dist/async/index.d.ts +232 -0
- package/dist/async/index.js +366 -0
- package/dist/async/index.js.map +1 -0
- package/dist/collection/index.d.ts +230 -0
- package/dist/collection/index.js +375 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/color/index.d.ts +128 -0
- package/dist/color/index.js +167 -0
- package/dist/color/index.js.map +1 -0
- package/dist/core/index.d.ts +119 -0
- package/dist/core/index.js +324 -0
- package/dist/core/index.js.map +1 -0
- package/dist/crypto/index.d.ts +84 -0
- package/dist/crypto/index.js +144 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/date/index.d.ts +588 -0
- package/dist/date/index.js +737 -0
- package/dist/date/index.js.map +1 -0
- package/dist/dep-exray/analyzer/index.d.ts +7 -0
- package/dist/dep-exray/analyzer/index.js +68 -0
- package/dist/dep-exray/analyzer/index.js.map +1 -0
- package/dist/dep-exray/cli.d.ts +1 -0
- package/dist/dep-exray/cli.js +441 -0
- package/dist/dep-exray/cli.js.map +1 -0
- package/dist/dep-exray/index.d.ts +5 -0
- package/dist/dep-exray/index.js +454 -0
- package/dist/dep-exray/index.js.map +1 -0
- package/dist/dep-exray/known-mappings.d.ts +17 -0
- package/dist/dep-exray/known-mappings.js +122 -0
- package/dist/dep-exray/known-mappings.js.map +1 -0
- package/dist/dep-exray/reporter/index.d.ts +5 -0
- package/dist/dep-exray/reporter/index.js +89 -0
- package/dist/dep-exray/reporter/index.js.map +1 -0
- package/dist/dep-exray/scanner/index.d.ts +5 -0
- package/dist/dep-exray/scanner/index.js +299 -0
- package/dist/dep-exray/scanner/index.js.map +1 -0
- package/dist/dep-exray/types.d.ts +38 -0
- package/dist/dep-exray/types.js +1 -0
- package/dist/dep-exray/types.js.map +1 -0
- package/dist/error/index.d.ts +148 -0
- package/dist/error/index.js +115 -0
- package/dist/error/index.js.map +1 -0
- package/dist/index-BgG21uJC.d.ts +166 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +4378 -0
- package/dist/index.js.map +1 -0
- package/dist/io/index.d.ts +39 -0
- package/dist/io/index.js +111 -0
- package/dist/io/index.js.map +1 -0
- package/dist/logger/index.d.ts +1 -0
- package/dist/logger/index.js +214 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/transports.d.ts +1 -0
- package/dist/logger/transports.js +122 -0
- package/dist/logger/transports.js.map +1 -0
- package/dist/math/index.d.ts +362 -0
- package/dist/math/index.js +372 -0
- package/dist/math/index.js.map +1 -0
- package/dist/path/index.d.ts +81 -0
- package/dist/path/index.js +134 -0
- package/dist/path/index.js.map +1 -0
- package/dist/string/index.d.ts +234 -0
- package/dist/string/index.js +411 -0
- package/dist/string/index.js.map +1 -0
- package/dist/type/index.d.ts +85 -0
- package/dist/type/index.js +107 -0
- package/dist/type/index.js.map +1 -0
- package/dist/validation/index.d.ts +203 -0
- package/dist/validation/index.js +402 -0
- package/dist/validation/index.js.map +1 -0
- package/package.json +172 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Predefined error codes mapped to their default HTTP status codes.
|
|
3
|
+
*/
|
|
4
|
+
interface ErrorCodeMap {
|
|
5
|
+
'BAD_REQUEST': 400;
|
|
6
|
+
'UNAUTHORIZED': 401;
|
|
7
|
+
'FORBIDDEN': 403;
|
|
8
|
+
'NOT_FOUND': 404;
|
|
9
|
+
'CONFLICT': 409;
|
|
10
|
+
'VALIDATION_ERROR': 422;
|
|
11
|
+
'TOO_MANY': 429;
|
|
12
|
+
'INTERNAL': 500;
|
|
13
|
+
'BAD_GATEWAY': 502;
|
|
14
|
+
'UNAVAILABLE': 503;
|
|
15
|
+
}
|
|
16
|
+
/** Union of all known error codes. */
|
|
17
|
+
type ErrorCode = keyof ErrorCodeMap;
|
|
18
|
+
/**
|
|
19
|
+
* A typed error with a machine-readable code, HTTP status, optional details, and cause.
|
|
20
|
+
*
|
|
21
|
+
* - `code` – Short machine-readable identifier (e.g. `'NOT_FOUND'`).
|
|
22
|
+
* - `status` – Defaults to the mapped HTTP status for the code; can be overridden.
|
|
23
|
+
* - `details` – Arbitrary metadata attached to the error.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* throw new TypedError('NOT_FOUND', 'User not found', { details: { userId } })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare class TypedError extends Error {
|
|
31
|
+
readonly code: string;
|
|
32
|
+
readonly status: number;
|
|
33
|
+
readonly details?: unknown;
|
|
34
|
+
constructor(code: string, message: string, options?: {
|
|
35
|
+
status?: number;
|
|
36
|
+
details?: unknown;
|
|
37
|
+
cause?: unknown;
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Serialize the error to a plain JSON-safe object.
|
|
41
|
+
*/
|
|
42
|
+
toJSON(): {
|
|
43
|
+
name: string;
|
|
44
|
+
message: string;
|
|
45
|
+
code: string;
|
|
46
|
+
status: number;
|
|
47
|
+
details: unknown;
|
|
48
|
+
cause: unknown;
|
|
49
|
+
stack?: string;
|
|
50
|
+
};
|
|
51
|
+
toString(): string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a typed error from a known error code.
|
|
55
|
+
*
|
|
56
|
+
* The HTTP status is automatically derived from the code but can be overridden
|
|
57
|
+
* via an explicit `status` in options.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* throw createError('NOT_FOUND', 'User not found', { details: { userId: 1 } })
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function createError(code: ErrorCode, message: string, options?: {
|
|
65
|
+
details?: unknown;
|
|
66
|
+
cause?: unknown;
|
|
67
|
+
}): TypedError;
|
|
68
|
+
/**
|
|
69
|
+
* Checks whether an unknown value is a {@link TypedError}.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* if (isTypedError(err)) {
|
|
74
|
+
* console.log(err.code, err.status)
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare function isTypedError(error: unknown): error is TypedError;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Collects multiple errors into a single aggregate error.
|
|
82
|
+
*
|
|
83
|
+
* Useful for batch operations where independent steps may each fail and you
|
|
84
|
+
* want to report all failures together rather than throwing on the first one.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const err = new MultiError([
|
|
89
|
+
* new Error('First failure'),
|
|
90
|
+
* new Error('Second failure'),
|
|
91
|
+
* ])
|
|
92
|
+
* throw err
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare class MultiError extends Error {
|
|
96
|
+
readonly errors: Error[];
|
|
97
|
+
constructor(errors: Error[], message?: string);
|
|
98
|
+
/** Number of collected errors. */
|
|
99
|
+
get length(): number;
|
|
100
|
+
/**
|
|
101
|
+
* Check if any collected error satisfies `predicate`.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* if (err.some(e => e.message.includes('timeout'))) { … }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
some(predicate: (error: Error) => boolean): boolean;
|
|
109
|
+
/** Array of all error messages. */
|
|
110
|
+
get messages(): string[];
|
|
111
|
+
/**
|
|
112
|
+
* Serialize to a plain JSON-safe object.
|
|
113
|
+
*/
|
|
114
|
+
toJSON(): {
|
|
115
|
+
name: string;
|
|
116
|
+
message: string;
|
|
117
|
+
errors: Array<{
|
|
118
|
+
name: string;
|
|
119
|
+
message: string;
|
|
120
|
+
stack?: string;
|
|
121
|
+
}>;
|
|
122
|
+
stack?: string;
|
|
123
|
+
};
|
|
124
|
+
toString(): string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Run `fn` and capture any thrown error.
|
|
128
|
+
*
|
|
129
|
+
* If `fn` returns successfully, `result` holds the return value and `errors`
|
|
130
|
+
* is an empty array. If `fn` throws, `errors` contains the thrown value
|
|
131
|
+
* (wrapped in an `Error` if it is not already one).
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const { result, errors } = collectErrors(() => {
|
|
136
|
+
* return riskyOperation()
|
|
137
|
+
* })
|
|
138
|
+
* if (errors.length > 0) {
|
|
139
|
+
* console.error('Operation failed', errors)
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function collectErrors<T>(fn: () => T): {
|
|
144
|
+
result?: T;
|
|
145
|
+
errors: Error[];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export { type ErrorCode, type ErrorCodeMap, MultiError, TypedError, collectErrors, createError, isTypedError };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// src/error/createError.ts
|
|
2
|
+
var defaultStatus = {
|
|
3
|
+
"BAD_REQUEST": 400,
|
|
4
|
+
"UNAUTHORIZED": 401,
|
|
5
|
+
"FORBIDDEN": 403,
|
|
6
|
+
"NOT_FOUND": 404,
|
|
7
|
+
"CONFLICT": 409,
|
|
8
|
+
"VALIDATION_ERROR": 422,
|
|
9
|
+
"TOO_MANY": 429,
|
|
10
|
+
"INTERNAL": 500,
|
|
11
|
+
"BAD_GATEWAY": 502,
|
|
12
|
+
"UNAVAILABLE": 503
|
|
13
|
+
};
|
|
14
|
+
var TypedError = class extends Error {
|
|
15
|
+
code;
|
|
16
|
+
status;
|
|
17
|
+
details;
|
|
18
|
+
constructor(code, message, options) {
|
|
19
|
+
super(message, { cause: options?.cause });
|
|
20
|
+
this.name = "TypedError";
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.status = options?.status ?? defaultStatus[code] ?? 500;
|
|
23
|
+
this.details = options?.details;
|
|
24
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Serialize the error to a plain JSON-safe object.
|
|
28
|
+
*/
|
|
29
|
+
toJSON() {
|
|
30
|
+
return {
|
|
31
|
+
name: this.name,
|
|
32
|
+
message: this.message,
|
|
33
|
+
code: this.code,
|
|
34
|
+
status: this.status,
|
|
35
|
+
details: this.details,
|
|
36
|
+
cause: this.cause,
|
|
37
|
+
...this.stack ? { stack: this.stack } : {}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
toString() {
|
|
41
|
+
return `${this.name} [${this.code}]: ${this.message}`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function createError(code, message, options) {
|
|
45
|
+
return new TypedError(code, message, options);
|
|
46
|
+
}
|
|
47
|
+
function isTypedError(error) {
|
|
48
|
+
return error instanceof TypedError;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/error/MultiError.ts
|
|
52
|
+
var MultiError = class extends Error {
|
|
53
|
+
errors;
|
|
54
|
+
constructor(errors, message) {
|
|
55
|
+
const joined = errors.map((e) => e.message).join("; ");
|
|
56
|
+
super(message ?? joined);
|
|
57
|
+
this.name = "MultiError";
|
|
58
|
+
this.errors = [...errors];
|
|
59
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
60
|
+
}
|
|
61
|
+
/** Number of collected errors. */
|
|
62
|
+
get length() {
|
|
63
|
+
return this.errors.length;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if any collected error satisfies `predicate`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* if (err.some(e => e.message.includes('timeout'))) { … }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
some(predicate) {
|
|
74
|
+
return this.errors.some(predicate);
|
|
75
|
+
}
|
|
76
|
+
/** Array of all error messages. */
|
|
77
|
+
get messages() {
|
|
78
|
+
return this.errors.map((e) => e.message);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Serialize to a plain JSON-safe object.
|
|
82
|
+
*/
|
|
83
|
+
toJSON() {
|
|
84
|
+
return {
|
|
85
|
+
name: this.name,
|
|
86
|
+
message: this.message,
|
|
87
|
+
errors: this.errors.map((e) => ({
|
|
88
|
+
name: e.name,
|
|
89
|
+
message: e.message,
|
|
90
|
+
...e.stack ? { stack: e.stack } : {}
|
|
91
|
+
})),
|
|
92
|
+
...this.stack ? { stack: this.stack } : {}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
toString() {
|
|
96
|
+
return `${this.name}: ${this.message}`;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
function collectErrors(fn) {
|
|
100
|
+
try {
|
|
101
|
+
return { result: fn(), errors: [] };
|
|
102
|
+
} catch (err) {
|
|
103
|
+
return {
|
|
104
|
+
errors: [err instanceof Error ? err : new Error(String(err))]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
MultiError,
|
|
110
|
+
TypedError,
|
|
111
|
+
collectErrors,
|
|
112
|
+
createError,
|
|
113
|
+
isTypedError
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/error/createError.ts","../../src/error/MultiError.ts"],"sourcesContent":["/**\n * Predefined error codes mapped to their default HTTP status codes.\n */\nexport interface ErrorCodeMap {\n 'BAD_REQUEST': 400\n 'UNAUTHORIZED': 401\n 'FORBIDDEN': 403\n 'NOT_FOUND': 404\n 'CONFLICT': 409\n 'VALIDATION_ERROR': 422\n 'TOO_MANY': 429\n 'INTERNAL': 500\n 'BAD_GATEWAY': 502\n 'UNAVAILABLE': 503\n}\n\n/** Union of all known error codes. */\nexport type ErrorCode = keyof ErrorCodeMap\n\n/** Default HTTP status for each error code. */\nconst defaultStatus: ErrorCodeMap = {\n 'BAD_REQUEST': 400,\n 'UNAUTHORIZED': 401,\n 'FORBIDDEN': 403,\n 'NOT_FOUND': 404,\n 'CONFLICT': 409,\n 'VALIDATION_ERROR': 422,\n 'TOO_MANY': 429,\n 'INTERNAL': 500,\n 'BAD_GATEWAY': 502,\n 'UNAVAILABLE': 503,\n}\n\n/**\n * A typed error with a machine-readable code, HTTP status, optional details, and cause.\n *\n * - `code` – Short machine-readable identifier (e.g. `'NOT_FOUND'`).\n * - `status` – Defaults to the mapped HTTP status for the code; can be overridden.\n * - `details` – Arbitrary metadata attached to the error.\n *\n * @example\n * ```ts\n * throw new TypedError('NOT_FOUND', 'User not found', { details: { userId } })\n * ```\n */\nexport class TypedError extends Error {\n readonly code: string\n readonly status: number\n readonly details?: unknown\n\n constructor(\n code: string,\n message: string,\n options?: { status?: number; details?: unknown; cause?: unknown },\n ) {\n super(message, { cause: options?.cause })\n this.name = 'TypedError'\n this.code = code\n this.status = options?.status ?? defaultStatus[code as ErrorCode] ?? 500\n this.details = options?.details\n\n Object.setPrototypeOf(this, new.target.prototype)\n }\n\n /**\n * Serialize the error to a plain JSON-safe object.\n */\n toJSON(): {\n name: string\n message: string\n code: string\n status: number\n details: unknown\n cause: unknown\n stack?: string\n } {\n return {\n name: this.name,\n message: this.message,\n code: this.code,\n status: this.status,\n details: this.details,\n cause: this.cause,\n ...(this.stack ? { stack: this.stack } : {}),\n }\n }\n\n override toString(): string {\n return `${this.name} [${this.code}]: ${this.message}`\n }\n}\n\n/**\n * Create a typed error from a known error code.\n *\n * The HTTP status is automatically derived from the code but can be overridden\n * via an explicit `status` in options.\n *\n * @example\n * ```ts\n * throw createError('NOT_FOUND', 'User not found', { details: { userId: 1 } })\n * ```\n */\nexport function createError(\n code: ErrorCode,\n message: string,\n options?: { details?: unknown; cause?: unknown },\n): TypedError {\n return new TypedError(code, message, options)\n}\n\n/**\n * Checks whether an unknown value is a {@link TypedError}.\n *\n * @example\n * ```ts\n * if (isTypedError(err)) {\n * console.log(err.code, err.status)\n * }\n * ```\n */\nexport function isTypedError(error: unknown): error is TypedError {\n return error instanceof TypedError\n}\n","/**\n * Collects multiple errors into a single aggregate error.\n *\n * Useful for batch operations where independent steps may each fail and you\n * want to report all failures together rather than throwing on the first one.\n *\n * @example\n * ```ts\n * const err = new MultiError([\n * new Error('First failure'),\n * new Error('Second failure'),\n * ])\n * throw err\n * ```\n */\nexport class MultiError extends Error {\n readonly errors: Error[]\n\n constructor(errors: Error[], message?: string) {\n const joined = errors.map((e) => e.message).join('; ')\n super(message ?? joined)\n this.name = 'MultiError'\n this.errors = [...errors]\n\n Object.setPrototypeOf(this, new.target.prototype)\n }\n\n /** Number of collected errors. */\n get length(): number {\n return this.errors.length\n }\n\n /**\n * Check if any collected error satisfies `predicate`.\n *\n * @example\n * ```ts\n * if (err.some(e => e.message.includes('timeout'))) { … }\n * ```\n */\n some(predicate: (error: Error) => boolean): boolean {\n return this.errors.some(predicate)\n }\n\n /** Array of all error messages. */\n get messages(): string[] {\n return this.errors.map((e) => e.message)\n }\n\n /**\n * Serialize to a plain JSON-safe object.\n */\n toJSON(): {\n name: string\n message: string\n errors: Array<{ name: string; message: string; stack?: string }>\n stack?: string\n } {\n return {\n name: this.name,\n message: this.message,\n errors: this.errors.map((e) => ({\n name: e.name,\n message: e.message,\n ...(e.stack ? { stack: e.stack } : {}),\n })),\n ...(this.stack ? { stack: this.stack } : {}),\n }\n }\n\n override toString(): string {\n return `${this.name}: ${this.message}`\n }\n}\n\n/**\n * Run `fn` and capture any thrown error.\n *\n * If `fn` returns successfully, `result` holds the return value and `errors`\n * is an empty array. If `fn` throws, `errors` contains the thrown value\n * (wrapped in an `Error` if it is not already one).\n *\n * @example\n * ```ts\n * const { result, errors } = collectErrors(() => {\n * return riskyOperation()\n * })\n * if (errors.length > 0) {\n * console.error('Operation failed', errors)\n * }\n * ```\n */\nexport function collectErrors<T>(\n fn: () => T,\n): { result?: T; errors: Error[] } {\n try {\n return { result: fn(), errors: [] }\n } catch (err) {\n return {\n errors: [err instanceof Error ? err : new Error(String(err))],\n }\n }\n}\n"],"mappings":";AAoBA,IAAM,gBAA8B;AAAA,EAClC,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,oBAAoB;AAAA,EACpB,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,eAAe;AACjB;AAcO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,MACA,SACA,SACA;AACA,UAAM,SAAS,EAAE,OAAO,SAAS,MAAM,CAAC;AACxC,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,SAAS,SAAS,UAAU,cAAc,IAAiB,KAAK;AACrE,SAAK,UAAU,SAAS;AAExB,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA,EAKA,SAQE;AACA,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,MAAM,KAAK;AAAA,MACX,QAAQ,KAAK;AAAA,MACb,SAAS,KAAK;AAAA,MACd,OAAO,KAAK;AAAA,MACZ,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,IAC5C;AAAA,EACF;AAAA,EAES,WAAmB;AAC1B,WAAO,GAAG,KAAK,IAAI,KAAK,KAAK,IAAI,MAAM,KAAK,OAAO;AAAA,EACrD;AACF;AAaO,SAAS,YACd,MACA,SACA,SACY;AACZ,SAAO,IAAI,WAAW,MAAM,SAAS,OAAO;AAC9C;AAYO,SAAS,aAAa,OAAqC;AAChE,SAAO,iBAAiB;AAC1B;;;AC5GO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAC3B;AAAA,EAET,YAAY,QAAiB,SAAkB;AAC7C,UAAM,SAAS,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI;AACrD,UAAM,WAAW,MAAM;AACvB,SAAK,OAAO;AACZ,SAAK,SAAS,CAAC,GAAG,MAAM;AAExB,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AAAA;AAAA,EAGA,IAAI,SAAiB;AACnB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,KAAK,WAA+C;AAClD,WAAO,KAAK,OAAO,KAAK,SAAS;AAAA,EACnC;AAAA;AAAA,EAGA,IAAI,WAAqB;AACvB,WAAO,KAAK,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKA,SAKE;AACA,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,QAAQ,KAAK,OAAO,IAAI,CAAC,OAAO;AAAA,QAC9B,MAAM,EAAE;AAAA,QACR,SAAS,EAAE;AAAA,QACX,GAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAAA,MACtC,EAAE;AAAA,MACF,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,IAC5C;AAAA,EACF;AAAA,EAES,WAAmB;AAC1B,WAAO,GAAG,KAAK,IAAI,KAAK,KAAK,OAAO;AAAA,EACtC;AACF;AAmBO,SAAS,cACd,IACiC;AACjC,MAAI;AACF,WAAO,EAAE,QAAQ,GAAG,GAAG,QAAQ,CAAC,EAAE;AAAA,EACpC,SAAS,KAAK;AACZ,WAAO;AAAA,MACL,QAAQ,CAAC,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,IAC9D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the severity level of a log entry.
|
|
3
|
+
* Ordered from least to most severe: debug < info < warn < error.
|
|
4
|
+
*/
|
|
5
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
6
|
+
/**
|
|
7
|
+
* Log function signature bound to a specific severity level.
|
|
8
|
+
*/
|
|
9
|
+
type LogFn = (message: string, meta?: Record<string, unknown>) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for creating a Logger instance.
|
|
12
|
+
*/
|
|
13
|
+
interface LoggerOptions {
|
|
14
|
+
/** Minimum log level to output (default: 'info'). */
|
|
15
|
+
level?: LogLevel;
|
|
16
|
+
/** Optional name tag prepended to every message as `[name]`. */
|
|
17
|
+
name?: string;
|
|
18
|
+
/** Custom transport; defaults to {@link consoleTransport}. */
|
|
19
|
+
transport?: Transport$1;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A transport handles the formatted output of log entries.
|
|
23
|
+
* Implementations write to stdout, files, buffers, or remote services.
|
|
24
|
+
*/
|
|
25
|
+
interface Transport$1 {
|
|
26
|
+
log(level: LogLevel, message: string, meta?: Record<string, unknown>): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Structured logger with level filtering, child loggers, and pluggable transport.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const log = new Logger({ level: 'debug', name: 'app' })
|
|
34
|
+
* log.info('server started', { port: 3000 })
|
|
35
|
+
*
|
|
36
|
+
* const child = log.child({ requestId: 'abc-123' })
|
|
37
|
+
* child.warn('slow query', { durationMs: 450 })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare class Logger {
|
|
41
|
+
private _level;
|
|
42
|
+
private _name?;
|
|
43
|
+
private _transport;
|
|
44
|
+
private _extraMeta;
|
|
45
|
+
constructor(options?: LoggerOptions);
|
|
46
|
+
private _shouldLog;
|
|
47
|
+
private _log;
|
|
48
|
+
/** Log at `debug` level. Only emitted when the current level is `'debug'`. */
|
|
49
|
+
debug: LogFn;
|
|
50
|
+
/** Log at `info` level. Emitted when level is `'debug'` or `'info'`. */
|
|
51
|
+
info: LogFn;
|
|
52
|
+
/** Log at `warn` level. Emitted when level is `'debug'`, `'info'`, or `'warn'`. */
|
|
53
|
+
warn: LogFn;
|
|
54
|
+
/** Log at `error` level. Always emitted regardless of current level. */
|
|
55
|
+
error: LogFn;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a child logger that inherits the parent's level, name, and transport,
|
|
58
|
+
* but merges `extraMeta` into every log call. Child metadata is shallow-merged
|
|
59
|
+
* on top of the parent's inherited metadata.
|
|
60
|
+
*
|
|
61
|
+
* @param extraMeta - Additional context to include in every log entry.
|
|
62
|
+
*/
|
|
63
|
+
child(extraMeta: Record<string, unknown>): Logger;
|
|
64
|
+
/** Updates the minimum log level for this instance. */
|
|
65
|
+
setLevel(level: LogLevel): void;
|
|
66
|
+
/** Returns the current minimum log level. */
|
|
67
|
+
getLevel(): LogLevel;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new named Logger.
|
|
70
|
+
* Convenience shorthand for `new Logger({ ...options, name })`.
|
|
71
|
+
*
|
|
72
|
+
* @param name - The name tag shown in log output.
|
|
73
|
+
* @param options - Additional configuration.
|
|
74
|
+
*/
|
|
75
|
+
static create(name: string, options?: LoggerOptions): Logger;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Default transport that writes formatted log lines to `console.log`.
|
|
79
|
+
*
|
|
80
|
+
* Output format: `[LEVEL] message {meta}`
|
|
81
|
+
*
|
|
82
|
+
* When a logger has a name, the format becomes: `[LEVEL] [name] message {meta}`
|
|
83
|
+
*/
|
|
84
|
+
declare const consoleTransport: Transport$1;
|
|
85
|
+
/**
|
|
86
|
+
* Default logger instance at `'info'` level with no name.
|
|
87
|
+
*/
|
|
88
|
+
declare const logger: Logger;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A transport handles the formatted output of log entries.
|
|
92
|
+
*/
|
|
93
|
+
interface Transport {
|
|
94
|
+
log(level: LogLevel, message: string, meta?: Record<string, unknown>): void;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates a console transport that writes formatted log lines to `console.log`.
|
|
98
|
+
*
|
|
99
|
+
* The level prefix is optionally colored using ANSI escape codes:
|
|
100
|
+
* - `debug` → gray
|
|
101
|
+
* - `info` → blue
|
|
102
|
+
* - `warn` → yellow
|
|
103
|
+
* - `error` → red
|
|
104
|
+
*
|
|
105
|
+
* @param options - Configuration for the console transport.
|
|
106
|
+
* @param options.colors - Enable ANSI color output (default: `true`).
|
|
107
|
+
* @param options.timestamp - Prepend an ISO-8601 timestamp (default: `false`).
|
|
108
|
+
*/
|
|
109
|
+
declare function createConsoleTransport(options?: {
|
|
110
|
+
colors?: boolean;
|
|
111
|
+
timestamp?: boolean;
|
|
112
|
+
}): Transport;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a transport that outputs structured JSON lines.
|
|
115
|
+
*
|
|
116
|
+
* Each log entry is serialized as a single JSON object with
|
|
117
|
+
* `timestamp`, `level`, `message`, and optional `meta` fields.
|
|
118
|
+
*
|
|
119
|
+
* @param options - Configuration for the JSON transport.
|
|
120
|
+
* @param options.stream - A writable stream (e.g. `process.stdout`).
|
|
121
|
+
* Defaults to `process.stdout` in Node.js, falls
|
|
122
|
+
* back to `console.log` in browsers.
|
|
123
|
+
*/
|
|
124
|
+
declare function createJsonTransport(options?: {
|
|
125
|
+
stream?: {
|
|
126
|
+
write(data: string): void;
|
|
127
|
+
};
|
|
128
|
+
}): Transport;
|
|
129
|
+
/**
|
|
130
|
+
* Creates a transport that appends log entries to a file.
|
|
131
|
+
*
|
|
132
|
+
* Each line is formatted as: `[timestamp] [LEVEL] message {meta}`
|
|
133
|
+
*
|
|
134
|
+
* ⚠️ Node.js only. Silently discards log entries when `fs` is unavailable
|
|
135
|
+
* (browsers, Deno, Bun — though Bun supports `fs`).
|
|
136
|
+
*
|
|
137
|
+
* @param filename - Path to the log file.
|
|
138
|
+
* @param options - Configuration for the file transport.
|
|
139
|
+
* @param options.maxSize - Maximum file size in bytes before rotation
|
|
140
|
+
* (default: 10 MB). **Note:** rotation is not
|
|
141
|
+
* yet implemented; this is reserved for future use.
|
|
142
|
+
*/
|
|
143
|
+
declare function createFileTransport(filename: string, _options?: {
|
|
144
|
+
maxSize?: number;
|
|
145
|
+
}): Transport;
|
|
146
|
+
/**
|
|
147
|
+
* Creates a buffered transport that batches log entries and flushes them
|
|
148
|
+
* to the underlying transport when either the buffer size or flush interval
|
|
149
|
+
* is reached (whichever comes first).
|
|
150
|
+
*
|
|
151
|
+
* Useful for reducing I/O pressure in high-throughput scenarios.
|
|
152
|
+
*
|
|
153
|
+
* @param transport - The underlying transport to flush to.
|
|
154
|
+
* @param options - Configuration for the buffer.
|
|
155
|
+
* @param options.maxSize - Maximum number of entries before forced flush
|
|
156
|
+
* (default: 100).
|
|
157
|
+
* @param options.flushIntervalMs - How often to auto-flush in milliseconds
|
|
158
|
+
* (default: 5000). Set to `0` to disable
|
|
159
|
+
* interval flushing.
|
|
160
|
+
*/
|
|
161
|
+
declare function createBufferedTransport(transport: Transport, options?: {
|
|
162
|
+
maxSize?: number;
|
|
163
|
+
flushIntervalMs?: number;
|
|
164
|
+
}): Transport;
|
|
165
|
+
|
|
166
|
+
export { type LogLevel as L, type Transport$1 as T, Logger as a, createBufferedTransport as b, consoleTransport as c, createConsoleTransport as d, createFileTransport as e, createJsonTransport as f, type Transport as g, type LogFn as h, type LoggerOptions as i, logger as l };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { DebounceOptions, DebouncedFunction, MemoizedFunction, RetryOptions, compose, debounce, deepClone, deepEqual, deepMerge, identity, memoize, noop, once, pipe, retry, throttle } from './core/index.js';
|
|
2
|
+
export { DivisionByZeroError, add, approxEqual, average, ceil, clamp, combinations, correlation, div, factorial, floor, formatCurrency, gcd, geometricMean, inRange, isEven, isOdd, isPrime, lcm, lerp, mapRange, median, mode, mul, percentageOf, percentile, permutations, randomInt, range, round, sampleStddev, stddev, sub, sum, toDegrees, toRadians, weightedAverage } from './math/index.js';
|
|
3
|
+
export { DateDiff, Duration, InvalidDateError, TIMEZONE_WIB, TIMEZONE_WIT, TIMEZONE_WITA, addBusinessDays, addDays, addMonths, addYears, calculateAge, dateDiff, dayOfYear, daysInMonth, endOfDay, endOfMonth, endOfYear, formatDate, formatDuration, formatInTimezone, getIndonesianHolidayNames, isAfter, isBefore, isBetween, isBusinessDay, isFuture, isHolidayIndonesia, isLeapYear, isPast, isSameDay, isToday, isTomorrow, isWeekend, isYesterday, lastFriday, lastMonday, lastSaturday, lastSunday, lastThursday, lastTuesday, lastWednesday, maxDate, minDate, nextFriday, nextMonday, nextSaturday, nextSunday, nextThursday, nextTuesday, nextWednesday, parseDate, parseDuration, quarter, startOfDay, startOfMonth, startOfYear, timeAgo, timeRemaining, toTimezone, weekOfYear } from './date/index.js';
|
|
4
|
+
export { base64Decode, base64Encode, checksum, constantTimeEqual, generateOTP, generateToken, hash, randomHex, simpleHash, xorCipher } from './crypto/index.js';
|
|
5
|
+
export { ParsedPath, basename, dirname, extname, format, isAbsolute, join, normalize, parse, relative, resolve } from './path/index.js';
|
|
6
|
+
export { SortDirection, chunk, compact, countBy, deepGet, deepSet, difference, drop, dropRight, findIndex, findLast, first, flatten, groupBy, intersection, isEmpty, keyBy, last, maxBy, minBy, nth, omit, orderBy, partition, pick, pluck, sample, sampleSize, shuffle, slidingWindows, sortBy, sumBy, take, takeRight, topoSort, tumblingWindows, union, uniq, uniqueBy, unzip, without, zip } from './collection/index.js';
|
|
7
|
+
export { camelCase, capitalize, charCount, countOccurrences, dedent, escapeHtml, formatBytes, formatRupiah, fuzzyMatch, isAnagram, isPalindrome, kebabCase, levenshtein, maskString, nanoid, pad, padEnd, padStart, pascalCase, pluralize, randomBoolean, randomString, reverse, similarity, slugify, snakeCase, stripHtml, swapCase, template, terbilang, toCobolCase, trim, trimEnd, trimStart, truncate, truncateWords, unescapeHtml, uuid, wordCount, words } from './string/index.js';
|
|
8
|
+
export { Deferred, MemoizeAsyncOptions, Mutex, Queue, QueueOptions, RateLimiter, Semaphore, allSettledMap, batch, deferred, memoizeAsync, parallelMap, pipeline, raceWithTimeout, retryAsync, sleep, timeout, waterfall } from './async/index.js';
|
|
9
|
+
export { CsvOptions, env, envBool, envInt, parseCsv, safeJsonParse, stringifyCsv } from './io/index.js';
|
|
10
|
+
export { assertDefined, assertType, castArray, ensureArray, getType, isArray, isBoolean, isDate, isFunction, isMap, isNil, isNull, isNumber, isObject, isPromise, isRegExp, isSet, isString, isUndefined } from './type/index.js';
|
|
11
|
+
export { scanProject } from './dep-exray/scanner/index.js';
|
|
12
|
+
export { generateReport } from './dep-exray/reporter/index.js';
|
|
13
|
+
export { analyzeUsage } from './dep-exray/analyzer/index.js';
|
|
14
|
+
export { DependencyInfo, ReplacementSuggestion, ScanResult, ScannerConfig, SecurityIssue } from './dep-exray/types.js';
|
|
15
|
+
export { KNOWN_CVES, KNOWN_MAPPINGS } from './dep-exray/known-mappings.js';
|
|
16
|
+
export { NIKInfo, isEmail, isKodepos, isNIK, isNPWP, isNoBPJS, isNoKK, isNoRekening, isNoSIM, isPassport, isPhone, isPlatNomor, isURL, parseNIK } from './validation/index.js';
|
|
17
|
+
export { ErrorCode, MultiError, TypedError, collectErrors, createError, isTypedError } from './error/index.js';
|
|
18
|
+
export { L as LogLevel, a as Logger, T as Transport, c as consoleTransport, b as createBufferedTransport, d as createConsoleTransport, e as createFileTransport, f as createJsonTransport, l as logger } from './index-BgG21uJC.js';
|
|
19
|
+
export { alpha, complementary, contrastRatio, darken, hexToHsl, hexToRgb, hslToHex, isDark, isLight, isValidHex, lighten, meetsWCAG, mix, randomColor, rgbToHex } from './color/index.js';
|