@tstdl/base 0.93.76 → 0.93.78
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/ai/prompts/instructions-formatter.d.ts +68 -5
- package/ai/prompts/instructions-formatter.js +11 -3
- package/authentication/client/http-client.middleware.js +2 -2
- package/authentication/models/authentication-credentials.model.d.ts +2 -2
- package/authentication/models/authentication-credentials.model.js +5 -3
- package/authentication/models/authentication-session.model.d.ts +2 -2
- package/authentication/models/authentication-session.model.js +5 -3
- package/authentication/models/index.d.ts +4 -0
- package/authentication/models/index.js +4 -0
- package/authentication/models/service-account.model.d.ts +7 -0
- package/authentication/models/service-account.model.js +31 -0
- package/authentication/models/subject.model.d.ts +16 -0
- package/authentication/models/subject.model.js +59 -0
- package/authentication/models/system-account.model.d.ts +5 -0
- package/authentication/models/system-account.model.js +25 -0
- package/authentication/models/user.model.d.ts +15 -0
- package/authentication/models/user.model.js +47 -0
- package/authentication/server/drizzle/0001_condemned_pretty_boy.sql +70 -0
- package/authentication/server/drizzle/meta/0001_snapshot.json +651 -0
- package/authentication/server/drizzle/meta/_journal.json +7 -0
- package/authentication/server/index.d.ts +1 -0
- package/authentication/server/index.js +1 -0
- package/authentication/server/schemas.d.ts +16 -1
- package/authentication/server/schemas.js +7 -1
- package/authentication/server/subject.service.d.ts +6 -0
- package/authentication/server/subject.service.js +44 -0
- package/circuit-breaker/circuit-breaker.d.ts +32 -0
- package/circuit-breaker/circuit-breaker.js +9 -0
- package/circuit-breaker/index.d.ts +2 -0
- package/circuit-breaker/index.js +2 -0
- package/circuit-breaker/postgres/circuit-breaker.d.ts +7 -0
- package/circuit-breaker/postgres/circuit-breaker.js +78 -0
- package/circuit-breaker/postgres/drizzle/0000_hard_shocker.sql +9 -0
- package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +82 -0
- package/circuit-breaker/postgres/drizzle/meta/_journal.json +13 -0
- package/circuit-breaker/postgres/drizzle.config.d.ts +2 -0
- package/circuit-breaker/postgres/drizzle.config.js +11 -0
- package/circuit-breaker/postgres/index.d.ts +5 -0
- package/circuit-breaker/postgres/index.js +5 -0
- package/circuit-breaker/postgres/model.d.ts +9 -0
- package/circuit-breaker/postgres/model.js +40 -0
- package/circuit-breaker/postgres/module.d.ts +6 -0
- package/circuit-breaker/postgres/module.js +25 -0
- package/circuit-breaker/postgres/provider.d.ts +6 -0
- package/circuit-breaker/postgres/provider.js +21 -0
- package/circuit-breaker/postgres/schemas.d.ts +8 -0
- package/circuit-breaker/postgres/schemas.js +6 -0
- package/circuit-breaker/provider.d.ts +4 -0
- package/circuit-breaker/provider.js +2 -0
- package/circuit-breaker/tests/circuit-breaker.test.js +113 -0
- package/document-management/models/document.model.d.ts +0 -1
- package/document-management/models/document.model.js +0 -5
- package/document-management/server/api/document-management.api.js +1 -2
- package/document-management/server/drizzle/0002_round_warbird.sql +1 -0
- package/document-management/server/drizzle/meta/0002_snapshot.json +2722 -0
- package/document-management/server/drizzle/meta/_journal.json +7 -0
- package/document-management/server/services/document-collection.service.js +3 -3
- package/document-management/server/services/document-management-ancillary.service.d.ts +1 -1
- package/document-management/server/services/document-management.service.js +1 -1
- package/document-management/server/services/document-workflow.service.js +5 -5
- package/document-management/server/services/document.service.d.ts +0 -2
- package/document-management/server/services/document.service.js +1 -2
- package/document-management/service-models/enriched/enriched-document.view.d.ts +1 -1
- package/examples/document-management/main.d.ts +1 -1
- package/examples/document-management/main.js +1 -1
- package/logger/transports/console.d.ts +1 -1
- package/logger/transports/console.js +4 -1
- package/message-bus/message-bus-base.js +1 -1
- package/package.json +8 -5
- package/queue/enqueue-batch.d.ts +11 -11
- package/queue/enqueue-batch.js +2 -3
- package/queue/index.d.ts +1 -0
- package/queue/index.js +1 -0
- package/queue/postgres/drizzle/0003_tricky_venom.sql +30 -0
- package/queue/postgres/drizzle/meta/0003_snapshot.json +288 -0
- package/queue/postgres/drizzle/meta/_journal.json +7 -0
- package/queue/postgres/drizzle.config.js +2 -2
- package/queue/postgres/index.d.ts +1 -1
- package/queue/postgres/index.js +1 -1
- package/queue/postgres/module.d.ts +1 -1
- package/queue/postgres/module.js +1 -1
- package/queue/postgres/queue.d.ts +52 -23
- package/queue/postgres/queue.js +582 -64
- package/queue/postgres/queue.provider.d.ts +1 -1
- package/queue/postgres/schemas.d.ts +13 -2
- package/queue/postgres/schemas.js +4 -2
- package/queue/postgres/task.model.d.ts +24 -0
- package/queue/postgres/task.model.js +115 -0
- package/queue/provider.d.ts +1 -1
- package/queue/queue.d.ts +158 -37
- package/queue/queue.js +97 -19
- package/queue/task-context.d.ts +38 -0
- package/queue/task-context.js +102 -0
- package/queue/tests/queue.test.d.ts +1 -0
- package/queue/tests/queue.test.js +623 -0
- package/test4.d.ts +1 -1
- package/test4.js +1 -1
- package/utils/format-error.d.ts +17 -20
- package/utils/format-error.js +105 -47
- package/queue/postgres/job.model.d.ts +0 -12
- package/queue/postgres/job.model.js +0 -53
- package/test6.js +0 -33
- /package/{test6.d.ts → circuit-breaker/tests/circuit-breaker.test.d.ts} +0 -0
package/utils/format-error.d.ts
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
import type { UndefinableJson } from '../types/index.js';
|
|
1
|
+
import type { Record, UndefinableJson } from '../types/index.js';
|
|
2
2
|
export type FormatErrorOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* Include error name in message
|
|
5
|
-
*/
|
|
3
|
+
/** Include error name in message */
|
|
6
4
|
includeName?: boolean;
|
|
7
|
-
/**
|
|
8
|
-
* Include all error properties beside name and message
|
|
9
|
-
*/
|
|
5
|
+
/** Include all error properties beside name and message */
|
|
10
6
|
includeRest?: boolean | 'if-no-extra-info';
|
|
11
|
-
/**
|
|
12
|
-
* Include extraInfo from errors implementing {@link ErrorExtraInfo}
|
|
13
|
-
*/
|
|
7
|
+
/** Include extraInfo from errors implementing {@link ErrorExtraInfo} */
|
|
14
8
|
includeExtraInfo?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Include stack trace
|
|
17
|
-
*/
|
|
9
|
+
/** Include stack trace */
|
|
18
10
|
includeStack?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Maximum recursion depth for nested causes and aggregate errors (default: 5)
|
|
21
|
-
*/
|
|
11
|
+
/** Maximum recursion depth for nested causes and aggregate errors (default: 5) */
|
|
22
12
|
depth?: number;
|
|
23
13
|
};
|
|
14
|
+
export type SerializedError = {
|
|
15
|
+
name?: string;
|
|
16
|
+
message: string;
|
|
17
|
+
rest?: Record;
|
|
18
|
+
extraInfo?: UndefinableJson;
|
|
19
|
+
stack?: string;
|
|
20
|
+
cause?: SerializedError;
|
|
21
|
+
aggregateErrors?: SerializedError[];
|
|
22
|
+
};
|
|
24
23
|
export interface ErrorExtraInfo {
|
|
25
24
|
/** Format extra data (without message and stack) as JSON */
|
|
26
25
|
getExtraInfo(): UndefinableJson | undefined;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*/
|
|
31
|
-
export declare function formatError(error: any, options?: FormatErrorOptions): string;
|
|
27
|
+
export declare function serializeError(error: unknown, options?: FormatErrorOptions): SerializedError;
|
|
28
|
+
export declare function formatError(error: unknown, options?: FormatErrorOptions): string;
|
package/utils/format-error.js
CHANGED
|
@@ -2,76 +2,134 @@ import { unwrapError } from '../errors/utils.js';
|
|
|
2
2
|
import { decycle } from './object/decycle.js';
|
|
3
3
|
import { objectKeys } from './object/object.js';
|
|
4
4
|
import { tryChain } from './try-chain.js';
|
|
5
|
-
import { isArray, isDefined, isFunction, isObject, isUndefined } from './type-guards.js';
|
|
6
|
-
|
|
7
|
-
* Enhanced error formatting
|
|
8
|
-
*/
|
|
9
|
-
export function formatError(error, options = {}) {
|
|
5
|
+
import { isArray, isDefined, isFunction, isObject, isString, isUndefined } from './type-guards.js';
|
|
6
|
+
export function serializeError(error, options = {}) {
|
|
10
7
|
const { includeName = true, includeRest = 'if-no-extra-info', includeExtraInfo = true, includeStack = true, depth = 5, } = options;
|
|
11
8
|
if (depth <= 0) {
|
|
12
|
-
return '[Max recursion depth reached]';
|
|
9
|
+
return { message: '[Max recursion depth reached]' };
|
|
13
10
|
}
|
|
14
11
|
const actualError = unwrapError(error);
|
|
12
|
+
// 1. Initial Property Extraction
|
|
15
13
|
let name;
|
|
16
14
|
let message;
|
|
17
15
|
let stack;
|
|
18
|
-
let rest;
|
|
19
|
-
let extraInfo;
|
|
20
16
|
let cause;
|
|
21
17
|
let aggregateErrors;
|
|
18
|
+
let extraInfo;
|
|
19
|
+
let rest;
|
|
20
|
+
// Track if we treat this as a raw object (affects default name logic)
|
|
21
|
+
let isRawObjectFallback = false;
|
|
22
22
|
if (isObject(actualError)) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const errObj = actualError;
|
|
24
|
+
// Extract standard properties
|
|
25
|
+
name = isString(errObj.name) ? errObj.name : undefined;
|
|
26
|
+
message = isString(errObj.message) ? errObj.message : undefined;
|
|
27
|
+
stack = isString(errObj.stack) ? errObj.stack : undefined;
|
|
28
|
+
cause = errObj.cause;
|
|
29
|
+
if (actualError instanceof AggregateError) {
|
|
30
|
+
aggregateErrors = actualError.errors;
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
({ name, message, stack, cause, ...rest } = actualError);
|
|
32
|
-
}
|
|
33
|
-
// Check for extra info (duck-typing)
|
|
34
|
-
if (includeExtraInfo && isFunction(actualError.getExtraInfo)) { // eslint-disable-line @typescript-eslint/unbound-method
|
|
32
|
+
// Extract Extra Info
|
|
33
|
+
if (includeExtraInfo && isFunction(actualError.getExtraInfo)) {
|
|
35
34
|
extraInfo = actualError.getExtraInfo();
|
|
36
35
|
}
|
|
36
|
+
// Isolate 'rest' properties via destructuring
|
|
37
|
+
const { name: _n, message: _m, stack: _s, cause: _c, errors: _agg, ...restObj } = errObj;
|
|
38
|
+
rest = restObj;
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
else {
|
|
41
|
+
// Primitive types (string, number, etc.)
|
|
42
|
+
message = String(actualError);
|
|
43
|
+
}
|
|
44
|
+
// 2. Message Normalization & Fallback Logic
|
|
45
|
+
const hasEmptyMessage = isUndefined(message) || (String(message).trim().length == 0);
|
|
46
|
+
if (hasEmptyMessage) {
|
|
47
|
+
if (actualError instanceof Error) {
|
|
48
|
+
// Standard Error with empty message: keep name, keep rest, ensure message is string
|
|
49
|
+
message = '';
|
|
43
50
|
}
|
|
44
|
-
else {
|
|
51
|
+
else if (isObject(actualError)) {
|
|
52
|
+
// Plain Object (e.g. { code: 500 }): Serialize entire object into message
|
|
45
53
|
message = tryChain([
|
|
46
|
-
() => JSON.stringify(actualError, null, 2),
|
|
47
|
-
() =>
|
|
48
|
-
// Fallback with decycle for objects with circular references
|
|
49
|
-
const decycledError = decycle(actualError);
|
|
50
|
-
return JSON.stringify(decycledError, null, 2);
|
|
51
|
-
},
|
|
54
|
+
() => JSON.stringify(actualError, null, 2),
|
|
55
|
+
() => JSON.stringify(decycle(actualError), null, 2),
|
|
52
56
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
53
|
-
() => `[Unstringifiable object: ${String(actualError)}]`,
|
|
57
|
+
() => `[Unstringifiable object: ${String(actualError)}]`,
|
|
54
58
|
]);
|
|
59
|
+
// Clear rest to avoid duplication since the whole object is now the message
|
|
60
|
+
rest = undefined;
|
|
61
|
+
// Flag as fallback to prevent defaulting name to "Error"
|
|
62
|
+
isRawObjectFallback = true;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Fallback for weird primitive edge cases (should be covered by initial String() conversion)
|
|
66
|
+
message = String(actualError);
|
|
55
67
|
}
|
|
56
68
|
}
|
|
57
|
-
//
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
// 3. Finalize Optional Properties
|
|
70
|
+
const shouldIncludeRest = includeRest === true || (includeRest === 'if-no-extra-info' && isUndefined(extraInfo));
|
|
71
|
+
const hasRest = isDefined(rest) && objectKeys(rest).length > 0;
|
|
72
|
+
// Determine Final Name
|
|
73
|
+
// If fallback (raw object) and no name exists, return undefined. Otherwise default to 'Error'.
|
|
74
|
+
const defaultName = isRawObjectFallback ? undefined : 'Error';
|
|
75
|
+
const finalName = includeName ? (name ?? defaultName) : undefined;
|
|
76
|
+
const nextOptions = { ...options, depth: depth - 1 };
|
|
77
|
+
return {
|
|
78
|
+
name: finalName,
|
|
79
|
+
message: message ?? '',
|
|
80
|
+
extraInfo: isDefined(extraInfo) ? extraInfo : undefined,
|
|
81
|
+
rest: shouldIncludeRest && hasRest ? decycle(rest) : undefined,
|
|
82
|
+
stack: (includeStack && isDefined(stack)) ? stack : undefined,
|
|
83
|
+
cause: (includeStack && cause)
|
|
84
|
+
? serializeError(cause, nextOptions)
|
|
85
|
+
: undefined,
|
|
86
|
+
aggregateErrors: (isArray(aggregateErrors))
|
|
87
|
+
? aggregateErrors.map((err) => serializeError(err, nextOptions))
|
|
88
|
+
: undefined,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export function formatError(error, options = {}) {
|
|
92
|
+
const serialized = serializeError(error, options);
|
|
93
|
+
return formatSerializedError(serialized, options);
|
|
94
|
+
}
|
|
95
|
+
function formatSerializedError(serialized, options) {
|
|
96
|
+
const { name, message, rest, extraInfo, stack, cause, aggregateErrors, } = serialized;
|
|
97
|
+
const { includeName = true, includeStack = true, depth = 5 } = options;
|
|
98
|
+
// 1. Header (Name: Message)
|
|
99
|
+
const prefix = includeName && name ? `${name}: ` : '';
|
|
100
|
+
const header = `${prefix}${message}`;
|
|
101
|
+
// 2. Body (Rest / Extra Info)
|
|
102
|
+
let body = '';
|
|
103
|
+
if (rest) {
|
|
104
|
+
body += `\n${JSON.stringify(rest, null, 2)}`;
|
|
105
|
+
}
|
|
106
|
+
if (extraInfo) {
|
|
107
|
+
body += `\n${JSON.stringify(extraInfo, null, 2)}`;
|
|
108
|
+
}
|
|
109
|
+
// 3. Stack Trace
|
|
110
|
+
let stackString = '';
|
|
111
|
+
if (includeStack && stack) {
|
|
112
|
+
// Deduplicate header if stack already starts with it (standard Node.js behavior)
|
|
113
|
+
if (stack.startsWith(header)) {
|
|
114
|
+
stackString = stack.slice(header.length);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
stackString = `\n${stack}`;
|
|
118
|
+
}
|
|
63
119
|
}
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const causeString = includeStack && cause
|
|
67
|
-
? formatNestedError('Caused by:', cause,
|
|
120
|
+
// 4. Recursion (Causes and Aggregate Errors)
|
|
121
|
+
const nextOptions = { ...options, depth: depth - 1 };
|
|
122
|
+
const causeString = (includeStack && cause)
|
|
123
|
+
? formatNestedError('Caused by:', cause, nextOptions)
|
|
68
124
|
: '';
|
|
69
|
-
const aggregateErrorsString =
|
|
70
|
-
? aggregateErrors
|
|
125
|
+
const aggregateErrorsString = aggregateErrors
|
|
126
|
+
? aggregateErrors
|
|
127
|
+
.map((err, i) => formatNestedError(`Sub-error #${i + 1}:`, err, nextOptions))
|
|
128
|
+
.join('')
|
|
71
129
|
: '';
|
|
72
|
-
return `${
|
|
130
|
+
return `${header}${body}${stackString}${causeString}${aggregateErrorsString}`;
|
|
73
131
|
}
|
|
74
|
-
function formatNestedError(prefix,
|
|
75
|
-
const formatted =
|
|
132
|
+
function formatNestedError(prefix, serializedError, options) {
|
|
133
|
+
const formatted = formatSerializedError(serializedError, options).replace(/\n/g, '\n ');
|
|
76
134
|
return `\n\n${prefix}\n ${formatted}`;
|
|
77
135
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BaseEntity, type Json, type Timestamp } from '../../orm/index.js';
|
|
2
|
-
import type { ObjectLiteral } from '../../types/index.js';
|
|
3
|
-
import type { Job } from '../queue.js';
|
|
4
|
-
export declare class PostgresJob<T extends ObjectLiteral = ObjectLiteral> extends BaseEntity implements Job<T> {
|
|
5
|
-
queue: string;
|
|
6
|
-
tag: string | null;
|
|
7
|
-
priority: number;
|
|
8
|
-
enqueueTimestamp: Timestamp;
|
|
9
|
-
tries: number;
|
|
10
|
-
lastDequeueTimestamp: Timestamp | null;
|
|
11
|
-
data: Json<T>;
|
|
12
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { BaseEntity, JsonProperty, Table, TimestampProperty, Unique } from '../../orm/index.js';
|
|
11
|
-
import { Integer, StringProperty } from '../../schema/index.js';
|
|
12
|
-
let PostgresJob = class PostgresJob extends BaseEntity {
|
|
13
|
-
queue;
|
|
14
|
-
tag;
|
|
15
|
-
priority;
|
|
16
|
-
enqueueTimestamp;
|
|
17
|
-
tries;
|
|
18
|
-
lastDequeueTimestamp;
|
|
19
|
-
data;
|
|
20
|
-
};
|
|
21
|
-
__decorate([
|
|
22
|
-
StringProperty(),
|
|
23
|
-
__metadata("design:type", String)
|
|
24
|
-
], PostgresJob.prototype, "queue", void 0);
|
|
25
|
-
__decorate([
|
|
26
|
-
StringProperty({ nullable: true }),
|
|
27
|
-
__metadata("design:type", Object)
|
|
28
|
-
], PostgresJob.prototype, "tag", void 0);
|
|
29
|
-
__decorate([
|
|
30
|
-
Integer(),
|
|
31
|
-
__metadata("design:type", Number)
|
|
32
|
-
], PostgresJob.prototype, "priority", void 0);
|
|
33
|
-
__decorate([
|
|
34
|
-
TimestampProperty(),
|
|
35
|
-
__metadata("design:type", Number)
|
|
36
|
-
], PostgresJob.prototype, "enqueueTimestamp", void 0);
|
|
37
|
-
__decorate([
|
|
38
|
-
Integer(),
|
|
39
|
-
__metadata("design:type", Number)
|
|
40
|
-
], PostgresJob.prototype, "tries", void 0);
|
|
41
|
-
__decorate([
|
|
42
|
-
TimestampProperty({ nullable: true }),
|
|
43
|
-
__metadata("design:type", Object)
|
|
44
|
-
], PostgresJob.prototype, "lastDequeueTimestamp", void 0);
|
|
45
|
-
__decorate([
|
|
46
|
-
JsonProperty(),
|
|
47
|
-
__metadata("design:type", Object)
|
|
48
|
-
], PostgresJob.prototype, "data", void 0);
|
|
49
|
-
PostgresJob = __decorate([
|
|
50
|
-
Table('job', { schema: 'queue' }),
|
|
51
|
-
Unique(['queue', 'tag'])
|
|
52
|
-
], PostgresJob);
|
|
53
|
-
export { PostgresJob };
|
package/test6.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { benchmark } from './utils/benchmark.js';
|
|
2
|
-
import { isDefined } from './utils/type-guards.js';
|
|
3
|
-
const numberFormatterMap = new Map();
|
|
4
|
-
function getNumberFormatter1(locale, options) {
|
|
5
|
-
const key = JSON.stringify({ locale, ...options });
|
|
6
|
-
const existing = numberFormatterMap.get(key);
|
|
7
|
-
if (isDefined(existing)) {
|
|
8
|
-
return existing;
|
|
9
|
-
}
|
|
10
|
-
const formatter = new Intl.NumberFormat(locale, options);
|
|
11
|
-
numberFormatterMap.set(key, formatter);
|
|
12
|
-
return formatter;
|
|
13
|
-
}
|
|
14
|
-
function getNumberFormatter2(locale, options) {
|
|
15
|
-
const key = JSON.stringify({ locale, options });
|
|
16
|
-
const existing = numberFormatterMap.get(key);
|
|
17
|
-
if (isDefined(existing)) {
|
|
18
|
-
return existing;
|
|
19
|
-
}
|
|
20
|
-
const formatter = new Intl.NumberFormat(locale, options);
|
|
21
|
-
numberFormatterMap.set(key, formatter);
|
|
22
|
-
return formatter;
|
|
23
|
-
}
|
|
24
|
-
function format1(value, locale, format) {
|
|
25
|
-
return getNumberFormatter1(locale, format).format(value);
|
|
26
|
-
}
|
|
27
|
-
function format2(value, locale, format) {
|
|
28
|
-
return getNumberFormatter2(locale, format).format(value);
|
|
29
|
-
}
|
|
30
|
-
const result1 = benchmark(200000, (run) => format1(run, 'en-US', { maximumFractionDigits: 2 }));
|
|
31
|
-
const result2 = benchmark(200000, (run) => format2(run, 'en-US', { maximumFractionDigits: 2 }));
|
|
32
|
-
console.log(`format: ${result1.operationsPerMillisecond.toFixed(2)} ops/ms`);
|
|
33
|
-
console.log(`formatCached: ${result2.operationsPerMillisecond.toFixed(2)} ops/ms`);
|
|
File without changes
|