@formatjs/ecma402-abstract 2.0.0 → 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/index.d.ts +2 -2
- package/index.js +8 -3
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +52 -0
- package/package.json +2 -1
- package/utils.d.ts +5 -0
- package/utils.js +53 -1
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,7 +28,6 @@ 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
33
|
export { createDataProperty, defineProperty, getInternalSlot, getMagnitude, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
|
|
@@ -41,4 +41,4 @@ export * from './types/list';
|
|
|
41
41
|
export * from './types/number';
|
|
42
42
|
export * from './types/plural-rules';
|
|
43
43
|
export * from './types/relative-time';
|
|
44
|
-
export { invariant } from './utils';
|
|
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.isMissingLocaleDataError = exports.setMultiInternalSlots = exports.setInternalSlot = exports.isLiteralPart = exports.getMultiInternalSlots = exports.getMagnitude = exports.getInternalSlot = exports.defineProperty = exports.createDataProperty = exports._formatToParts = void 0;
|
|
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,8 +33,6 @@ 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");
|
|
@@ -54,4 +54,9 @@ tslib_1.__exportStar(require("./types/number"), exports);
|
|
|
54
54
|
tslib_1.__exportStar(require("./types/plural-rules"), exports);
|
|
55
55
|
tslib_1.__exportStar(require("./types/relative-time"), exports);
|
|
56
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; } });
|
|
57
62
|
Object.defineProperty(exports, "invariant", { enumerable: true, get: function () { return utils_2.invariant; } });
|
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,7 +28,6 @@ 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
33
|
export { createDataProperty, defineProperty, getInternalSlot, getMagnitude, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
|
|
@@ -41,4 +41,4 @@ export * from './types/list';
|
|
|
41
41
|
export * from './types/number';
|
|
42
42
|
export * from './types/plural-rules';
|
|
43
43
|
export * from './types/relative-time';
|
|
44
|
-
export { invariant } from './utils';
|
|
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,7 +28,6 @@ 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
33
|
export { createDataProperty, defineProperty, getInternalSlot, getMagnitude, getMultiInternalSlots, isLiteralPart, setInternalSlot, setMultiInternalSlots, } from './utils';
|
|
@@ -39,4 +39,4 @@ export * from './types/list';
|
|
|
39
39
|
export * from './types/number';
|
|
40
40
|
export * from './types/plural-rules';
|
|
41
41
|
export * from './types/relative-time';
|
|
42
|
-
export { invariant } from './utils';
|
|
42
|
+
export { createMemoizedDateTimeFormat, createMemoizedListFormat, createMemoizedLocale, createMemoizedNumberFormat, createMemoizedPluralRules, invariant, } from './utils';
|
package/lib/utils.d.ts
CHANGED
|
@@ -28,3 +28,8 @@ export declare function defineProperty<T extends object>(target: T, name: string
|
|
|
28
28
|
export declare function createDataProperty<T extends object>(target: T, name: string | symbol, value: any): void;
|
|
29
29
|
export declare const UNICODE_EXTENSION_SEQUENCE_REGEX: RegExp;
|
|
30
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
|
|
@@ -90,3 +92,53 @@ export function invariant(condition, message, Err) {
|
|
|
90
92
|
throw new Err(message);
|
|
91
93
|
}
|
|
92
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": "2.
|
|
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/utils.d.ts
CHANGED
|
@@ -28,3 +28,8 @@ export declare function defineProperty<T extends object>(target: T, name: string
|
|
|
28
28
|
export declare function createDataProperty<T extends object>(target: T, name: string | symbol, value: any): void;
|
|
29
29
|
export declare const UNICODE_EXTENSION_SEQUENCE_REGEX: RegExp;
|
|
30
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.createDataProperty = 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
|
|
@@ -103,3 +105,53 @@ function invariant(condition, message, Err) {
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
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
|
+
});
|