@formatjs/ecma402-abstract 1.18.3 → 2.1.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/NumberFormat/format_to_parts.js +4 -1
- package/index.d.ts +8 -8
- package/index.js +15 -9
- package/lib/NumberFormat/format_to_parts.js +4 -1
- package/lib/index.d.ts +8 -8
- package/lib/index.js +7 -7
- package/lib/types/number.d.ts +1 -0
- package/lib/utils.d.ts +12 -0
- package/lib/utils.js +66 -0
- package/package.json +2 -1
- package/types/number.d.ts +1 -0
- package/utils.d.ts +12 -0
- package/utils.js +68 -1
|
@@ -343,7 +343,10 @@ decimalNumberPattern, style) {
|
|
|
343
343
|
}
|
|
344
344
|
// #endregion
|
|
345
345
|
if (fraction !== undefined) {
|
|
346
|
-
|
|
346
|
+
var decimalSepSymbol = style === 'currency' && symbols.currencyDecimal != null
|
|
347
|
+
? symbols.currencyDecimal
|
|
348
|
+
: symbols.decimal;
|
|
349
|
+
result.push({ type: 'decimal', value: decimalSepSymbol }, { type: 'fraction', value: fraction });
|
|
347
350
|
}
|
|
348
351
|
if ((notation === 'scientific' || notation === 'engineering') &&
|
|
349
352
|
isFinite(x)) {
|
package/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './NumberFormat/CollapseNumberRange';
|
|
|
14
14
|
export * from './NumberFormat/ComputeExponent';
|
|
15
15
|
export * from './NumberFormat/ComputeExponentForMagnitude';
|
|
16
16
|
export * from './NumberFormat/CurrencyDigits';
|
|
17
|
+
export { default as _formatToParts } from './NumberFormat/format_to_parts';
|
|
17
18
|
export * from './NumberFormat/FormatApproximately';
|
|
18
19
|
export * from './NumberFormat/FormatNumericRange';
|
|
19
20
|
export * from './NumberFormat/FormatNumericRangeToParts';
|
|
@@ -27,18 +28,17 @@ export * from './NumberFormat/SetNumberFormatDigitOptions';
|
|
|
27
28
|
export * from './NumberFormat/SetNumberFormatUnitOptions';
|
|
28
29
|
export * from './NumberFormat/ToRawFixed';
|
|
29
30
|
export * from './NumberFormat/ToRawPrecision';
|
|
30
|
-
export { default as _formatToParts } from './NumberFormat/format_to_parts';
|
|
31
31
|
export * from './PartitionPattern';
|
|
32
32
|
export * from './SupportedLocales';
|
|
33
|
-
export { getInternalSlot, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots,
|
|
33
|
+
export { createDataProperty, defineProperty, getInternalSlot, getMagnitude, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
|
|
34
34
|
export type { LiteralPart } from './utils';
|
|
35
|
+
export * from './262';
|
|
35
36
|
export { isMissingLocaleDataError } from './data';
|
|
36
|
-
export
|
|
37
|
+
export type { LocaleData } from './types/core';
|
|
37
38
|
export * from './types/date-time';
|
|
39
|
+
export * from './types/displaynames';
|
|
38
40
|
export * from './types/list';
|
|
39
|
-
export * from './types/plural-rules';
|
|
40
41
|
export * from './types/number';
|
|
41
|
-
export * from './types/
|
|
42
|
-
export
|
|
43
|
-
export
|
|
44
|
-
export * from './262';
|
|
42
|
+
export * from './types/plural-rules';
|
|
43
|
+
export * from './types/relative-time';
|
|
44
|
+
export { createMemoizedDateTimeFormat, createMemoizedListFormat, createMemoizedLocale, createMemoizedNumberFormat, createMemoizedPluralRules, invariant, } from './utils';
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.invariant = exports.
|
|
3
|
+
exports.invariant = exports.createMemoizedPluralRules = exports.createMemoizedNumberFormat = exports.createMemoizedLocale = exports.createMemoizedListFormat = exports.createMemoizedDateTimeFormat = exports.isMissingLocaleDataError = exports.setMultiInternalSlots = exports.setInternalSlot = exports.isLiteralPart = exports.getMultiInternalSlots = exports.getMagnitude = exports.getInternalSlot = exports.defineProperty = exports.createDataProperty = exports._formatToParts = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./CanonicalizeLocaleList"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./CanonicalizeTimeZoneName"), exports);
|
|
@@ -18,6 +18,8 @@ tslib_1.__exportStar(require("./NumberFormat/CollapseNumberRange"), exports);
|
|
|
18
18
|
tslib_1.__exportStar(require("./NumberFormat/ComputeExponent"), exports);
|
|
19
19
|
tslib_1.__exportStar(require("./NumberFormat/ComputeExponentForMagnitude"), exports);
|
|
20
20
|
tslib_1.__exportStar(require("./NumberFormat/CurrencyDigits"), exports);
|
|
21
|
+
var format_to_parts_1 = require("./NumberFormat/format_to_parts");
|
|
22
|
+
Object.defineProperty(exports, "_formatToParts", { enumerable: true, get: function () { return tslib_1.__importDefault(format_to_parts_1).default; } });
|
|
21
23
|
tslib_1.__exportStar(require("./NumberFormat/FormatApproximately"), exports);
|
|
22
24
|
tslib_1.__exportStar(require("./NumberFormat/FormatNumericRange"), exports);
|
|
23
25
|
tslib_1.__exportStar(require("./NumberFormat/FormatNumericRangeToParts"), exports);
|
|
@@ -31,26 +33,30 @@ tslib_1.__exportStar(require("./NumberFormat/SetNumberFormatDigitOptions"), expo
|
|
|
31
33
|
tslib_1.__exportStar(require("./NumberFormat/SetNumberFormatUnitOptions"), exports);
|
|
32
34
|
tslib_1.__exportStar(require("./NumberFormat/ToRawFixed"), exports);
|
|
33
35
|
tslib_1.__exportStar(require("./NumberFormat/ToRawPrecision"), exports);
|
|
34
|
-
var format_to_parts_1 = require("./NumberFormat/format_to_parts");
|
|
35
|
-
Object.defineProperty(exports, "_formatToParts", { enumerable: true, get: function () { return tslib_1.__importDefault(format_to_parts_1).default; } });
|
|
36
36
|
tslib_1.__exportStar(require("./PartitionPattern"), exports);
|
|
37
37
|
tslib_1.__exportStar(require("./SupportedLocales"), exports);
|
|
38
38
|
var utils_1 = require("./utils");
|
|
39
|
+
Object.defineProperty(exports, "createDataProperty", { enumerable: true, get: function () { return utils_1.createDataProperty; } });
|
|
40
|
+
Object.defineProperty(exports, "defineProperty", { enumerable: true, get: function () { return utils_1.defineProperty; } });
|
|
39
41
|
Object.defineProperty(exports, "getInternalSlot", { enumerable: true, get: function () { return utils_1.getInternalSlot; } });
|
|
42
|
+
Object.defineProperty(exports, "getMagnitude", { enumerable: true, get: function () { return utils_1.getMagnitude; } });
|
|
40
43
|
Object.defineProperty(exports, "getMultiInternalSlots", { enumerable: true, get: function () { return utils_1.getMultiInternalSlots; } });
|
|
41
44
|
Object.defineProperty(exports, "isLiteralPart", { enumerable: true, get: function () { return utils_1.isLiteralPart; } });
|
|
42
45
|
Object.defineProperty(exports, "setInternalSlot", { enumerable: true, get: function () { return utils_1.setInternalSlot; } });
|
|
43
46
|
Object.defineProperty(exports, "setMultiInternalSlots", { enumerable: true, get: function () { return utils_1.setMultiInternalSlots; } });
|
|
44
|
-
|
|
45
|
-
Object.defineProperty(exports, "defineProperty", { enumerable: true, get: function () { return utils_1.defineProperty; } });
|
|
47
|
+
tslib_1.__exportStar(require("./262"), exports);
|
|
46
48
|
var data_1 = require("./data");
|
|
47
49
|
Object.defineProperty(exports, "isMissingLocaleDataError", { enumerable: true, get: function () { return data_1.isMissingLocaleDataError; } });
|
|
48
|
-
tslib_1.__exportStar(require("./types/relative-time"), exports);
|
|
49
50
|
tslib_1.__exportStar(require("./types/date-time"), exports);
|
|
51
|
+
tslib_1.__exportStar(require("./types/displaynames"), exports);
|
|
50
52
|
tslib_1.__exportStar(require("./types/list"), exports);
|
|
51
|
-
tslib_1.__exportStar(require("./types/plural-rules"), exports);
|
|
52
53
|
tslib_1.__exportStar(require("./types/number"), exports);
|
|
53
|
-
tslib_1.__exportStar(require("./types/
|
|
54
|
+
tslib_1.__exportStar(require("./types/plural-rules"), exports);
|
|
55
|
+
tslib_1.__exportStar(require("./types/relative-time"), exports);
|
|
54
56
|
var utils_2 = require("./utils");
|
|
57
|
+
Object.defineProperty(exports, "createMemoizedDateTimeFormat", { enumerable: true, get: function () { return utils_2.createMemoizedDateTimeFormat; } });
|
|
58
|
+
Object.defineProperty(exports, "createMemoizedListFormat", { enumerable: true, get: function () { return utils_2.createMemoizedListFormat; } });
|
|
59
|
+
Object.defineProperty(exports, "createMemoizedLocale", { enumerable: true, get: function () { return utils_2.createMemoizedLocale; } });
|
|
60
|
+
Object.defineProperty(exports, "createMemoizedNumberFormat", { enumerable: true, get: function () { return utils_2.createMemoizedNumberFormat; } });
|
|
61
|
+
Object.defineProperty(exports, "createMemoizedPluralRules", { enumerable: true, get: function () { return utils_2.createMemoizedPluralRules; } });
|
|
55
62
|
Object.defineProperty(exports, "invariant", { enumerable: true, get: function () { return utils_2.invariant; } });
|
|
56
|
-
tslib_1.__exportStar(require("./262"), exports);
|
|
@@ -340,7 +340,10 @@ decimalNumberPattern, style) {
|
|
|
340
340
|
}
|
|
341
341
|
// #endregion
|
|
342
342
|
if (fraction !== undefined) {
|
|
343
|
-
|
|
343
|
+
var decimalSepSymbol = style === 'currency' && symbols.currencyDecimal != null
|
|
344
|
+
? symbols.currencyDecimal
|
|
345
|
+
: symbols.decimal;
|
|
346
|
+
result.push({ type: 'decimal', value: decimalSepSymbol }, { type: 'fraction', value: fraction });
|
|
344
347
|
}
|
|
345
348
|
if ((notation === 'scientific' || notation === 'engineering') &&
|
|
346
349
|
isFinite(x)) {
|
package/lib/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './NumberFormat/CollapseNumberRange';
|
|
|
14
14
|
export * from './NumberFormat/ComputeExponent';
|
|
15
15
|
export * from './NumberFormat/ComputeExponentForMagnitude';
|
|
16
16
|
export * from './NumberFormat/CurrencyDigits';
|
|
17
|
+
export { default as _formatToParts } from './NumberFormat/format_to_parts';
|
|
17
18
|
export * from './NumberFormat/FormatApproximately';
|
|
18
19
|
export * from './NumberFormat/FormatNumericRange';
|
|
19
20
|
export * from './NumberFormat/FormatNumericRangeToParts';
|
|
@@ -27,18 +28,17 @@ export * from './NumberFormat/SetNumberFormatDigitOptions';
|
|
|
27
28
|
export * from './NumberFormat/SetNumberFormatUnitOptions';
|
|
28
29
|
export * from './NumberFormat/ToRawFixed';
|
|
29
30
|
export * from './NumberFormat/ToRawPrecision';
|
|
30
|
-
export { default as _formatToParts } from './NumberFormat/format_to_parts';
|
|
31
31
|
export * from './PartitionPattern';
|
|
32
32
|
export * from './SupportedLocales';
|
|
33
|
-
export { getInternalSlot, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots,
|
|
33
|
+
export { createDataProperty, defineProperty, getInternalSlot, getMagnitude, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
|
|
34
34
|
export type { LiteralPart } from './utils';
|
|
35
|
+
export * from './262';
|
|
35
36
|
export { isMissingLocaleDataError } from './data';
|
|
36
|
-
export
|
|
37
|
+
export type { LocaleData } from './types/core';
|
|
37
38
|
export * from './types/date-time';
|
|
39
|
+
export * from './types/displaynames';
|
|
38
40
|
export * from './types/list';
|
|
39
|
-
export * from './types/plural-rules';
|
|
40
41
|
export * from './types/number';
|
|
41
|
-
export * from './types/
|
|
42
|
-
export
|
|
43
|
-
export
|
|
44
|
-
export * from './262';
|
|
42
|
+
export * from './types/plural-rules';
|
|
43
|
+
export * from './types/relative-time';
|
|
44
|
+
export { createMemoizedDateTimeFormat, createMemoizedListFormat, createMemoizedLocale, createMemoizedNumberFormat, createMemoizedPluralRules, invariant, } from './utils';
|
package/lib/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export * from './NumberFormat/CollapseNumberRange';
|
|
|
14
14
|
export * from './NumberFormat/ComputeExponent';
|
|
15
15
|
export * from './NumberFormat/ComputeExponentForMagnitude';
|
|
16
16
|
export * from './NumberFormat/CurrencyDigits';
|
|
17
|
+
export { default as _formatToParts } from './NumberFormat/format_to_parts';
|
|
17
18
|
export * from './NumberFormat/FormatApproximately';
|
|
18
19
|
export * from './NumberFormat/FormatNumericRange';
|
|
19
20
|
export * from './NumberFormat/FormatNumericRangeToParts';
|
|
@@ -27,16 +28,15 @@ export * from './NumberFormat/SetNumberFormatDigitOptions';
|
|
|
27
28
|
export * from './NumberFormat/SetNumberFormatUnitOptions';
|
|
28
29
|
export * from './NumberFormat/ToRawFixed';
|
|
29
30
|
export * from './NumberFormat/ToRawPrecision';
|
|
30
|
-
export { default as _formatToParts } from './NumberFormat/format_to_parts';
|
|
31
31
|
export * from './PartitionPattern';
|
|
32
32
|
export * from './SupportedLocales';
|
|
33
|
-
export { getInternalSlot, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots,
|
|
33
|
+
export { createDataProperty, defineProperty, getInternalSlot, getMagnitude, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
|
|
34
|
+
export * from './262';
|
|
34
35
|
export { isMissingLocaleDataError } from './data';
|
|
35
|
-
export * from './types/relative-time';
|
|
36
36
|
export * from './types/date-time';
|
|
37
|
+
export * from './types/displaynames';
|
|
37
38
|
export * from './types/list';
|
|
38
|
-
export * from './types/plural-rules';
|
|
39
39
|
export * from './types/number';
|
|
40
|
-
export * from './types/
|
|
41
|
-
export
|
|
42
|
-
export
|
|
40
|
+
export * from './types/plural-rules';
|
|
41
|
+
export * from './types/relative-time';
|
|
42
|
+
export { createMemoizedDateTimeFormat, createMemoizedListFormat, createMemoizedLocale, createMemoizedNumberFormat, createMemoizedPluralRules, invariant, } from './utils';
|
package/lib/types/number.d.ts
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -19,5 +19,17 @@ export declare function isLiteralPart(patternPart: LiteralPart | {
|
|
|
19
19
|
export declare function defineProperty<T extends object>(target: T, name: string | symbol, { value }: {
|
|
20
20
|
value: any;
|
|
21
21
|
} & ThisType<any>): void;
|
|
22
|
+
/**
|
|
23
|
+
* 7.3.5 CreateDataProperty
|
|
24
|
+
* @param target
|
|
25
|
+
* @param name
|
|
26
|
+
* @param value
|
|
27
|
+
*/
|
|
28
|
+
export declare function createDataProperty<T extends object>(target: T, name: string | symbol, value: any): void;
|
|
22
29
|
export declare const UNICODE_EXTENSION_SEQUENCE_REGEX: RegExp;
|
|
23
30
|
export declare function invariant(condition: boolean, message: string, Err?: any): asserts condition;
|
|
31
|
+
export declare const createMemoizedNumberFormat: (...args: ConstructorParameters<typeof Intl.NumberFormat>) => Intl.NumberFormat;
|
|
32
|
+
export declare const createMemoizedDateTimeFormat: (...args: ConstructorParameters<typeof Intl.DateTimeFormat>) => Intl.DateTimeFormat;
|
|
33
|
+
export declare const createMemoizedPluralRules: (...args: ConstructorParameters<typeof Intl.PluralRules>) => Intl.PluralRules;
|
|
34
|
+
export declare const createMemoizedLocale: (...args: ConstructorParameters<typeof Intl.Locale>) => Intl.Locale;
|
|
35
|
+
export declare const createMemoizedListFormat: (...args: ConstructorParameters<typeof Intl.ListFormat>) => Intl.ListFormat;
|
package/lib/utils.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
|
+
import { memoize, strategies } from '@formatjs/fast-memoize';
|
|
1
3
|
/**
|
|
2
4
|
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
|
|
3
5
|
* @param x number
|
|
@@ -69,6 +71,20 @@ export function defineProperty(target, name, _a) {
|
|
|
69
71
|
value: value,
|
|
70
72
|
});
|
|
71
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* 7.3.5 CreateDataProperty
|
|
76
|
+
* @param target
|
|
77
|
+
* @param name
|
|
78
|
+
* @param value
|
|
79
|
+
*/
|
|
80
|
+
export function createDataProperty(target, name, value) {
|
|
81
|
+
Object.defineProperty(target, name, {
|
|
82
|
+
configurable: true,
|
|
83
|
+
enumerable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
value: value,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
72
88
|
export var UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi;
|
|
73
89
|
export function invariant(condition, message, Err) {
|
|
74
90
|
if (Err === void 0) { Err = Error; }
|
|
@@ -76,3 +92,53 @@ export function invariant(condition, message, Err) {
|
|
|
76
92
|
throw new Err(message);
|
|
77
93
|
}
|
|
78
94
|
}
|
|
95
|
+
export var createMemoizedNumberFormat = memoize(function () {
|
|
96
|
+
var _a;
|
|
97
|
+
var args = [];
|
|
98
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
99
|
+
args[_i] = arguments[_i];
|
|
100
|
+
}
|
|
101
|
+
return new ((_a = Intl.NumberFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
102
|
+
}, {
|
|
103
|
+
strategy: strategies.variadic,
|
|
104
|
+
});
|
|
105
|
+
export var createMemoizedDateTimeFormat = memoize(function () {
|
|
106
|
+
var _a;
|
|
107
|
+
var args = [];
|
|
108
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
109
|
+
args[_i] = arguments[_i];
|
|
110
|
+
}
|
|
111
|
+
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
112
|
+
}, {
|
|
113
|
+
strategy: strategies.variadic,
|
|
114
|
+
});
|
|
115
|
+
export var createMemoizedPluralRules = memoize(function () {
|
|
116
|
+
var _a;
|
|
117
|
+
var args = [];
|
|
118
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
119
|
+
args[_i] = arguments[_i];
|
|
120
|
+
}
|
|
121
|
+
return new ((_a = Intl.PluralRules).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
122
|
+
}, {
|
|
123
|
+
strategy: strategies.variadic,
|
|
124
|
+
});
|
|
125
|
+
export var createMemoizedLocale = memoize(function () {
|
|
126
|
+
var _a;
|
|
127
|
+
var args = [];
|
|
128
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
129
|
+
args[_i] = arguments[_i];
|
|
130
|
+
}
|
|
131
|
+
return new ((_a = Intl.Locale).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
132
|
+
}, {
|
|
133
|
+
strategy: strategies.variadic,
|
|
134
|
+
});
|
|
135
|
+
export var createMemoizedListFormat = memoize(function () {
|
|
136
|
+
var _a;
|
|
137
|
+
var args = [];
|
|
138
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
139
|
+
args[_i] = arguments[_i];
|
|
140
|
+
}
|
|
141
|
+
return new ((_a = Intl.ListFormat).bind.apply(_a, __spreadArray([void 0], args, false)))();
|
|
142
|
+
}, {
|
|
143
|
+
strategy: strategies.variadic,
|
|
144
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/ecma402-abstract",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A collection of implementation for ECMAScript abstract operations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"tslib": "^2.4.0",
|
|
18
|
+
"@formatjs/fast-memoize": "2.2.0",
|
|
18
19
|
"@formatjs/intl-localematcher": "0.5.4"
|
|
19
20
|
},
|
|
20
21
|
"author": "Long Ho <holevietlong@gmail.com",
|
package/types/number.d.ts
CHANGED
package/utils.d.ts
CHANGED
|
@@ -19,5 +19,17 @@ export declare function isLiteralPart(patternPart: LiteralPart | {
|
|
|
19
19
|
export declare function defineProperty<T extends object>(target: T, name: string | symbol, { value }: {
|
|
20
20
|
value: any;
|
|
21
21
|
} & ThisType<any>): void;
|
|
22
|
+
/**
|
|
23
|
+
* 7.3.5 CreateDataProperty
|
|
24
|
+
* @param target
|
|
25
|
+
* @param name
|
|
26
|
+
* @param value
|
|
27
|
+
*/
|
|
28
|
+
export declare function createDataProperty<T extends object>(target: T, name: string | symbol, value: any): void;
|
|
22
29
|
export declare const UNICODE_EXTENSION_SEQUENCE_REGEX: RegExp;
|
|
23
30
|
export declare function invariant(condition: boolean, message: string, Err?: any): asserts condition;
|
|
31
|
+
export declare const createMemoizedNumberFormat: (...args: ConstructorParameters<typeof Intl.NumberFormat>) => Intl.NumberFormat;
|
|
32
|
+
export declare const createMemoizedDateTimeFormat: (...args: ConstructorParameters<typeof Intl.DateTimeFormat>) => Intl.DateTimeFormat;
|
|
33
|
+
export declare const createMemoizedPluralRules: (...args: ConstructorParameters<typeof Intl.PluralRules>) => Intl.PluralRules;
|
|
34
|
+
export declare const createMemoizedLocale: (...args: ConstructorParameters<typeof Intl.Locale>) => Intl.Locale;
|
|
35
|
+
export declare const createMemoizedListFormat: (...args: ConstructorParameters<typeof Intl.ListFormat>) => Intl.ListFormat;
|
package/utils.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.invariant = exports.UNICODE_EXTENSION_SEQUENCE_REGEX = exports.defineProperty = exports.isLiteralPart = exports.getMultiInternalSlots = exports.getInternalSlot = exports.setMultiInternalSlots = exports.setInternalSlot = exports.repeat = exports.getMagnitude = void 0;
|
|
3
|
+
exports.createMemoizedListFormat = exports.createMemoizedLocale = exports.createMemoizedPluralRules = exports.createMemoizedDateTimeFormat = exports.createMemoizedNumberFormat = exports.invariant = exports.UNICODE_EXTENSION_SEQUENCE_REGEX = exports.createDataProperty = exports.defineProperty = exports.isLiteralPart = exports.getMultiInternalSlots = exports.getInternalSlot = exports.setMultiInternalSlots = exports.setInternalSlot = exports.repeat = exports.getMagnitude = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var fast_memoize_1 = require("@formatjs/fast-memoize");
|
|
4
6
|
/**
|
|
5
7
|
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
|
|
6
8
|
* @param x number
|
|
@@ -80,6 +82,21 @@ function defineProperty(target, name, _a) {
|
|
|
80
82
|
});
|
|
81
83
|
}
|
|
82
84
|
exports.defineProperty = defineProperty;
|
|
85
|
+
/**
|
|
86
|
+
* 7.3.5 CreateDataProperty
|
|
87
|
+
* @param target
|
|
88
|
+
* @param name
|
|
89
|
+
* @param value
|
|
90
|
+
*/
|
|
91
|
+
function createDataProperty(target, name, value) {
|
|
92
|
+
Object.defineProperty(target, name, {
|
|
93
|
+
configurable: true,
|
|
94
|
+
enumerable: true,
|
|
95
|
+
writable: true,
|
|
96
|
+
value: value,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
exports.createDataProperty = createDataProperty;
|
|
83
100
|
exports.UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi;
|
|
84
101
|
function invariant(condition, message, Err) {
|
|
85
102
|
if (Err === void 0) { Err = Error; }
|
|
@@ -88,3 +105,53 @@ function invariant(condition, message, Err) {
|
|
|
88
105
|
}
|
|
89
106
|
}
|
|
90
107
|
exports.invariant = invariant;
|
|
108
|
+
exports.createMemoizedNumberFormat = (0, fast_memoize_1.memoize)(function () {
|
|
109
|
+
var _a;
|
|
110
|
+
var args = [];
|
|
111
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
112
|
+
args[_i] = arguments[_i];
|
|
113
|
+
}
|
|
114
|
+
return new ((_a = Intl.NumberFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
|
|
115
|
+
}, {
|
|
116
|
+
strategy: fast_memoize_1.strategies.variadic,
|
|
117
|
+
});
|
|
118
|
+
exports.createMemoizedDateTimeFormat = (0, fast_memoize_1.memoize)(function () {
|
|
119
|
+
var _a;
|
|
120
|
+
var args = [];
|
|
121
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
122
|
+
args[_i] = arguments[_i];
|
|
123
|
+
}
|
|
124
|
+
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
|
|
125
|
+
}, {
|
|
126
|
+
strategy: fast_memoize_1.strategies.variadic,
|
|
127
|
+
});
|
|
128
|
+
exports.createMemoizedPluralRules = (0, fast_memoize_1.memoize)(function () {
|
|
129
|
+
var _a;
|
|
130
|
+
var args = [];
|
|
131
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
132
|
+
args[_i] = arguments[_i];
|
|
133
|
+
}
|
|
134
|
+
return new ((_a = Intl.PluralRules).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
|
|
135
|
+
}, {
|
|
136
|
+
strategy: fast_memoize_1.strategies.variadic,
|
|
137
|
+
});
|
|
138
|
+
exports.createMemoizedLocale = (0, fast_memoize_1.memoize)(function () {
|
|
139
|
+
var _a;
|
|
140
|
+
var args = [];
|
|
141
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
142
|
+
args[_i] = arguments[_i];
|
|
143
|
+
}
|
|
144
|
+
return new ((_a = Intl.Locale).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
|
|
145
|
+
}, {
|
|
146
|
+
strategy: fast_memoize_1.strategies.variadic,
|
|
147
|
+
});
|
|
148
|
+
exports.createMemoizedListFormat = (0, fast_memoize_1.memoize)(function () {
|
|
149
|
+
var _a;
|
|
150
|
+
var args = [];
|
|
151
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
152
|
+
args[_i] = arguments[_i];
|
|
153
|
+
}
|
|
154
|
+
return new ((_a = Intl.ListFormat).bind.apply(_a, tslib_1.__spreadArray([void 0], args, false)))();
|
|
155
|
+
}, {
|
|
156
|
+
strategy: fast_memoize_1.strategies.variadic,
|
|
157
|
+
});
|