react-native-nitro-input 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/README.md +132 -2
- package/android/CMakeLists.txt +4 -0
- package/android/gradle.properties +1 -1
- package/android/src/main/cpp/JReflowEngine.cpp +32 -0
- package/android/src/main/cpp/JReflowEngine.hpp +13 -0
- package/android/src/main/cpp/JRollingEngine.cpp +43 -2
- package/android/src/main/cpp/JRollingEngine.hpp +9 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroInputView.kt +20 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatform.kt +284 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroNumberView.kt +113 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextMeasure.kt +25 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/HybridNitroTextView.kt +140 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputPackage.kt +2 -1
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroInputView.kt +69 -10
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroNumberView.kt +522 -130
- package/android/src/main/java/com/margelo/nitro/nitroinput/NitroTextView.kt +868 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/ReflowEngine.kt +21 -0
- package/android/src/main/java/com/margelo/nitro/nitroinput/RollingEngine.kt +14 -2
- package/cpp/RollingEngine.cpp +102 -8
- package/cpp/RollingEngine.hpp +44 -3
- package/cpp/numberformat/HybridNitroNumberFormat.cpp +498 -0
- package/cpp/numberformat/HybridNitroNumberFormat.hpp +74 -0
- package/cpp/numberformat/HybridNitroNumberFormatFactory.hpp +11 -0
- package/cpp/numberformat/NumberFormatCore.cpp +629 -0
- package/cpp/numberformat/NumberFormatCore.hpp +154 -0
- package/cpp/numberformat/NumberFormatProbe.cpp +354 -0
- package/cpp/numberformat/NumberFormatProbe.hpp +63 -0
- package/ios/HybridNitroInputView.swift +15 -0
- package/ios/HybridNitroNumberFormatPlatform.swift +426 -0
- package/ios/HybridNitroNumberView.swift +101 -1
- package/ios/HybridNitroTextView.swift +134 -0
- package/ios/NitroInputView.swift +79 -19
- package/ios/NitroNumberView.swift +520 -147
- package/ios/NitroTextView.swift +583 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroNumberViewConfig.json +26 -0
- package/lib/commonjs/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
- package/lib/commonjs/src/NitroInput.js +8 -6
- package/lib/commonjs/src/NitroNumber.js +54 -3
- package/lib/commonjs/src/NitroText.js +138 -0
- package/lib/commonjs/src/NitroTime.js +65 -0
- package/lib/commonjs/src/NumberFormat.js +525 -0
- package/lib/commonjs/src/formatProps.js +108 -0
- package/lib/commonjs/src/index.js +8 -1
- package/lib/commonjs/src/specs/NitroText.nitro.js +2 -0
- package/lib/commonjs/src/specs/NumberFormat.nitro.js +2 -0
- package/lib/module/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/lib/module/nitrogen/generated/shared/json/NitroNumberViewConfig.json +26 -0
- package/lib/module/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
- package/lib/module/src/NitroInput.js +8 -6
- package/lib/module/src/NitroNumber.js +54 -3
- package/lib/module/src/NitroText.js +98 -0
- package/lib/module/src/NitroTime.js +29 -0
- package/lib/module/src/NumberFormat.js +521 -0
- package/lib/module/src/formatProps.js +104 -0
- package/lib/module/src/index.js +3 -0
- package/lib/module/src/specs/NitroText.nitro.js +1 -0
- package/lib/module/src/specs/NumberFormat.nitro.js +1 -0
- package/lib/typescript/src/NitroInput.d.ts +22 -0
- package/lib/typescript/src/NitroNumber.d.ts +115 -2
- package/lib/typescript/src/NitroText.d.ts +67 -0
- package/lib/typescript/src/NitroTime.d.ts +19 -0
- package/lib/typescript/src/NumberFormat.d.ts +47 -0
- package/lib/typescript/src/formatProps.d.ts +47 -0
- package/lib/typescript/src/index.d.ts +6 -1
- package/lib/typescript/src/specs/NitroInput.nitro.d.ts +10 -0
- package/lib/typescript/src/specs/NitroNumber.nitro.d.ts +80 -1
- package/lib/typescript/src/specs/NitroText.nitro.d.ts +60 -0
- package/lib/typescript/src/specs/NumberFormat.nitro.d.ts +139 -0
- package/nitro.json +36 -0
- package/nitrogen/generated/android/NitroInput+autolinking.cmake +12 -0
- package/nitrogen/generated/android/NitroInputOnLoad.cpp +62 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.cpp +45 -0
- package/nitrogen/generated/android/c++/JHybridNitroInputViewSpec.hpp +10 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberFormatPlatformSpec.cpp +118 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberFormatPlatformSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.cpp +297 -0
- package/nitrogen/generated/android/c++/JHybridNitroNumberViewSpec.hpp +52 -0
- package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.cpp +65 -0
- package/nitrogen/generated/android/c++/JHybridNitroPlatformNumberFormatterSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.cpp +58 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextMeasureSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.cpp +253 -0
- package/nitrogen/generated/android/c++/JHybridNitroTextViewSpec.hpp +104 -0
- package/nitrogen/generated/android/c++/JNitroNumberDirection.hpp +3 -0
- package/nitrogen/generated/android/c++/JNitroNumberShimmerDirection.hpp +61 -0
- package/nitrogen/generated/android/c++/JNitroNumberSignDisplay.hpp +67 -0
- package/nitrogen/generated/android/c++/JNumberFormatCompactDisplay.hpp +58 -0
- package/nitrogen/generated/android/c++/JNumberFormatCurrencyDisplay.hpp +64 -0
- package/nitrogen/generated/android/c++/JNumberFormatCurrencySign.hpp +58 -0
- package/nitrogen/generated/android/c++/JNumberFormatNotation.hpp +64 -0
- package/nitrogen/generated/android/c++/JNumberFormatPlatformOptions.hpp +161 -0
- package/nitrogen/generated/android/c++/JNumberFormatPlatformSymbols.hpp +89 -0
- package/nitrogen/generated/android/c++/JNumberFormatRoundingMode.hpp +79 -0
- package/nitrogen/generated/android/c++/JNumberFormatSignDisplay.hpp +67 -0
- package/nitrogen/generated/android/c++/JNumberFormatStyle.hpp +64 -0
- package/nitrogen/generated/android/c++/JNumberFormatUnitDisplay.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroInputViewStateUpdater.cpp +25 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroNumberViewStateUpdater.cpp +130 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.cpp +174 -0
- package/nitrogen/generated/android/c++/views/JHybridNitroTextViewStateUpdater.hpp +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroInputViewSpec.kt +30 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberFormatPlatformSpec.kt +60 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroNumberViewSpec.kt +172 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroPlatformNumberFormatterSpec.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextMeasureSpec.kt +60 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/HybridNitroTextViewSpec.kt +179 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberDirection.kt +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberShimmerDirection.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NitroNumberSignDisplay.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCompactDisplay.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCurrencyDisplay.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatCurrencySign.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatNotation.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatPlatformOptions.kt +136 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatPlatformSymbols.kt +91 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatRoundingMode.kt +30 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatSignDisplay.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatStyle.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/NumberFormatUnitDisplay.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewManager.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroinput/views/HybridNitroTextViewStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.cpp +68 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Bridge.hpp +184 -0
- package/nitrogen/generated/ios/NitroInput-Swift-Cxx-Umbrella.hpp +56 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.mm +34 -0
- package/nitrogen/generated/ios/NitroInputAutolinking.swift +36 -0
- package/nitrogen/generated/ios/c++/HybridNitroInputViewSpecSwift.hpp +30 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberFormatPlatformSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberFormatPlatformSpecSwift.hpp +122 -0
- package/nitrogen/generated/ios/c++/HybridNitroNumberViewSpecSwift.hpp +188 -0
- package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroPlatformNumberFormatterSpecSwift.hpp +94 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextMeasureSpecSwift.hpp +90 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroTextViewSpecSwift.hpp +233 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroInputViewComponent.mm +30 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroNumberViewComponent.mm +156 -0
- package/nitrogen/generated/ios/c++/views/HybridNitroTextViewComponent.mm +264 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec.swift +5 -0
- package/nitrogen/generated/ios/swift/HybridNitroInputViewSpec_cxx.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberFormatPlatformSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberFormatPlatformSpec_cxx.swift +159 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec.swift +26 -0
- package/nitrogen/generated/ios/swift/HybridNitroNumberViewSpec_cxx.swift +658 -21
- package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroPlatformNumberFormatterSpec_cxx.swift +155 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextMeasureSpec_cxx.swift +150 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec.swift +75 -0
- package/nitrogen/generated/ios/swift/HybridNitroTextViewSpec_cxx.swift +608 -0
- package/nitrogen/generated/ios/swift/NitroNumberDirection.swift +4 -0
- package/nitrogen/generated/ios/swift/NitroNumberShimmerDirection.swift +44 -0
- package/nitrogen/generated/ios/swift/NitroNumberSignDisplay.swift +52 -0
- package/nitrogen/generated/ios/swift/NumberFormatCompactDisplay.swift +40 -0
- package/nitrogen/generated/ios/swift/NumberFormatCurrencyDisplay.swift +48 -0
- package/nitrogen/generated/ios/swift/NumberFormatCurrencySign.swift +40 -0
- package/nitrogen/generated/ios/swift/NumberFormatNotation.swift +48 -0
- package/nitrogen/generated/ios/swift/NumberFormatPlatformOptions.swift +159 -0
- package/nitrogen/generated/ios/swift/NumberFormatPlatformSymbols.swift +69 -0
- package/nitrogen/generated/ios/swift/NumberFormatRoundingMode.swift +68 -0
- package/nitrogen/generated/ios/swift/NumberFormatSignDisplay.swift +52 -0
- package/nitrogen/generated/ios/swift/NumberFormatStyle.swift +48 -0
- package/nitrogen/generated/ios/swift/NumberFormatUnitDisplay.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.cpp +10 -0
- package/nitrogen/generated/shared/c++/HybridNitroInputViewSpec.hpp +10 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatFactorySpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatFactorySpec.hpp +70 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatPlatformSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatPlatformSpec.hpp +70 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberFormatSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.cpp +52 -0
- package/nitrogen/generated/shared/c++/HybridNitroNumberViewSpec.hpp +58 -0
- package/nitrogen/generated/shared/c++/HybridNitroPlatformNumberFormatterSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridNitroPlatformNumberFormatterSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextMeasureSpec.hpp +63 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.cpp +62 -0
- package/nitrogen/generated/shared/c++/HybridNitroTextViewSpec.hpp +115 -0
- package/nitrogen/generated/shared/c++/NitroNumberDirection.hpp +4 -0
- package/nitrogen/generated/shared/c++/NitroNumberShimmerDirection.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroNumberSignDisplay.hpp +88 -0
- package/nitrogen/generated/shared/c++/NumberFormatCompactDisplay.hpp +76 -0
- package/nitrogen/generated/shared/c++/NumberFormatCurrencyDisplay.hpp +84 -0
- package/nitrogen/generated/shared/c++/NumberFormatCurrencySign.hpp +76 -0
- package/nitrogen/generated/shared/c++/NumberFormatGrouping.hpp +80 -0
- package/nitrogen/generated/shared/c++/NumberFormatNotation.hpp +84 -0
- package/nitrogen/generated/shared/c++/NumberFormatOptions.hpp +193 -0
- package/nitrogen/generated/shared/c++/NumberFormatPart.hpp +87 -0
- package/nitrogen/generated/shared/c++/NumberFormatPlatformOptions.hpp +176 -0
- package/nitrogen/generated/shared/c++/NumberFormatPlatformSymbols.hpp +115 -0
- package/nitrogen/generated/shared/c++/NumberFormatRoundingMode.hpp +104 -0
- package/nitrogen/generated/shared/c++/NumberFormatRoundingPriority.hpp +80 -0
- package/nitrogen/generated/shared/c++/NumberFormatSignDisplay.hpp +88 -0
- package/nitrogen/generated/shared/c++/NumberFormatStyle.hpp +84 -0
- package/nitrogen/generated/shared/c++/NumberFormatTrailingZeroDisplay.hpp +76 -0
- package/nitrogen/generated/shared/c++/NumberFormatUnitDisplay.hpp +80 -0
- package/nitrogen/generated/shared/c++/ResolvedNumberFormatOptions.hpp +197 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.cpp +10 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroInputViewComponent.hpp +15 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.cpp +52 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroNumberViewComponent.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.cpp +74 -0
- package/nitrogen/generated/shared/c++/views/HybridNitroTextViewComponent.hpp +149 -0
- package/nitrogen/generated/shared/json/NitroInputViewConfig.json +5 -0
- package/nitrogen/generated/shared/json/NitroNumberViewConfig.json +26 -0
- package/nitrogen/generated/shared/json/NitroTextViewConfig.json +30 -0
- package/package.json +2 -2
- package/src/NitroInput.tsx +42 -7
- package/src/NitroNumber.tsx +236 -12
- package/src/NitroText.tsx +166 -0
- package/src/NitroTime.tsx +68 -0
- package/src/NumberFormat.ts +563 -0
- package/src/formatProps.ts +149 -0
- package/src/index.ts +23 -0
- package/src/specs/NitroInput.nitro.ts +10 -0
- package/src/specs/NitroNumber.nitro.ts +82 -1
- package/src/specs/NitroText.nitro.ts +65 -0
- package/src/specs/NumberFormat.nitro.ts +145 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { NumberFormat, sharedFormatterOf } from './NumberFormat'
|
|
2
|
+
|
|
3
|
+
/** What `NitroNumber` and `NitroInput` take from a `NumberFormat` through their `format` prop. */
|
|
4
|
+
export interface FormatProps {
|
|
5
|
+
prefix: string
|
|
6
|
+
suffix: string
|
|
7
|
+
groupingSeparator: string
|
|
8
|
+
decimalSeparator: string
|
|
9
|
+
/** The digits after the decimal separator: the format's maximum. */
|
|
10
|
+
fractionDigits: number
|
|
11
|
+
minimumIntegerDigits: number
|
|
12
|
+
/** Whether a negative amount's sign comes before the prefix ("-$5") or after it ("$-5"). */
|
|
13
|
+
signPlacement: 'beforeAffix' | 'afterAffix'
|
|
14
|
+
/** Which values carry a sign, as the format's `signDisplay`. */
|
|
15
|
+
signDisplay: 'auto' | 'always' | 'exceptZero' | 'negative' | 'never'
|
|
16
|
+
/** The minus sign the locale writes ("-", or "−" in Swedish and Finnish). */
|
|
17
|
+
minusSign: string
|
|
18
|
+
/** The plus sign the locale writes. */
|
|
19
|
+
plusSign: string
|
|
20
|
+
/** The glyphs for 0…9 in the format's numbering system; empty for Latin digits. */
|
|
21
|
+
digitGlyphs: string[]
|
|
22
|
+
/** The first digit group and every later one, from the decimal point ([3, 2]: 12,34,567). */
|
|
23
|
+
groupingSizes: number[]
|
|
24
|
+
/** Compact notation: the prefix, suffix and digits follow the value (`compactParts`). */
|
|
25
|
+
compact: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const NUMBER_PARTS = new Set(['integer', 'group', 'decimal', 'fraction'])
|
|
29
|
+
// By the native formatter, which instances built with the same locales and options share.
|
|
30
|
+
const cache = new WeakMap<object, FormatProps>()
|
|
31
|
+
|
|
32
|
+
type Part = { type: string; value: string }
|
|
33
|
+
|
|
34
|
+
function join(parts: Part[], from: number, to: number): string {
|
|
35
|
+
return parts
|
|
36
|
+
.slice(from, to)
|
|
37
|
+
.map((p) => p.value)
|
|
38
|
+
.join('')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The text before and after the number in `parts`. */
|
|
42
|
+
function affixes(parts: Part[]): { prefix: string; suffix: string } {
|
|
43
|
+
const first = parts.findIndex((p) => NUMBER_PARTS.has(p.type))
|
|
44
|
+
let last = first
|
|
45
|
+
parts.forEach((p, i) => {
|
|
46
|
+
if (NUMBER_PARTS.has(p.type)) last = i
|
|
47
|
+
})
|
|
48
|
+
// The sign is the component's own glyph, not part of an affix.
|
|
49
|
+
const unsigned = (from: number, to: number) =>
|
|
50
|
+
join(
|
|
51
|
+
parts.map((p) => (p.type === 'minusSign' || p.type === 'plusSign' ? { ...p, value: '' } : p)),
|
|
52
|
+
from,
|
|
53
|
+
to
|
|
54
|
+
)
|
|
55
|
+
return {
|
|
56
|
+
prefix: first < 0 ? '' : unsigned(0, first),
|
|
57
|
+
suffix: first < 0 ? '' : unsigned(last + 1, parts.length),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The prefix, suffix, separators and digit counts of `format`, read off its
|
|
63
|
+
* parts once and cached per formatter. The components keep their own model
|
|
64
|
+
* (a sign, a prefix, digits in groups, a suffix), so a format outside it
|
|
65
|
+
* (accounting parentheses, a unit between the digits) is followed as far as
|
|
66
|
+
* that model goes.
|
|
67
|
+
*/
|
|
68
|
+
export function formatProps(format: NumberFormat): FormatProps {
|
|
69
|
+
const key = sharedFormatterOf(format) ?? format
|
|
70
|
+
const cached = cache.get(key)
|
|
71
|
+
if (cached) return cached
|
|
72
|
+
const resolved = format.resolvedOptions()
|
|
73
|
+
const compact = resolved.notation === 'compact'
|
|
74
|
+
const fractionDigits = resolved.maximumFractionDigits ?? 0
|
|
75
|
+
// A value with every part: groups, and a fraction when the format has one.
|
|
76
|
+
// Compact notation would print it "1.2M", so its affixes come per value.
|
|
77
|
+
const parts = format.formatToParts(compact ? 1 : fractionDigits > 0 ? 1234567.5 : 1234567) as Part[]
|
|
78
|
+
const negative = format.formatToParts(-1) as Part[]
|
|
79
|
+
const minus = negative.findIndex((p) => p.type === 'minusSign')
|
|
80
|
+
const currency = negative.findIndex((p) => p.type === 'currency' || p.type === 'percentSign')
|
|
81
|
+
const integers = parts.filter((p) => p.type === 'integer').map((p) => p.value.length)
|
|
82
|
+
const props: FormatProps = {
|
|
83
|
+
...affixes(parts),
|
|
84
|
+
groupingSeparator: parts.find((p) => p.type === 'group')?.value ?? '',
|
|
85
|
+
decimalSeparator: parts.find((p) => p.type === 'decimal')?.value ?? '.',
|
|
86
|
+
fractionDigits,
|
|
87
|
+
minimumIntegerDigits: resolved.minimumIntegerDigits,
|
|
88
|
+
signPlacement: minus >= 0 && currency >= 0 && minus > currency ? 'afterAffix' : 'beforeAffix',
|
|
89
|
+
signDisplay: (resolved.signDisplay ?? 'auto') as FormatProps['signDisplay'],
|
|
90
|
+
minusSign: negative[minus]?.value ?? '-',
|
|
91
|
+
plusSign: '+',
|
|
92
|
+
digitGlyphs: digitGlyphsOf(resolved.locale, resolved.numberingSystem),
|
|
93
|
+
// "12,34,567": the last group is the first size, the one before it every later one.
|
|
94
|
+
groupingSizes: integers.length >= 3 ? [integers[integers.length - 1]!, integers[integers.length - 2]!] : [3],
|
|
95
|
+
compact,
|
|
96
|
+
}
|
|
97
|
+
cache.set(key, props)
|
|
98
|
+
return props
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const digitGlyphCache = new Map<string, string[]>()
|
|
102
|
+
|
|
103
|
+
/** The ten digits of a numbering system, or [] for Latin ones. */
|
|
104
|
+
function digitGlyphsOf(locale: string, numberingSystem: string | undefined): string[] {
|
|
105
|
+
if (!numberingSystem || numberingSystem === 'latn') return []
|
|
106
|
+
const cached = digitGlyphCache.get(numberingSystem)
|
|
107
|
+
if (cached) return cached
|
|
108
|
+
const digits = new NumberFormat(locale, { numberingSystem, useGrouping: false })
|
|
109
|
+
const glyphs = Array.from({ length: 10 }, (_, d) => digits.format(d))
|
|
110
|
+
const result = glyphs.every((g, d) => g === String(d)) ? [] : glyphs
|
|
111
|
+
digitGlyphCache.set(numberingSystem, result)
|
|
112
|
+
return result
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** What a compact format shows for one value: the figure to roll and the text around it. */
|
|
116
|
+
export interface CompactParts {
|
|
117
|
+
/** The figure as the digits show it: 1.2 for "1.2K". */
|
|
118
|
+
value: number
|
|
119
|
+
fractionDigits: number
|
|
120
|
+
prefix: string
|
|
121
|
+
suffix: string
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Compact notation's parts for `value`: "1.2K" is the figure 1.2 with the
|
|
126
|
+
* suffix "K", so the digits roll and the suffix swaps as the value crosses
|
|
127
|
+
* a thousand, a million…
|
|
128
|
+
*/
|
|
129
|
+
export function compactParts(format: NumberFormat, value: number): CompactParts {
|
|
130
|
+
const parts = format.formatToParts(value) as Part[]
|
|
131
|
+
const props = formatProps(format)
|
|
132
|
+
const latin = (text: string) =>
|
|
133
|
+
props.digitGlyphs.length === 10
|
|
134
|
+
? Array.from(text)
|
|
135
|
+
.map((c) => {
|
|
136
|
+
const d = props.digitGlyphs.indexOf(c)
|
|
137
|
+
return d >= 0 ? String(d) : c
|
|
138
|
+
})
|
|
139
|
+
.join('')
|
|
140
|
+
: text
|
|
141
|
+
const integer = latin(parts.filter((p) => p.type === 'integer').map((p) => p.value).join(''))
|
|
142
|
+
const fraction = latin(parts.filter((p) => p.type === 'fraction').map((p) => p.value).join(''))
|
|
143
|
+
const magnitude = Number(fraction ? `${integer}.${fraction}` : integer)
|
|
144
|
+
return {
|
|
145
|
+
value: (value < 0 ? -1 : 1) * (Number.isFinite(magnitude) ? magnitude : 0),
|
|
146
|
+
fractionDigits: fraction.length,
|
|
147
|
+
...affixes(parts),
|
|
148
|
+
}
|
|
149
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -56,14 +56,37 @@ export {
|
|
|
56
56
|
type NitroNumberHandle,
|
|
57
57
|
type NitroNumberRef,
|
|
58
58
|
} from './NitroNumber'
|
|
59
|
+
export { NitroTime, type NitroTimeProps, type NitroTimeFormat } from './NitroTime'
|
|
60
|
+
export { NitroText, NativeNitroTextView, type NitroTextProps } from './NitroText'
|
|
61
|
+
export type { NitroTextMeasure, NitroTextView } from './specs/NitroText.nitro'
|
|
59
62
|
export type {
|
|
60
63
|
NitroNumberAffixAlign,
|
|
61
64
|
NitroNumberDirection,
|
|
62
65
|
NitroNumberTransition,
|
|
63
66
|
NitroNumberEasing,
|
|
64
67
|
NitroNumberRevealStyle,
|
|
68
|
+
NitroNumberShimmerDirection,
|
|
69
|
+
NitroNumberSignDisplay,
|
|
65
70
|
NitroNumberTextAlign,
|
|
66
71
|
NitroNumberMethods,
|
|
67
72
|
NitroNumberProps as NativeNitroNumberProps,
|
|
68
73
|
NitroNumberView,
|
|
69
74
|
} from './specs/NitroNumber.nitro'
|
|
75
|
+
|
|
76
|
+
export { NumberFormat, type NumberFormatConstructor, type NumberFormatRangePart } from './NumberFormat'
|
|
77
|
+
export type {
|
|
78
|
+
NumberFormatOptions,
|
|
79
|
+
NumberFormatPart,
|
|
80
|
+
ResolvedNumberFormatOptions,
|
|
81
|
+
NumberFormatStyle,
|
|
82
|
+
NumberFormatCurrencyDisplay,
|
|
83
|
+
NumberFormatCurrencySign,
|
|
84
|
+
NumberFormatUnitDisplay,
|
|
85
|
+
NumberFormatNotation,
|
|
86
|
+
NumberFormatCompactDisplay,
|
|
87
|
+
NumberFormatSignDisplay,
|
|
88
|
+
NumberFormatRoundingMode,
|
|
89
|
+
NumberFormatRoundingPriority,
|
|
90
|
+
NumberFormatTrailingZeroDisplay,
|
|
91
|
+
NumberFormatGrouping,
|
|
92
|
+
} from './specs/NumberFormat.nitro'
|
|
@@ -220,6 +220,16 @@ export interface NitroInputProps extends HybridViewProps {
|
|
|
220
220
|
prefixAlign: NitroInputAffixAlign
|
|
221
221
|
/** Vertical alignment of `suffix` relative to the text (the wrapper folds its `affixAlign` into this). */
|
|
222
222
|
suffixAlign: NitroInputAffixAlign
|
|
223
|
+
/** Points added after every glyph, like `Text`'s `letterSpacing`; an affix gets it in proportion to its size. */
|
|
224
|
+
letterSpacing: number
|
|
225
|
+
/** Points between the prefix and the text, in place of the letter spacing there. Not finite: the letter spacing. */
|
|
226
|
+
prefixSpacing: number
|
|
227
|
+
/** Points between the text and the suffix, in place of the letter spacing there. Not finite: the letter spacing. */
|
|
228
|
+
suffixSpacing: number
|
|
229
|
+
/** Points the prefix is moved down after its alignment (negative: up). */
|
|
230
|
+
prefixOffset: number
|
|
231
|
+
/** Points the suffix is moved down after its alignment (negative: up). */
|
|
232
|
+
suffixOffset: number
|
|
223
233
|
/** Shown (and reflowed away) while the field is empty. Default: `''`. */
|
|
224
234
|
placeholder: string
|
|
225
235
|
/** Color of the placeholder as a processed ARGB integer; `NaN` = platform default. */
|
|
@@ -23,7 +23,7 @@ export type NitroNumberEasing =
|
|
|
23
23
|
| 'spring'
|
|
24
24
|
|
|
25
25
|
/** Which way the digits roll: `'auto'` follows the sign of the change. */
|
|
26
|
-
export type NitroNumberDirection = 'auto' | 'up' | 'down'
|
|
26
|
+
export type NitroNumberDirection = 'auto' | 'up' | 'down' | 'shortest'
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* How a value change plays. `'roll'` is the odometer: every changed digit
|
|
@@ -52,6 +52,18 @@ export type NitroNumberRevealStyle = 'count' | 'spin'
|
|
|
52
52
|
*/
|
|
53
53
|
export type NitroNumberAffixAlign = 'baseline' | 'center' | 'top' | 'bottom'
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Which values carry a sign, as `Intl.NumberFormat`'s `signDisplay`:
|
|
57
|
+
* `'auto'` negatives, `'always'` a plus on positives and zero too,
|
|
58
|
+
* `'exceptZero'` a plus or minus on everything but zero, `'negative'`
|
|
59
|
+
* negatives, `'never'` none. A value that rounds to zero at the shown
|
|
60
|
+
* fraction digits counts as zero, so `-0.001` shows no minus.
|
|
61
|
+
*/
|
|
62
|
+
export type NitroNumberSignDisplay = 'auto' | 'always' | 'never' | 'exceptZero' | 'negative'
|
|
63
|
+
|
|
64
|
+
/** Which way the loading shimmer sweeps: `'auto'` follows the layout direction. */
|
|
65
|
+
export type NitroNumberShimmerDirection = 'auto' | 'ltr' | 'rtl'
|
|
66
|
+
|
|
55
67
|
export interface NitroNumberProps extends HybridViewProps {
|
|
56
68
|
/**
|
|
57
69
|
* The number to display.
|
|
@@ -173,6 +185,16 @@ export interface NitroNumberProps extends HybridViewProps {
|
|
|
173
185
|
shimmerColor?: number
|
|
174
186
|
/** Duration of one sweep in ms (linear, repeating). Default: `950`. */
|
|
175
187
|
shimmerDuration?: number
|
|
188
|
+
/** The band's slant in degrees: 0 upright, positive leans it like "/". Default: `31`. */
|
|
189
|
+
shimmerAngle?: number
|
|
190
|
+
/** The band's width as a fraction of the number's. Default: `1`. */
|
|
191
|
+
shimmerWidth?: number
|
|
192
|
+
/** The glyphs' colour while loading, outside the band (processed). Not finite: `color`. */
|
|
193
|
+
shimmerBaseColor?: number
|
|
194
|
+
/** Which way the band sweeps. Default: `'auto'`, the layout direction. */
|
|
195
|
+
shimmerDirection?: NitroNumberShimmerDirection
|
|
196
|
+
/** A pause after each sweep, in ms. Default: `0`. */
|
|
197
|
+
shimmerDelay?: number
|
|
176
198
|
/** Font size of the digits in points. Default: `32`. */
|
|
177
199
|
fontSize?: number
|
|
178
200
|
/** Font size of `prefix` in points. Defaults to `fontSize`. */
|
|
@@ -185,6 +207,58 @@ export interface NitroNumberProps extends HybridViewProps {
|
|
|
185
207
|
prefixAlign?: NitroNumberAffixAlign
|
|
186
208
|
/** Vertical alignment of `suffix` only. Defaults to `affixAlign`. */
|
|
187
209
|
suffixAlign?: NitroNumberAffixAlign
|
|
210
|
+
/** Points added after every glyph, like `Text`'s `letterSpacing`; an affix gets it in proportion to its size. Default: `0`. */
|
|
211
|
+
letterSpacing?: number
|
|
212
|
+
/** Points between the prefix and the digits, in place of the letter spacing there. Not finite: the letter spacing. */
|
|
213
|
+
prefixSpacing?: number
|
|
214
|
+
/** Points between the digits and the suffix, in place of the letter spacing there. Not finite: the letter spacing. */
|
|
215
|
+
suffixSpacing?: number
|
|
216
|
+
/** Points the prefix is moved down after its alignment (negative: up). Default: `0`. */
|
|
217
|
+
prefixOffset?: number
|
|
218
|
+
/** Points the suffix is moved down after its alignment (negative: up). Default: `0`. */
|
|
219
|
+
suffixOffset?: number
|
|
220
|
+
/** Every digit as wide as the widest (`true`, the default), or each digit at its own width. */
|
|
221
|
+
tabularNums?: boolean
|
|
222
|
+
/** Which values carry a sign. Default: `'auto'`. */
|
|
223
|
+
signDisplay?: NitroNumberSignDisplay
|
|
224
|
+
/** The glyph drawn for a plus sign. Default: `'+'`. */
|
|
225
|
+
plusSign?: string
|
|
226
|
+
/** The glyph drawn for a minus sign. Default: `'-'`. */
|
|
227
|
+
minusSign?: string
|
|
228
|
+
/**
|
|
229
|
+
* The ten glyphs drawn for 0 to 9: native digits (Arabic-Indic, Devanagari…).
|
|
230
|
+
* Empty: `'0'`…`'9'`.
|
|
231
|
+
*/
|
|
232
|
+
digitGlyphs?: string[]
|
|
233
|
+
/**
|
|
234
|
+
* Digit group sizes counted from the decimal point: the first group, then
|
|
235
|
+
* every one after it. Empty: `[3]`. `[3, 2]` is Indian grouping
|
|
236
|
+
* (12,34,567), `[2]` a clock's (12:34:56 with `groupingSeparator=":"`).
|
|
237
|
+
*/
|
|
238
|
+
groupingSizes?: number[]
|
|
239
|
+
/**
|
|
240
|
+
* Per integer position (0 the ones, 1 the tens…), the highest digit its
|
|
241
|
+
* wheel shows before it wraps to 0; missing or not 0–8 means 9. `[9, 5]`
|
|
242
|
+
* makes the tens wrap after 5, as on a clock: 59 → 00 turns them one step.
|
|
243
|
+
*/
|
|
244
|
+
digitMax?: number[]
|
|
245
|
+
/**
|
|
246
|
+
* Rolls turn the wheels below the highest one that changes a full turn
|
|
247
|
+
* too, so the figure seems to pass through every value between. Default: `false`.
|
|
248
|
+
*/
|
|
249
|
+
continuous?: boolean
|
|
250
|
+
/** The prefix's color (processed). Not finite: `color`. */
|
|
251
|
+
prefixColor?: number
|
|
252
|
+
/** The suffix's color (processed). Not finite: `color`. */
|
|
253
|
+
suffixColor?: number
|
|
254
|
+
/** The fraction digits' and decimal separator's color (processed). Not finite: `color`. */
|
|
255
|
+
fractionColor?: number
|
|
256
|
+
/** The fraction digits' and decimal separator's size. Not finite: `fontSize`. */
|
|
257
|
+
fractionFontSize?: number
|
|
258
|
+
/** How smaller fraction digits line up with the integer ones. Default: `'baseline'`. */
|
|
259
|
+
fractionAlign?: NitroNumberAffixAlign
|
|
260
|
+
/** Snap instead of animating while the system's Reduce Motion is on. Default: `true`. */
|
|
261
|
+
respectReduceMotion?: boolean
|
|
188
262
|
/**
|
|
189
263
|
* When the view is narrower than the number (e.g. it has a fixed `width` or
|
|
190
264
|
* `maxWidth`), scale the whole number down so it fits. Default: `false`.
|
|
@@ -234,6 +308,13 @@ export interface NitroNumberProps extends HybridViewProps {
|
|
|
234
308
|
* banner, fire the confetti and play the sting.
|
|
235
309
|
*/
|
|
236
310
|
onRevealMilestone?: (index: number, value: number) => void
|
|
311
|
+
/** Called when the figure starts moving from rest (a change, or a reveal). */
|
|
312
|
+
onAnimationStart?: () => void
|
|
313
|
+
/**
|
|
314
|
+
* Called when the figure comes to rest again, with the value it shows:
|
|
315
|
+
* once, however many changes arrived while it was moving.
|
|
316
|
+
*/
|
|
317
|
+
onAnimationEnd?: (value: number) => void
|
|
237
318
|
}
|
|
238
319
|
|
|
239
320
|
export interface NitroNumberMethods extends HybridViewMethods {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HybridObject,
|
|
3
|
+
HybridView,
|
|
4
|
+
HybridViewMethods,
|
|
5
|
+
HybridViewProps,
|
|
6
|
+
} from 'react-native-nitro-modules'
|
|
7
|
+
import type { NitroNumberShimmerDirection, NitroNumberTextAlign } from './NitroNumber.nitro'
|
|
8
|
+
import type { NitroInputEasing, NitroInputEffect } from './NitroInput.nitro'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A single line of text that morphs to the next: the reflow engine's
|
|
12
|
+
* characters drawn in one pass, no text field. `NitroText` measures it (see
|
|
13
|
+
* `NitroTextMeasure`) and gives it its size, so a label lays out in the same
|
|
14
|
+
* commit that mounts it.
|
|
15
|
+
*
|
|
16
|
+
* Everything but the text is optional and the wrapper sends only what was
|
|
17
|
+
* set: each prop that crosses costs a conversion and an allocation per view
|
|
18
|
+
* in the commit, and a label usually sets two or three. The native side holds
|
|
19
|
+
* the defaults, and forgets what the last element set when it is recycled.
|
|
20
|
+
*/
|
|
21
|
+
export interface NitroTextProps extends HybridViewProps {
|
|
22
|
+
text: string
|
|
23
|
+
/** In points, already scaled for the system text size when the wrapper was asked to. Default 17. */
|
|
24
|
+
fontSize?: number
|
|
25
|
+
/** Numeric weight, 100–900. Default 400. */
|
|
26
|
+
fontWeight?: number
|
|
27
|
+
/** Default: the system font. */
|
|
28
|
+
fontFamily?: string
|
|
29
|
+
/** Processed ARGB. Default: the platform label colour. */
|
|
30
|
+
color?: number
|
|
31
|
+
/** Points after every character. */
|
|
32
|
+
letterSpacing?: number
|
|
33
|
+
textAlign?: NitroNumberTextAlign
|
|
34
|
+
rightToLeft?: boolean
|
|
35
|
+
/** Of a morph, in ms. Default 400. */
|
|
36
|
+
duration?: number
|
|
37
|
+
easing?: NitroInputEasing
|
|
38
|
+
bounce?: number
|
|
39
|
+
effect?: NitroInputEffect
|
|
40
|
+
respectReduceMotion?: boolean
|
|
41
|
+
loading?: boolean
|
|
42
|
+
shimmerColor?: number
|
|
43
|
+
shimmerDuration?: number
|
|
44
|
+
shimmerAngle?: number
|
|
45
|
+
shimmerWidth?: number
|
|
46
|
+
shimmerBaseColor?: number
|
|
47
|
+
shimmerDirection?: NitroNumberShimmerDirection
|
|
48
|
+
shimmerDelay?: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface NitroTextMethods extends HybridViewMethods {}
|
|
52
|
+
|
|
53
|
+
export type NitroTextView = HybridView<NitroTextProps, NitroTextMethods>
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Measures a line the way `NitroTextView` lays it out (the sum of each
|
|
57
|
+
* character's advance plus the letter spacing), synchronously, so the
|
|
58
|
+
* component knows its size while it renders.
|
|
59
|
+
*/
|
|
60
|
+
export interface NitroTextMeasure extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
61
|
+
/** The line's width in points. */
|
|
62
|
+
measure(text: string, fontSize: number, fontWeight: number, fontFamily: string, letterSpacing: number): number
|
|
63
|
+
/** The line box's height in points. */
|
|
64
|
+
lineHeight(fontSize: number, fontWeight: number, fontFamily: string): number
|
|
65
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { HybridObject, Int64 } from 'react-native-nitro-modules'
|
|
2
|
+
|
|
3
|
+
// The option types of `Intl.NumberFormat` (ECMA-402), for the native `NumberFormat`.
|
|
4
|
+
|
|
5
|
+
export type NumberFormatStyle = 'decimal' | 'currency' | 'percent' | 'unit'
|
|
6
|
+
export type NumberFormatCurrencyDisplay = 'symbol' | 'narrowSymbol' | 'code' | 'name'
|
|
7
|
+
export type NumberFormatCurrencySign = 'standard' | 'accounting'
|
|
8
|
+
export type NumberFormatUnitDisplay = 'short' | 'narrow' | 'long'
|
|
9
|
+
export type NumberFormatNotation = 'standard' | 'scientific' | 'engineering' | 'compact'
|
|
10
|
+
export type NumberFormatCompactDisplay = 'short' | 'long'
|
|
11
|
+
export type NumberFormatSignDisplay = 'auto' | 'never' | 'always' | 'exceptZero' | 'negative'
|
|
12
|
+
export type NumberFormatRoundingMode = 'ceil' | 'floor' | 'expand' | 'trunc' | 'halfCeil' | 'halfFloor' | 'halfExpand' | 'halfTrunc' | 'halfEven'
|
|
13
|
+
export type NumberFormatRoundingPriority = 'auto' | 'morePrecision' | 'lessPrecision'
|
|
14
|
+
export type NumberFormatTrailingZeroDisplay = 'auto' | 'stripIfInteger'
|
|
15
|
+
export type NumberFormatGrouping = 'always' | 'auto' | 'min2'
|
|
16
|
+
|
|
17
|
+
/** `Intl.NumberFormatOptions`, less `localeMatcher` (the lookup matcher is always used). */
|
|
18
|
+
export interface NumberFormatOptions {
|
|
19
|
+
numberingSystem?: string
|
|
20
|
+
style?: NumberFormatStyle
|
|
21
|
+
currency?: string
|
|
22
|
+
currencyDisplay?: NumberFormatCurrencyDisplay
|
|
23
|
+
currencySign?: NumberFormatCurrencySign
|
|
24
|
+
unit?: string
|
|
25
|
+
unitDisplay?: NumberFormatUnitDisplay
|
|
26
|
+
minimumIntegerDigits?: number
|
|
27
|
+
minimumFractionDigits?: number
|
|
28
|
+
maximumFractionDigits?: number
|
|
29
|
+
minimumSignificantDigits?: number
|
|
30
|
+
maximumSignificantDigits?: number
|
|
31
|
+
roundingPriority?: NumberFormatRoundingPriority
|
|
32
|
+
roundingIncrement?: number
|
|
33
|
+
roundingMode?: NumberFormatRoundingMode
|
|
34
|
+
trailingZeroDisplay?: NumberFormatTrailingZeroDisplay
|
|
35
|
+
notation?: NumberFormatNotation
|
|
36
|
+
compactDisplay?: NumberFormatCompactDisplay
|
|
37
|
+
useGrouping?: boolean | NumberFormatGrouping
|
|
38
|
+
signDisplay?: NumberFormatSignDisplay
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `Intl.ResolvedNumberFormatOptions`. */
|
|
42
|
+
export interface ResolvedNumberFormatOptions {
|
|
43
|
+
locale: string
|
|
44
|
+
numberingSystem: string
|
|
45
|
+
style: NumberFormatStyle
|
|
46
|
+
currency?: string
|
|
47
|
+
currencyDisplay?: NumberFormatCurrencyDisplay
|
|
48
|
+
currencySign?: NumberFormatCurrencySign
|
|
49
|
+
unit?: string
|
|
50
|
+
unitDisplay?: NumberFormatUnitDisplay
|
|
51
|
+
minimumIntegerDigits: number
|
|
52
|
+
minimumFractionDigits?: number
|
|
53
|
+
maximumFractionDigits?: number
|
|
54
|
+
minimumSignificantDigits?: number
|
|
55
|
+
maximumSignificantDigits?: number
|
|
56
|
+
useGrouping: boolean | NumberFormatGrouping
|
|
57
|
+
notation: NumberFormatNotation
|
|
58
|
+
compactDisplay?: NumberFormatCompactDisplay
|
|
59
|
+
signDisplay: NumberFormatSignDisplay
|
|
60
|
+
roundingIncrement: number
|
|
61
|
+
roundingMode: NumberFormatRoundingMode
|
|
62
|
+
roundingPriority: NumberFormatRoundingPriority
|
|
63
|
+
trailingZeroDisplay: NumberFormatTrailingZeroDisplay
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** One piece of a formatted number, as `Intl.NumberFormat#formatToParts` reports it. */
|
|
67
|
+
export interface NumberFormatPart {
|
|
68
|
+
type: string
|
|
69
|
+
value: string
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A number formatter with the API of `Intl.NumberFormat`. It learns a
|
|
74
|
+
* locale's format once from the platform (Foundation on iOS, ICU on Android)
|
|
75
|
+
* and formats in C++ from then on, without calling into the platform per
|
|
76
|
+
* number. Instances are immutable and shared: the same locales and options
|
|
77
|
+
* return the same object.
|
|
78
|
+
*/
|
|
79
|
+
export interface NitroNumberFormat extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
|
|
80
|
+
format(value: number | Int64 | string): string
|
|
81
|
+
formatToParts(value: number | Int64 | string): NumberFormatPart[]
|
|
82
|
+
resolvedOptions(): ResolvedNumberFormatOptions
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface NitroNumberFormatFactory extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
|
|
86
|
+
create(locales: string[], options: NumberFormatOptions): NitroNumberFormat
|
|
87
|
+
supportedLocalesOf(locales: string[]): string[]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// The platform side, used by the C++ formatter only: builds the system's own
|
|
92
|
+
// formatter for a configuration, so C++ can learn the locale's format from it,
|
|
93
|
+
// and formats with it where C++ does not (compact and scientific notation,
|
|
94
|
+
// units, currency names).
|
|
95
|
+
|
|
96
|
+
export interface NumberFormatPlatformOptions {
|
|
97
|
+
locales: string[]
|
|
98
|
+
numberingSystem?: string
|
|
99
|
+
style: NumberFormatStyle
|
|
100
|
+
currency?: string
|
|
101
|
+
currencyDisplay: NumberFormatCurrencyDisplay
|
|
102
|
+
currencySign: NumberFormatCurrencySign
|
|
103
|
+
unit?: string
|
|
104
|
+
unitDisplay: NumberFormatUnitDisplay
|
|
105
|
+
notation: NumberFormatNotation
|
|
106
|
+
compactDisplay: NumberFormatCompactDisplay
|
|
107
|
+
useGrouping: boolean
|
|
108
|
+
minimumIntegerDigits: number
|
|
109
|
+
minimumFractionDigits: number
|
|
110
|
+
maximumFractionDigits: number
|
|
111
|
+
/** 0 when significant digits are not used. */
|
|
112
|
+
minimumSignificantDigits: number
|
|
113
|
+
maximumSignificantDigits: number
|
|
114
|
+
roundingMode: NumberFormatRoundingMode
|
|
115
|
+
signDisplay: NumberFormatSignDisplay
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface NumberFormatPlatformSymbols {
|
|
119
|
+
/** The locale the platform resolved the request to, as a BCP 47 tag. */
|
|
120
|
+
locale: string
|
|
121
|
+
numberingSystem: string
|
|
122
|
+
minusSign: string
|
|
123
|
+
plusSign: string
|
|
124
|
+
percentSign: string
|
|
125
|
+
/** The currency as this formatter shows it (symbol, narrow symbol or code). */
|
|
126
|
+
currency: string
|
|
127
|
+
/** The locale's symbol for NaN. */
|
|
128
|
+
nan: string
|
|
129
|
+
/** The locale's symbol for infinity, without a sign. */
|
|
130
|
+
infinity: string
|
|
131
|
+
/** The "E" of scientific notation. */
|
|
132
|
+
exponentSeparator: string
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface NitroPlatformNumberFormatter extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
136
|
+
readonly symbols: NumberFormatPlatformSymbols
|
|
137
|
+
format(value: number): string
|
|
138
|
+
/** A decimal string, formatted without going through a double. */
|
|
139
|
+
formatDecimal(value: string): string
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface NitroNumberFormatPlatform extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
143
|
+
create(options: NumberFormatPlatformOptions): NitroPlatformNumberFormatter
|
|
144
|
+
supportedLocalesOf(locales: string[]): string[]
|
|
145
|
+
}
|