@formatjs/ecma402-abstract 1.11.8 → 1.11.9
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/262.ts +372 -0
- package/BUILD +97 -0
- package/CHANGELOG.md +709 -0
- package/CanonicalizeLocaleList.ts +8 -0
- package/CanonicalizeTimeZoneName.ts +29 -0
- package/CoerceOptionsToObject.ts +13 -0
- package/DefaultNumberOption.ts +28 -0
- package/GetNumberOption.ts +29 -0
- package/GetOption.ts +38 -0
- package/GetOptionsObject.ts +14 -0
- package/IsSanctionedSimpleUnitIdentifier.ts +66 -0
- package/IsValidTimeZoneName.ts +27 -0
- package/IsWellFormedCurrencyCode.ts +23 -0
- package/IsWellFormedUnitIdentifier.ts +32 -0
- package/LICENSE.md +0 -0
- package/NumberFormat/ComputeExponent.ts +49 -0
- package/NumberFormat/ComputeExponentForMagnitude.ts +71 -0
- package/NumberFormat/CurrencyDigits.ts +13 -0
- package/NumberFormat/FormatNumericToParts.ts +22 -0
- package/NumberFormat/FormatNumericToString.ts +71 -0
- package/NumberFormat/InitializeNumberFormat.ts +147 -0
- package/NumberFormat/PartitionNumberPattern.ts +86 -0
- package/NumberFormat/SetNumberFormatDigitOptions.ts +45 -0
- package/NumberFormat/SetNumberFormatUnitOptions.ts +77 -0
- package/NumberFormat/ToRawFixed.ts +56 -0
- package/NumberFormat/ToRawPrecision.ts +86 -0
- package/NumberFormat/digit-mapping.generated.ts +1 -0
- package/NumberFormat/format_to_parts.ts +571 -0
- package/PartitionPattern.ts +38 -0
- package/README.md +0 -0
- package/SupportedLocales.ts +31 -0
- package/data.ts +9 -0
- package/index.ts +45 -0
- package/package.json +3 -3
- package/regex.generated.ts +2 -0
- package/scripts/digit-mapping.ts +109 -0
- package/scripts/regex-gen.ts +19 -0
- package/tests/PartitionPattern.test.ts +38 -0
- package/tests/ToRawFixed.test.tsx +41 -0
- package/tests/ToRawPrecision.test.tsx +65 -0
- package/tsconfig.json +5 -0
- package/types/core.ts +11 -0
- package/types/date-time.ts +199 -0
- package/types/displaynames.ts +48 -0
- package/types/list.ts +22 -0
- package/types/number.ts +240 -0
- package/types/plural-rules.ts +18 -0
- package/types/relative-time.ts +74 -0
- package/utils.ts +128 -0
- package/262.d.ts +0 -92
- package/262.d.ts.map +0 -1
- package/262.js +0 -362
- package/CanonicalizeLocaleList.d.ts +0 -6
- package/CanonicalizeLocaleList.d.ts.map +0 -1
- package/CanonicalizeLocaleList.js +0 -12
- package/CanonicalizeTimeZoneName.d.ts +0 -9
- package/CanonicalizeTimeZoneName.d.ts.map +0 -1
- package/CanonicalizeTimeZoneName.js +0 -21
- package/CoerceOptionsToObject.d.ts +0 -7
- package/CoerceOptionsToObject.d.ts.map +0 -1
- package/CoerceOptionsToObject.js +0 -16
- package/DefaultNumberOption.d.ts +0 -9
- package/DefaultNumberOption.d.ts.map +0 -1
- package/DefaultNumberOption.js +0 -14
- package/GetNumberOption.d.ts +0 -10
- package/GetNumberOption.d.ts.map +0 -1
- package/GetNumberOption.js +0 -18
- package/GetOption.d.ts +0 -10
- package/GetOption.d.ts.map +0 -1
- package/GetOption.js +0 -35
- package/GetOptionsObject.d.ts +0 -7
- package/GetOptionsObject.d.ts.map +0 -1
- package/GetOptionsObject.js +0 -18
- package/IsSanctionedSimpleUnitIdentifier.d.ts +0 -14
- package/IsSanctionedSimpleUnitIdentifier.d.ts.map +0 -1
- package/IsSanctionedSimpleUnitIdentifier.js +0 -68
- package/IsValidTimeZoneName.d.ts +0 -10
- package/IsValidTimeZoneName.d.ts.map +0 -1
- package/IsValidTimeZoneName.js +0 -23
- package/IsWellFormedCurrencyCode.d.ts +0 -5
- package/IsWellFormedCurrencyCode.d.ts.map +0 -1
- package/IsWellFormedCurrencyCode.js +0 -25
- package/IsWellFormedUnitIdentifier.d.ts +0 -6
- package/IsWellFormedUnitIdentifier.d.ts.map +0 -1
- package/IsWellFormedUnitIdentifier.js +0 -32
- package/NumberFormat/ComputeExponent.d.ts +0 -12
- package/NumberFormat/ComputeExponent.d.ts.map +0 -1
- package/NumberFormat/ComputeExponent.js +0 -43
- package/NumberFormat/ComputeExponentForMagnitude.d.ts +0 -10
- package/NumberFormat/ComputeExponentForMagnitude.d.ts.map +0 -1
- package/NumberFormat/ComputeExponentForMagnitude.js +0 -64
- package/NumberFormat/CurrencyDigits.d.ts +0 -7
- package/NumberFormat/CurrencyDigits.d.ts.map +0 -1
- package/NumberFormat/CurrencyDigits.js +0 -14
- package/NumberFormat/FormatNumericToParts.d.ts +0 -5
- package/NumberFormat/FormatNumericToParts.d.ts.map +0 -1
- package/NumberFormat/FormatNumericToParts.js +0 -18
- package/NumberFormat/FormatNumericToString.d.ts +0 -9
- package/NumberFormat/FormatNumericToString.d.ts.map +0 -1
- package/NumberFormat/FormatNumericToString.js +0 -45
- package/NumberFormat/InitializeNumberFormat.d.ts +0 -13
- package/NumberFormat/InitializeNumberFormat.d.ts.map +0 -1
- package/NumberFormat/InitializeNumberFormat.js +0 -68
- package/NumberFormat/PartitionNumberPattern.d.ts +0 -8
- package/NumberFormat/PartitionNumberPattern.d.ts.map +0 -1
- package/NumberFormat/PartitionNumberPattern.js +0 -80
- package/NumberFormat/SetNumberFormatDigitOptions.d.ts +0 -6
- package/NumberFormat/SetNumberFormatDigitOptions.d.ts.map +0 -1
- package/NumberFormat/SetNumberFormatDigitOptions.js +0 -40
- package/NumberFormat/SetNumberFormatUnitOptions.d.ts +0 -8
- package/NumberFormat/SetNumberFormatUnitOptions.d.ts.map +0 -1
- package/NumberFormat/SetNumberFormatUnitOptions.js +0 -43
- package/NumberFormat/ToRawFixed.d.ts +0 -10
- package/NumberFormat/ToRawFixed.d.ts.map +0 -1
- package/NumberFormat/ToRawFixed.js +0 -55
- package/NumberFormat/ToRawPrecision.d.ts +0 -3
- package/NumberFormat/ToRawPrecision.d.ts.map +0 -1
- package/NumberFormat/ToRawPrecision.js +0 -78
- package/NumberFormat/digit-mapping.generated.d.ts +0 -2
- package/NumberFormat/digit-mapping.generated.d.ts.map +0 -1
- package/NumberFormat/digit-mapping.generated.js +0 -4
- package/NumberFormat/format_to_parts.d.ts +0 -22
- package/NumberFormat/format_to_parts.d.ts.map +0 -1
- package/NumberFormat/format_to_parts.js +0 -424
- package/PartitionPattern.d.ts +0 -9
- package/PartitionPattern.d.ts.map +0 -1
- package/PartitionPattern.js +0 -39
- package/SupportedLocales.d.ts +0 -10
- package/SupportedLocales.d.ts.map +0 -1
- package/SupportedLocales.js +0 -24
- package/data.d.ts +0 -6
- package/data.d.ts.map +0 -1
- package/data.js +0 -17
- package/index.d.ts +0 -37
- package/index.d.ts.map +0 -1
- package/index.js +0 -48
- package/lib/262.d.ts +0 -92
- package/lib/262.d.ts.map +0 -1
- package/lib/262.js +0 -336
- package/lib/CanonicalizeLocaleList.d.ts +0 -6
- package/lib/CanonicalizeLocaleList.d.ts.map +0 -1
- package/lib/CanonicalizeLocaleList.js +0 -8
- package/lib/CanonicalizeTimeZoneName.d.ts +0 -9
- package/lib/CanonicalizeTimeZoneName.d.ts.map +0 -1
- package/lib/CanonicalizeTimeZoneName.js +0 -17
- package/lib/CoerceOptionsToObject.d.ts +0 -7
- package/lib/CoerceOptionsToObject.d.ts.map +0 -1
- package/lib/CoerceOptionsToObject.js +0 -12
- package/lib/DefaultNumberOption.d.ts +0 -9
- package/lib/DefaultNumberOption.d.ts.map +0 -1
- package/lib/DefaultNumberOption.js +0 -10
- package/lib/GetNumberOption.d.ts +0 -10
- package/lib/GetNumberOption.d.ts.map +0 -1
- package/lib/GetNumberOption.js +0 -14
- package/lib/GetOption.d.ts +0 -10
- package/lib/GetOption.d.ts.map +0 -1
- package/lib/GetOption.js +0 -31
- package/lib/GetOptionsObject.d.ts +0 -7
- package/lib/GetOptionsObject.d.ts.map +0 -1
- package/lib/GetOptionsObject.js +0 -14
- package/lib/IsSanctionedSimpleUnitIdentifier.d.ts +0 -14
- package/lib/IsSanctionedSimpleUnitIdentifier.d.ts.map +0 -1
- package/lib/IsSanctionedSimpleUnitIdentifier.js +0 -63
- package/lib/IsValidTimeZoneName.d.ts +0 -10
- package/lib/IsValidTimeZoneName.d.ts.map +0 -1
- package/lib/IsValidTimeZoneName.js +0 -19
- package/lib/IsWellFormedCurrencyCode.d.ts +0 -5
- package/lib/IsWellFormedCurrencyCode.d.ts.map +0 -1
- package/lib/IsWellFormedCurrencyCode.js +0 -21
- package/lib/IsWellFormedUnitIdentifier.d.ts +0 -6
- package/lib/IsWellFormedUnitIdentifier.d.ts.map +0 -1
- package/lib/IsWellFormedUnitIdentifier.js +0 -28
- package/lib/NumberFormat/ComputeExponent.d.ts +0 -12
- package/lib/NumberFormat/ComputeExponent.d.ts.map +0 -1
- package/lib/NumberFormat/ComputeExponent.js +0 -39
- package/lib/NumberFormat/ComputeExponentForMagnitude.d.ts +0 -10
- package/lib/NumberFormat/ComputeExponentForMagnitude.d.ts.map +0 -1
- package/lib/NumberFormat/ComputeExponentForMagnitude.js +0 -60
- package/lib/NumberFormat/CurrencyDigits.d.ts +0 -7
- package/lib/NumberFormat/CurrencyDigits.d.ts.map +0 -1
- package/lib/NumberFormat/CurrencyDigits.js +0 -10
- package/lib/NumberFormat/FormatNumericToParts.d.ts +0 -5
- package/lib/NumberFormat/FormatNumericToParts.d.ts.map +0 -1
- package/lib/NumberFormat/FormatNumericToParts.js +0 -14
- package/lib/NumberFormat/FormatNumericToString.d.ts +0 -9
- package/lib/NumberFormat/FormatNumericToString.d.ts.map +0 -1
- package/lib/NumberFormat/FormatNumericToString.js +0 -41
- package/lib/NumberFormat/InitializeNumberFormat.d.ts +0 -13
- package/lib/NumberFormat/InitializeNumberFormat.d.ts.map +0 -1
- package/lib/NumberFormat/InitializeNumberFormat.js +0 -64
- package/lib/NumberFormat/PartitionNumberPattern.d.ts +0 -8
- package/lib/NumberFormat/PartitionNumberPattern.d.ts.map +0 -1
- package/lib/NumberFormat/PartitionNumberPattern.js +0 -75
- package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts +0 -6
- package/lib/NumberFormat/SetNumberFormatDigitOptions.d.ts.map +0 -1
- package/lib/NumberFormat/SetNumberFormatDigitOptions.js +0 -36
- package/lib/NumberFormat/SetNumberFormatUnitOptions.d.ts +0 -8
- package/lib/NumberFormat/SetNumberFormatUnitOptions.d.ts.map +0 -1
- package/lib/NumberFormat/SetNumberFormatUnitOptions.js +0 -39
- package/lib/NumberFormat/ToRawFixed.d.ts +0 -10
- package/lib/NumberFormat/ToRawFixed.d.ts.map +0 -1
- package/lib/NumberFormat/ToRawFixed.js +0 -51
- package/lib/NumberFormat/ToRawPrecision.d.ts +0 -3
- package/lib/NumberFormat/ToRawPrecision.d.ts.map +0 -1
- package/lib/NumberFormat/ToRawPrecision.js +0 -74
- package/lib/NumberFormat/digit-mapping.generated.d.ts +0 -2
- package/lib/NumberFormat/digit-mapping.generated.d.ts.map +0 -1
- package/lib/NumberFormat/digit-mapping.generated.js +0 -1
- package/lib/NumberFormat/format_to_parts.d.ts +0 -22
- package/lib/NumberFormat/format_to_parts.d.ts.map +0 -1
- package/lib/NumberFormat/format_to_parts.js +0 -421
- package/lib/PartitionPattern.d.ts +0 -9
- package/lib/PartitionPattern.d.ts.map +0 -1
- package/lib/PartitionPattern.js +0 -35
- package/lib/SupportedLocales.d.ts +0 -10
- package/lib/SupportedLocales.d.ts.map +0 -1
- package/lib/SupportedLocales.js +0 -20
- package/lib/data.d.ts +0 -6
- package/lib/data.d.ts.map +0 -1
- package/lib/data.js +0 -13
- package/lib/index.d.ts +0 -37
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -34
- package/lib/regex.generated.d.ts +0 -2
- package/lib/regex.generated.d.ts.map +0 -1
- package/lib/regex.generated.js +0 -2
- package/lib/types/core.d.ts +0 -11
- package/lib/types/core.d.ts.map +0 -1
- package/lib/types/core.js +0 -1
- package/lib/types/date-time.d.ts +0 -135
- package/lib/types/date-time.d.ts.map +0 -1
- package/lib/types/date-time.js +0 -6
- package/lib/types/displaynames.d.ts +0 -47
- package/lib/types/displaynames.d.ts.map +0 -1
- package/lib/types/displaynames.js +0 -1
- package/lib/types/list.d.ts +0 -19
- package/lib/types/list.d.ts.map +0 -1
- package/lib/types/list.js +0 -1
- package/lib/types/number.d.ts +0 -147
- package/lib/types/number.d.ts.map +0 -1
- package/lib/types/number.js +0 -1
- package/lib/types/plural-rules.d.ts +0 -17
- package/lib/types/plural-rules.d.ts.map +0 -1
- package/lib/types/plural-rules.js +0 -1
- package/lib/types/relative-time.d.ts +0 -41
- package/lib/types/relative-time.d.ts.map +0 -1
- package/lib/types/relative-time.js +0 -1
- package/lib/utils.d.ts +0 -24
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -78
- package/regex.generated.d.ts +0 -2
- package/regex.generated.d.ts.map +0 -1
- package/regex.generated.js +0 -5
- package/types/core.d.ts +0 -11
- package/types/core.d.ts.map +0 -1
- package/types/core.js +0 -2
- package/types/date-time.d.ts +0 -135
- package/types/date-time.d.ts.map +0 -1
- package/types/date-time.js +0 -9
- package/types/displaynames.d.ts +0 -47
- package/types/displaynames.d.ts.map +0 -1
- package/types/displaynames.js +0 -2
- package/types/list.d.ts +0 -19
- package/types/list.d.ts.map +0 -1
- package/types/list.js +0 -2
- package/types/number.d.ts +0 -147
- package/types/number.d.ts.map +0 -1
- package/types/number.js +0 -2
- package/types/plural-rules.d.ts +0 -17
- package/types/plural-rules.d.ts.map +0 -1
- package/types/plural-rules.js +0 -2
- package/types/relative-time.d.ts +0 -41
- package/types/relative-time.d.ts.map +0 -1
- package/types/relative-time.js +0 -2
- package/utils.d.ts +0 -24
- package/utils.d.ts.map +0 -1
- package/utils.js +0 -90
package/types/number.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {LDMLPluralRule} from './plural-rules'
|
|
2
|
+
import {LocaleData} from './core'
|
|
3
|
+
|
|
4
|
+
export type NumberFormatNotation =
|
|
5
|
+
| 'standard'
|
|
6
|
+
| 'scientific'
|
|
7
|
+
| 'engineering'
|
|
8
|
+
| 'compact'
|
|
9
|
+
|
|
10
|
+
export type NumberFormatRoundingType =
|
|
11
|
+
| 'significantDigits'
|
|
12
|
+
| 'fractionDigits'
|
|
13
|
+
| 'compactRounding'
|
|
14
|
+
|
|
15
|
+
export interface NumberFormatDigitOptions {
|
|
16
|
+
minimumIntegerDigits?: number
|
|
17
|
+
minimumSignificantDigits?: number
|
|
18
|
+
maximumSignificantDigits?: number
|
|
19
|
+
minimumFractionDigits?: number
|
|
20
|
+
maximumFractionDigits?: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface NumberFormatDigitInternalSlots {
|
|
24
|
+
minimumIntegerDigits: number
|
|
25
|
+
minimumSignificantDigits?: number
|
|
26
|
+
maximumSignificantDigits?: number
|
|
27
|
+
roundingType: NumberFormatRoundingType
|
|
28
|
+
// These two properties are only used when `roundingType` is "fractionDigits".
|
|
29
|
+
minimumFractionDigits?: number
|
|
30
|
+
maximumFractionDigits?: number
|
|
31
|
+
notation?: NumberFormatNotation
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// All fields are optional due to de-duping
|
|
35
|
+
export type RawNumberLocaleData = LocaleData<NumberFormatLocaleInternalData>
|
|
36
|
+
|
|
37
|
+
export interface NumberFormatLocaleInternalData {
|
|
38
|
+
units: UnitDataTable
|
|
39
|
+
currencies: Record<string, CurrencyData>
|
|
40
|
+
numbers: RawNumberData
|
|
41
|
+
// Bc of relevantExtensionKeys in the spec
|
|
42
|
+
nu: string[]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface UnitDataTable {
|
|
46
|
+
simple: Record<string, UnitData>
|
|
47
|
+
compound: Record<string, CompoundUnitData>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface UnitData {
|
|
51
|
+
// A pattern where {0} is number placeholder. Example: "摂氏 {0} 度".
|
|
52
|
+
long: LDMLPluralRuleMap<string>
|
|
53
|
+
short: LDMLPluralRuleMap<string>
|
|
54
|
+
narrow: LDMLPluralRuleMap<string>
|
|
55
|
+
// perUnitPattern. See http://unicode.org/reports/tr35/tr35-general.html#perUnitPatterns
|
|
56
|
+
perUnit: Record<'narrow' | 'short' | 'long', string | undefined>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The values are patterns on how to compose simple units.
|
|
60
|
+
// For example, "{0} per {1}".
|
|
61
|
+
export interface CompoundUnitData {
|
|
62
|
+
long: string
|
|
63
|
+
short: string
|
|
64
|
+
narrow: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface CurrencyData {
|
|
68
|
+
displayName: LDMLPluralRuleMap<string>
|
|
69
|
+
symbol: string
|
|
70
|
+
narrow: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type DecimalFormatNum =
|
|
74
|
+
| '1000'
|
|
75
|
+
| '10000'
|
|
76
|
+
| '100000'
|
|
77
|
+
| '1000000'
|
|
78
|
+
| '10000000'
|
|
79
|
+
| '100000000'
|
|
80
|
+
| '1000000000'
|
|
81
|
+
| '10000000000'
|
|
82
|
+
| '100000000000'
|
|
83
|
+
| '1000000000000'
|
|
84
|
+
| '10000000000000'
|
|
85
|
+
| '100000000000000'
|
|
86
|
+
export type NumberingSystem = string
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* We only care about insertBetween bc we assume
|
|
90
|
+
* `currencyMatch` & `surroundingMatch` are all the same
|
|
91
|
+
*
|
|
92
|
+
* @export
|
|
93
|
+
* @interface CurrencySpacingData
|
|
94
|
+
*/
|
|
95
|
+
export interface CurrencySpacingData {
|
|
96
|
+
beforeInsertBetween: string
|
|
97
|
+
afterInsertBetween: string
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface RawCurrencyData {
|
|
101
|
+
currencySpacing: CurrencySpacingData
|
|
102
|
+
standard: string
|
|
103
|
+
accounting: string
|
|
104
|
+
short?: Record<DecimalFormatNum, LDMLPluralRuleMap<string>>
|
|
105
|
+
// IMPORTANT: We're making the assumption here that currency unitPattern
|
|
106
|
+
// are the same for all LDMLPluralRule
|
|
107
|
+
unitPattern: string
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface SymbolsData {
|
|
111
|
+
decimal: string
|
|
112
|
+
group: string
|
|
113
|
+
list: string
|
|
114
|
+
percentSign: string
|
|
115
|
+
plusSign: string
|
|
116
|
+
minusSign: string
|
|
117
|
+
exponential: string
|
|
118
|
+
superscriptingExponent: string
|
|
119
|
+
perMille: string
|
|
120
|
+
infinity: string
|
|
121
|
+
nan: string
|
|
122
|
+
timeSeparator: string
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface RawNumberData {
|
|
126
|
+
nu: string[]
|
|
127
|
+
// numberingSystem -> pattern
|
|
128
|
+
symbols: Record<NumberingSystem, SymbolsData>
|
|
129
|
+
// numberingSystem -> pattern
|
|
130
|
+
decimal: Record<
|
|
131
|
+
NumberingSystem,
|
|
132
|
+
{
|
|
133
|
+
// The standard number pattern of the decimal.
|
|
134
|
+
standard: string
|
|
135
|
+
// These two are compact notation mappings.
|
|
136
|
+
long: Record<DecimalFormatNum, LDMLPluralRuleMap<string>>
|
|
137
|
+
short: Record<DecimalFormatNum, LDMLPluralRuleMap<string>>
|
|
138
|
+
}
|
|
139
|
+
>
|
|
140
|
+
percent: Record<NumberingSystem, string>
|
|
141
|
+
currency: Record<NumberingSystem, RawCurrencyData>
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export type LDMLPluralRuleMap<T> = Omit<
|
|
145
|
+
Partial<Record<LDMLPluralRule, T>>,
|
|
146
|
+
'other'
|
|
147
|
+
> & {
|
|
148
|
+
other: T
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface RawNumberFormatResult {
|
|
152
|
+
formattedString: string
|
|
153
|
+
roundedNumber: number
|
|
154
|
+
integerDigitsCount: number
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export type NumberFormatOptionsLocaleMatcher = 'lookup' | 'best fit'
|
|
158
|
+
export type NumberFormatOptionsStyle =
|
|
159
|
+
| 'decimal'
|
|
160
|
+
| 'percent'
|
|
161
|
+
| 'currency'
|
|
162
|
+
| 'unit'
|
|
163
|
+
export type NumberFormatOptionsCompactDisplay = 'short' | 'long'
|
|
164
|
+
export type NumberFormatOptionsCurrencyDisplay =
|
|
165
|
+
| 'symbol'
|
|
166
|
+
| 'code'
|
|
167
|
+
| 'name'
|
|
168
|
+
| 'narrowSymbol'
|
|
169
|
+
export type NumberFormatOptionsCurrencySign = 'standard' | 'accounting'
|
|
170
|
+
export type NumberFormatOptionsNotation = NumberFormatNotation
|
|
171
|
+
export type NumberFormatOptionsSignDisplay =
|
|
172
|
+
| 'auto'
|
|
173
|
+
| 'always'
|
|
174
|
+
| 'never'
|
|
175
|
+
| 'exceptZero'
|
|
176
|
+
export type NumberFormatOptionsUnitDisplay = 'long' | 'short' | 'narrow'
|
|
177
|
+
|
|
178
|
+
export interface NumberFormatInternal extends NumberFormatDigitInternalSlots {
|
|
179
|
+
locale: string
|
|
180
|
+
dataLocale: string
|
|
181
|
+
style: NumberFormatOptionsStyle
|
|
182
|
+
currency?: string
|
|
183
|
+
currencyDisplay: NumberFormatOptionsCurrencyDisplay
|
|
184
|
+
unit?: string
|
|
185
|
+
unitDisplay: NumberFormatOptionsUnitDisplay
|
|
186
|
+
currencySign: NumberFormatOptionsCurrencySign
|
|
187
|
+
notation: NumberFormatOptionsNotation
|
|
188
|
+
compactDisplay: NumberFormatOptionsCompactDisplay
|
|
189
|
+
signDisplay: NumberFormatOptionsSignDisplay
|
|
190
|
+
useGrouping: boolean
|
|
191
|
+
pl: Intl.PluralRules
|
|
192
|
+
boundFormat?: Intl.NumberFormat['format']
|
|
193
|
+
numberingSystem: string
|
|
194
|
+
// Locale-dependent formatter data
|
|
195
|
+
dataLocaleData: NumberFormatLocaleInternalData
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export type NumberFormatOptions = Omit<
|
|
199
|
+
Intl.NumberFormatOptions,
|
|
200
|
+
'signDisplay'
|
|
201
|
+
> &
|
|
202
|
+
NumberFormatDigitOptions & {
|
|
203
|
+
localeMatcher?: NumberFormatOptionsLocaleMatcher
|
|
204
|
+
style?: NumberFormatOptionsStyle
|
|
205
|
+
compactDisplay?: NumberFormatOptionsCompactDisplay
|
|
206
|
+
currencyDisplay?: NumberFormatOptionsCurrencyDisplay
|
|
207
|
+
currencySign?: NumberFormatOptionsCurrencySign
|
|
208
|
+
notation?: NumberFormatOptionsNotation
|
|
209
|
+
signDisplay?: NumberFormatOptionsSignDisplay
|
|
210
|
+
unit?: string
|
|
211
|
+
unitDisplay?: NumberFormatOptionsUnitDisplay
|
|
212
|
+
numberingSystem?: string
|
|
213
|
+
trailingZeroDisplay?: 'auto' | 'stripIfInteger'
|
|
214
|
+
roundingPriority?: 'auto' | 'morePrecision' | 'lessPrecision'
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export type ResolvedNumberFormatOptions = Intl.ResolvedNumberFormatOptions &
|
|
218
|
+
Pick<
|
|
219
|
+
NumberFormatInternal,
|
|
220
|
+
| 'currencySign'
|
|
221
|
+
| 'unit'
|
|
222
|
+
| 'unitDisplay'
|
|
223
|
+
| 'notation'
|
|
224
|
+
| 'compactDisplay'
|
|
225
|
+
| 'signDisplay'
|
|
226
|
+
>
|
|
227
|
+
|
|
228
|
+
export type NumberFormatPartTypes =
|
|
229
|
+
| Intl.NumberFormatPartTypes
|
|
230
|
+
| 'exponentSeparator'
|
|
231
|
+
| 'exponentMinusSign'
|
|
232
|
+
| 'exponentInteger'
|
|
233
|
+
| 'compact'
|
|
234
|
+
| 'unit'
|
|
235
|
+
| 'literal'
|
|
236
|
+
|
|
237
|
+
export interface NumberFormatPart {
|
|
238
|
+
type: NumberFormatPartTypes
|
|
239
|
+
value: string
|
|
240
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {LocaleData} from './core'
|
|
2
|
+
import {NumberFormatDigitInternalSlots} from './number'
|
|
3
|
+
export type LDMLPluralRule = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other'
|
|
4
|
+
export interface PluralRulesData {
|
|
5
|
+
categories: {
|
|
6
|
+
cardinal: string[]
|
|
7
|
+
ordinal: string[]
|
|
8
|
+
}
|
|
9
|
+
fn: (val: number | string, ord?: boolean) => LDMLPluralRule
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type PluralRulesLocaleData = LocaleData<PluralRulesData>
|
|
13
|
+
|
|
14
|
+
export interface PluralRulesInternal extends NumberFormatDigitInternalSlots {
|
|
15
|
+
initializedPluralRules: boolean
|
|
16
|
+
locale: string
|
|
17
|
+
type: 'cardinal' | 'ordinal'
|
|
18
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {LocaleData} from './core'
|
|
2
|
+
import {LDMLPluralRule} from './plural-rules'
|
|
3
|
+
|
|
4
|
+
export interface FieldData {
|
|
5
|
+
'0'?: string
|
|
6
|
+
'1'?: string
|
|
7
|
+
'-1'?: string
|
|
8
|
+
'2'?: string
|
|
9
|
+
'-2'?: string
|
|
10
|
+
'3'?: string
|
|
11
|
+
'-3'?: string
|
|
12
|
+
future: RelativeTimeData
|
|
13
|
+
past: RelativeTimeData
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type RelativeTimeData = {[u in LDMLPluralRule]?: string}
|
|
17
|
+
|
|
18
|
+
export type UnpackedLocaleFieldsData = {
|
|
19
|
+
[f in RelativeTimeField]?: FieldData
|
|
20
|
+
} & {nu: Array<string | null>}
|
|
21
|
+
|
|
22
|
+
export type LocaleFieldsData = {
|
|
23
|
+
[f in RelativeTimeField]?: FieldData
|
|
24
|
+
} & {nu?: Array<string | null>}
|
|
25
|
+
|
|
26
|
+
export type RelativeTimeField =
|
|
27
|
+
| 'second'
|
|
28
|
+
| 'second-short'
|
|
29
|
+
| 'second-narrow'
|
|
30
|
+
| 'minute'
|
|
31
|
+
| 'minute-short'
|
|
32
|
+
| 'minute-narrow'
|
|
33
|
+
| 'hour'
|
|
34
|
+
| 'hour-short'
|
|
35
|
+
| 'hour-narrow'
|
|
36
|
+
| 'day'
|
|
37
|
+
| 'day-short'
|
|
38
|
+
| 'day-narrow'
|
|
39
|
+
| 'week'
|
|
40
|
+
| 'week-short'
|
|
41
|
+
| 'week-narrow'
|
|
42
|
+
| 'month'
|
|
43
|
+
| 'month-short'
|
|
44
|
+
| 'month-narrow'
|
|
45
|
+
| 'quarter'
|
|
46
|
+
| 'quarter-short'
|
|
47
|
+
| 'quarter-narrow'
|
|
48
|
+
| 'year'
|
|
49
|
+
| 'year-short'
|
|
50
|
+
| 'year-narrow'
|
|
51
|
+
|
|
52
|
+
export type RelativeTimeFormatSingularUnit = Exclude<
|
|
53
|
+
Intl.RelativeTimeFormatUnit,
|
|
54
|
+
| 'seconds'
|
|
55
|
+
| 'minutes'
|
|
56
|
+
| 'hours'
|
|
57
|
+
| 'days'
|
|
58
|
+
| 'weeks'
|
|
59
|
+
| 'months'
|
|
60
|
+
| 'quarters'
|
|
61
|
+
| 'years'
|
|
62
|
+
>
|
|
63
|
+
|
|
64
|
+
export type RelativeTimeLocaleData = LocaleData<LocaleFieldsData>
|
|
65
|
+
export interface RelativeTimeFormatInternal {
|
|
66
|
+
numberFormat: Intl.NumberFormat
|
|
67
|
+
pluralRules: Intl.PluralRules
|
|
68
|
+
locale: string
|
|
69
|
+
fields: LocaleFieldsData
|
|
70
|
+
style: Intl.ResolvedRelativeTimeFormatOptions['style']
|
|
71
|
+
numeric: Intl.ResolvedRelativeTimeFormatOptions['numeric']
|
|
72
|
+
numberingSystem: string
|
|
73
|
+
initializedRelativeTimeFormat: boolean
|
|
74
|
+
}
|
package/utils.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
|
|
3
|
+
* @param x number
|
|
4
|
+
*/
|
|
5
|
+
export function getMagnitude(x: number): number {
|
|
6
|
+
// Cannot count string length via Number.toString because it may use scientific notation
|
|
7
|
+
// for very small or very large numbers.
|
|
8
|
+
return Math.floor(Math.log(x) * Math.LOG10E)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function repeat(s: string, times: number): string {
|
|
12
|
+
if (typeof s.repeat === 'function') {
|
|
13
|
+
return s.repeat(times)
|
|
14
|
+
}
|
|
15
|
+
const arr = new Array(times)
|
|
16
|
+
for (let i = 0; i < arr.length; i++) {
|
|
17
|
+
arr[i] = s
|
|
18
|
+
}
|
|
19
|
+
return arr.join('')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function setInternalSlot<
|
|
23
|
+
Instance extends object,
|
|
24
|
+
Internal extends object,
|
|
25
|
+
Field extends keyof Internal
|
|
26
|
+
>(
|
|
27
|
+
map: WeakMap<Instance, Internal>,
|
|
28
|
+
pl: Instance,
|
|
29
|
+
field: Field,
|
|
30
|
+
value: NonNullable<Internal>[Field]
|
|
31
|
+
) {
|
|
32
|
+
if (!map.get(pl)) {
|
|
33
|
+
map.set(pl, Object.create(null))
|
|
34
|
+
}
|
|
35
|
+
const slots = map.get(pl)!
|
|
36
|
+
slots[field] = value
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function setMultiInternalSlots<
|
|
40
|
+
Instance extends object,
|
|
41
|
+
Internal extends object,
|
|
42
|
+
K extends keyof Internal
|
|
43
|
+
>(
|
|
44
|
+
map: WeakMap<Instance, Internal>,
|
|
45
|
+
pl: Instance,
|
|
46
|
+
props: Pick<NonNullable<Internal>, K>
|
|
47
|
+
) {
|
|
48
|
+
for (const k of Object.keys(props) as K[]) {
|
|
49
|
+
setInternalSlot(map, pl, k, props[k])
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function getInternalSlot<
|
|
54
|
+
Instance extends object,
|
|
55
|
+
Internal extends object,
|
|
56
|
+
Field extends keyof Internal
|
|
57
|
+
>(
|
|
58
|
+
map: WeakMap<Instance, Internal>,
|
|
59
|
+
pl: Instance,
|
|
60
|
+
field: Field
|
|
61
|
+
): Internal[Field] {
|
|
62
|
+
return getMultiInternalSlots(map, pl, field)[field]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getMultiInternalSlots<
|
|
66
|
+
Instance extends object,
|
|
67
|
+
Internal extends object,
|
|
68
|
+
Field extends keyof Internal
|
|
69
|
+
>(
|
|
70
|
+
map: WeakMap<Instance, Internal>,
|
|
71
|
+
pl: Instance,
|
|
72
|
+
...fields: Field[]
|
|
73
|
+
): Pick<Internal, Field> {
|
|
74
|
+
const slots = map.get(pl)
|
|
75
|
+
if (!slots) {
|
|
76
|
+
throw new TypeError(`${pl} InternalSlot has not been initialized`)
|
|
77
|
+
}
|
|
78
|
+
return fields.reduce((all, f) => {
|
|
79
|
+
all[f] = slots[f]
|
|
80
|
+
return all
|
|
81
|
+
}, Object.create(null) as Pick<Internal, Field>)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface LiteralPart {
|
|
85
|
+
type: 'literal'
|
|
86
|
+
value: string
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function isLiteralPart(
|
|
90
|
+
patternPart: LiteralPart | {type: string; value?: string}
|
|
91
|
+
): patternPart is LiteralPart {
|
|
92
|
+
return patternPart.type === 'literal'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
17 ECMAScript Standard Built-in Objects:
|
|
97
|
+
Every built-in Function object, including constructors, that is not
|
|
98
|
+
identified as an anonymous function has a name property whose value
|
|
99
|
+
is a String.
|
|
100
|
+
|
|
101
|
+
Unless otherwise specified, the name property of a built-in Function
|
|
102
|
+
object, if it exists, has the attributes { [[Writable]]: false,
|
|
103
|
+
[[Enumerable]]: false, [[Configurable]]: true }.
|
|
104
|
+
*/
|
|
105
|
+
export function defineProperty<T extends object>(
|
|
106
|
+
target: T,
|
|
107
|
+
name: string | symbol,
|
|
108
|
+
{value}: {value: any} & ThisType<any>
|
|
109
|
+
) {
|
|
110
|
+
Object.defineProperty(target, name, {
|
|
111
|
+
configurable: true,
|
|
112
|
+
enumerable: false,
|
|
113
|
+
writable: true,
|
|
114
|
+
value,
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi
|
|
119
|
+
|
|
120
|
+
export function invariant(
|
|
121
|
+
condition: boolean,
|
|
122
|
+
message: string,
|
|
123
|
+
Err: any = Error
|
|
124
|
+
): asserts condition {
|
|
125
|
+
if (!condition) {
|
|
126
|
+
throw new Err(message)
|
|
127
|
+
}
|
|
128
|
+
}
|
package/262.d.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* https://tc39.es/ecma262/#sec-tostring
|
|
3
|
-
*/
|
|
4
|
-
export declare function ToString(o: unknown): string;
|
|
5
|
-
/**
|
|
6
|
-
* https://tc39.es/ecma262/#sec-tonumber
|
|
7
|
-
* @param val
|
|
8
|
-
*/
|
|
9
|
-
export declare function ToNumber(val: any): number;
|
|
10
|
-
/**
|
|
11
|
-
* https://tc39.es/ecma262/#sec-timeclip
|
|
12
|
-
* @param time
|
|
13
|
-
*/
|
|
14
|
-
export declare function TimeClip(time: number): number;
|
|
15
|
-
/**
|
|
16
|
-
* https://tc39.es/ecma262/#sec-toobject
|
|
17
|
-
* @param arg
|
|
18
|
-
*/
|
|
19
|
-
export declare function ToObject<T>(arg: T): T extends null ? never : T extends undefined ? never : T;
|
|
20
|
-
/**
|
|
21
|
-
* https://www.ecma-international.org/ecma-262/11.0/index.html#sec-samevalue
|
|
22
|
-
* @param x
|
|
23
|
-
* @param y
|
|
24
|
-
*/
|
|
25
|
-
export declare function SameValue(x: any, y: any): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* https://www.ecma-international.org/ecma-262/11.0/index.html#sec-arraycreate
|
|
28
|
-
* @param len
|
|
29
|
-
*/
|
|
30
|
-
export declare function ArrayCreate(len: number): any[];
|
|
31
|
-
/**
|
|
32
|
-
* https://www.ecma-international.org/ecma-262/11.0/index.html#sec-hasownproperty
|
|
33
|
-
* @param o
|
|
34
|
-
* @param prop
|
|
35
|
-
*/
|
|
36
|
-
export declare function HasOwnProperty(o: object, prop: string): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* https://www.ecma-international.org/ecma-262/11.0/index.html#sec-type
|
|
39
|
-
* @param x
|
|
40
|
-
*/
|
|
41
|
-
export declare function Type(x: any): "Null" | "Undefined" | "Object" | "Number" | "Boolean" | "String" | "Symbol" | "BigInt" | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* https://tc39.es/ecma262/#eqn-Day
|
|
44
|
-
* @param t
|
|
45
|
-
*/
|
|
46
|
-
export declare function Day(t: number): number;
|
|
47
|
-
/**
|
|
48
|
-
* https://tc39.es/ecma262/#sec-week-day
|
|
49
|
-
* @param t
|
|
50
|
-
*/
|
|
51
|
-
export declare function WeekDay(t: number): number;
|
|
52
|
-
/**
|
|
53
|
-
* https://tc39.es/ecma262/#sec-year-number
|
|
54
|
-
* @param y
|
|
55
|
-
*/
|
|
56
|
-
export declare function DayFromYear(y: number): number;
|
|
57
|
-
/**
|
|
58
|
-
* https://tc39.es/ecma262/#sec-year-number
|
|
59
|
-
* @param y
|
|
60
|
-
*/
|
|
61
|
-
export declare function TimeFromYear(y: number): number;
|
|
62
|
-
/**
|
|
63
|
-
* https://tc39.es/ecma262/#sec-year-number
|
|
64
|
-
* @param t
|
|
65
|
-
*/
|
|
66
|
-
export declare function YearFromTime(t: number): number;
|
|
67
|
-
export declare function DaysInYear(y: number): 365 | 366;
|
|
68
|
-
export declare function DayWithinYear(t: number): number;
|
|
69
|
-
export declare function InLeapYear(t: number): 0 | 1;
|
|
70
|
-
/**
|
|
71
|
-
* https://tc39.es/ecma262/#sec-month-number
|
|
72
|
-
* @param t
|
|
73
|
-
*/
|
|
74
|
-
export declare function MonthFromTime(t: number): 0 | 1 | 2 | 3 | 4 | 7 | 5 | 6 | 8 | 9 | 10 | 11;
|
|
75
|
-
export declare function DateFromTime(t: number): number;
|
|
76
|
-
export declare function HourFromTime(t: number): number;
|
|
77
|
-
export declare function MinFromTime(t: number): number;
|
|
78
|
-
export declare function SecFromTime(t: number): number;
|
|
79
|
-
/**
|
|
80
|
-
* The abstract operation OrdinaryHasInstance implements
|
|
81
|
-
* the default algorithm for determining if an object O
|
|
82
|
-
* inherits from the instance object inheritance path
|
|
83
|
-
* provided by constructor C.
|
|
84
|
-
* @param C class
|
|
85
|
-
* @param O object
|
|
86
|
-
* @param internalSlots internalSlots
|
|
87
|
-
*/
|
|
88
|
-
export declare function OrdinaryHasInstance(C: Object, O: any, internalSlots?: {
|
|
89
|
-
boundTargetFunction: any;
|
|
90
|
-
}): boolean;
|
|
91
|
-
export declare function msFromTime(t: number): number;
|
|
92
|
-
//# sourceMappingURL=262.d.ts.map
|
package/262.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"262.d.ts","sourceRoot":"","sources":["../../../../../packages/ecma402-abstract/262.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAM3C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAiBzC;AAwBD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,UAQpC;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,GAAG,EAAE,CAAC,GACL,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,CAAC,CAK1D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,WAYvC;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,SAEtC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,WAErD;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,uGAyB1B;AAcD;;;GAGG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,UAE5B;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,UAEhC;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,UAEpC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,UAErC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,UAErC;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,aAWnC;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,UAEtC;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,CAE3C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,mDAwCtC;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,UAyCrC;AASD,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,UAErC;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,UAEpC;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,UAEpC;AAMD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,GAAG,EACN,aAAa,CAAC,EAAE;IAAC,mBAAmB,EAAE,GAAG,CAAA;CAAC,WAmB3C;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C"}
|