@ni/unit-format 0.0.1 → 1.0.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/README.md +72 -72
- package/dist/esm/decimal/index.js.map +1 -1
- package/dist/esm/default/index.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/scaled-unit/index.js.map +1 -1
- package/dist/esm/scaled-unit-format/index.js.map +1 -1
- package/dist/esm/scaled-unit-format/intl-number-format/index.js.map +1 -1
- package/dist/esm/scaled-unit-format/manually-translated/index.js.map +1 -1
- package/dist/esm/unit-scale/byte/index.js.map +1 -1
- package/dist/esm/unit-scale/byte-1024/index.js.map +1 -1
- package/dist/esm/unit-scale/celsius/index.js.map +1 -1
- package/dist/esm/unit-scale/fahrenheit/index.js.map +1 -1
- package/dist/esm/unit-scale/index.js.map +1 -1
- package/dist/esm/unit-scale/passthrough/index.js.map +1 -1
- package/dist/esm/unit-scale/utilities/metric-prefixes.js.map +1 -1
- package/dist/esm/unit-scale/volt/index.js.map +1 -1
- package/package.json +72 -64
package/README.md
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<p><b>ni | unit format</b></p>
|
|
3
|
-
</div>
|
|
4
|
-
|
|
5
|
-
# Unit Format
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/@ni/unit-format)
|
|
8
|
-
|
|
9
|
-
The `@ni/unit-format` library provides a way to format numbers with units. The library:
|
|
10
|
-
|
|
11
|
-
- Provides opinionated number formatters that are well-suited for:
|
|
12
|
-
- numbers that can appear in large ranges (very small or very large).
|
|
13
|
-
- numbers that are always decimal with a configurable number of digits.
|
|
14
|
-
- Can scale number values on a unit scale, for example, a metric scale of voltage.
|
|
15
|
-
- Provides internationalized number formatting and unit strings.
|
|
16
|
-
|
|
17
|
-
The library is intended to align well with the [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) API to make it relatively straightforward to swap in.
|
|
18
|
-
|
|
19
|
-
## Getting Started
|
|
20
|
-
|
|
21
|
-
Choose a `UnitFormat` and create an instance with an optional `UnitScale` reference:
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
const formatter = new UnitFormatDefault('en', {
|
|
25
|
-
unitScale: unitScaleByte
|
|
26
|
-
});
|
|
27
|
-
console.log(formatter.format(1000));
|
|
28
|
-
// Output: '1 kB'
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Concepts
|
|
32
|
-
|
|
33
|
-
### UnitFormat
|
|
34
|
-
|
|
35
|
-
There are multiple `UnitFormat`s that represent different configurations for formatting numbers. These represent wrappers around `Intl.NumberFormat` with opinionated configurations.
|
|
36
|
-
|
|
37
|
-
For example, the `UnitFormatDefault` will represent "very large" and "very small" numbers with an exponential notation and numbers between those ranges as decimal. The different `UnitFormat`s take an optional `unitScale` that provides units and automatic conversions of numbers for that unit scale.
|
|
38
|
-
|
|
39
|
-
### UnitScale
|
|
40
|
-
|
|
41
|
-
A `UnitScale` represents a collection of `ScaledUnits` where a scale factor is used to define each scaled unit. Each `UnitScale` must have a "base" `ScaledUnit` with scale factor 1. For example, a byte `UnitScale` may contain:
|
|
42
|
-
|
|
43
|
-
- a `ScaledUnit` of scale factor 1 representing bytes (the base `ScaledUnit`)
|
|
44
|
-
- a `ScaledUnit` of scale factor 1000 representing kilobytes.
|
|
45
|
-
|
|
46
|
-
Each `ScaledUnit` represents a scale factor and a factory function for creating a `ScaledUnitFormat` instance. This system is used so that the top-level `UnitFormat` objects can pass configuration settings to individual `ScaledUnitFormat` instances.
|
|
47
|
-
|
|
48
|
-
## ScaledUnitFormat
|
|
49
|
-
|
|
50
|
-
A `ScaledUnitFormat` is an object for formatting a particular `ScaledUnit` on the `UnitScale`.
|
|
51
|
-
|
|
52
|
-
There are two main types of `ScaledUnitFormat`s:
|
|
53
|
-
|
|
54
|
-
- `ScaledUnitFormatIntlNumberFormat` which are scaled units can be translated by [`Intl.NumberFormat`](https://tc39.es/ecma402/#table-sanctioned-single-unit-identifiers).
|
|
55
|
-
- `ScaledUnitFormatManuallyTranslated` which are scaled units manually translated for a set of supported languages via `UnitTranslation` string collections.
|
|
56
|
-
|
|
57
|
-
The different `ScaledUnitFormat` objects have a static function to assist with their factory creation, for example:
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
new ScaledUnit(
|
|
61
|
-
10 ** 3,
|
|
62
|
-
ScaledUnitFormatIntlNumberFormat.createFactory({
|
|
63
|
-
style: 'unit',
|
|
64
|
-
unit: 'kilobyte',
|
|
65
|
-
unitDisplay: 'short'
|
|
66
|
-
})
|
|
67
|
-
),
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Contributing
|
|
71
|
-
|
|
72
|
-
See `Getting Started` in [`CONTRIBUTING.md`](/packages/unit-format/CONTRIBUTING.md#getting-started).
|
|
1
|
+
<div align="center">
|
|
2
|
+
<p><b>ni | unit format</b></p>
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
# Unit Format
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@ni/unit-format)
|
|
8
|
+
|
|
9
|
+
The `@ni/unit-format` library provides a way to format numbers with units. The library:
|
|
10
|
+
|
|
11
|
+
- Provides opinionated number formatters that are well-suited for:
|
|
12
|
+
- numbers that can appear in large ranges (very small or very large).
|
|
13
|
+
- numbers that are always decimal with a configurable number of digits.
|
|
14
|
+
- Can scale number values on a unit scale, for example, a metric scale of voltage.
|
|
15
|
+
- Provides internationalized number formatting and unit strings.
|
|
16
|
+
|
|
17
|
+
The library is intended to align well with the [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) API to make it relatively straightforward to swap in.
|
|
18
|
+
|
|
19
|
+
## Getting Started
|
|
20
|
+
|
|
21
|
+
Choose a `UnitFormat` and create an instance with an optional `UnitScale` reference:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const formatter = new UnitFormatDefault('en', {
|
|
25
|
+
unitScale: unitScaleByte
|
|
26
|
+
});
|
|
27
|
+
console.log(formatter.format(1000));
|
|
28
|
+
// Output: '1 kB'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Concepts
|
|
32
|
+
|
|
33
|
+
### UnitFormat
|
|
34
|
+
|
|
35
|
+
There are multiple `UnitFormat`s that represent different configurations for formatting numbers. These represent wrappers around `Intl.NumberFormat` with opinionated configurations.
|
|
36
|
+
|
|
37
|
+
For example, the `UnitFormatDefault` will represent "very large" and "very small" numbers with an exponential notation and numbers between those ranges as decimal. The different `UnitFormat`s take an optional `unitScale` that provides units and automatic conversions of numbers for that unit scale.
|
|
38
|
+
|
|
39
|
+
### UnitScale
|
|
40
|
+
|
|
41
|
+
A `UnitScale` represents a collection of `ScaledUnits` where a scale factor is used to define each scaled unit. Each `UnitScale` must have a "base" `ScaledUnit` with scale factor 1. For example, a byte `UnitScale` may contain:
|
|
42
|
+
|
|
43
|
+
- a `ScaledUnit` of scale factor 1 representing bytes (the base `ScaledUnit`)
|
|
44
|
+
- a `ScaledUnit` of scale factor 1000 representing kilobytes.
|
|
45
|
+
|
|
46
|
+
Each `ScaledUnit` represents a scale factor and a factory function for creating a `ScaledUnitFormat` instance. This system is used so that the top-level `UnitFormat` objects can pass configuration settings to individual `ScaledUnitFormat` instances.
|
|
47
|
+
|
|
48
|
+
## ScaledUnitFormat
|
|
49
|
+
|
|
50
|
+
A `ScaledUnitFormat` is an object for formatting a particular `ScaledUnit` on the `UnitScale`.
|
|
51
|
+
|
|
52
|
+
There are two main types of `ScaledUnitFormat`s:
|
|
53
|
+
|
|
54
|
+
- `ScaledUnitFormatIntlNumberFormat` which are scaled units can be translated by [`Intl.NumberFormat`](https://tc39.es/ecma402/#table-sanctioned-single-unit-identifiers).
|
|
55
|
+
- `ScaledUnitFormatManuallyTranslated` which are scaled units manually translated for a set of supported languages via `UnitTranslation` string collections.
|
|
56
|
+
|
|
57
|
+
The different `ScaledUnitFormat` objects have a static function to assist with their factory creation, for example:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
new ScaledUnit(
|
|
61
|
+
10 ** 3,
|
|
62
|
+
ScaledUnitFormatIntlNumberFormat.createFactory({
|
|
63
|
+
style: 'unit',
|
|
64
|
+
unit: 'kilobyte',
|
|
65
|
+
unitDisplay: 'short'
|
|
66
|
+
})
|
|
67
|
+
),
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Contributing
|
|
71
|
+
|
|
72
|
+
See `Getting Started` in [`CONTRIBUTING.md`](/packages/unit-format/CONTRIBUTING.md#getting-started).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decimal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,aAAa,CAAC;AAGjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAQ1E;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAoC;IAOvE,YACI,MAAc,EACd,EACI,qBAAqB,GAAG,CAAC,EACzB,qBAAqB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC,EAC1D,SAAS,GAAG,oBAAoB,KACN;QAC1B,qBAAqB,EAAE,CAAC;QACxB,qBAAqB,EAAE,CAAC;QACxB,SAAS,EAAE,oBAAoB;KAClC;QAED,KAAK,EAAE,CAAC;QAdK,yBAAoB,GAAG,IAAI,GAAG,EAA4B,CAAC;QAexE,uFAAuF;QACvF,4EAA4E;QAC5E,6FAA6F;QAC7F,MAAM,WAAW,GAAG,UAAqD,CAAC;QAC1E,MAAM,uBAAuB,GAAG;YAC5B,qBAAqB;YACrB,qBAAqB;YACrB,WAAW;SACd,CAAC;QACF,KAAK,MAAM,UAAU,IAAI,SAAS,CAAC,oBAAoB,EAAE,CAAC;YACtD,IAAI,CAAC,oBAAoB,CAAC,GAAG,CACzB,UAAU,CAAC,WAAW,EACtB,UAAU,CAAC,uBAAuB,CAAC;gBAC/B,MAAM;gBACN,uBAAuB;aAC1B,CAAC,CACL,CAAC;QACN,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACvD,CAAC;IAEe,eAAe;QAC3B,OAAO;YACH,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;YACjD,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;SACpD,CAAC;IACN,CAAC;IAES,SAAS,CAAC,MAAc;QAC9B,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACvE,MAAM,mBAAmB,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,CACrD,UAAU,CAAC,WAAW,CACxB,CAAC;QACH,OAAO,mBAAmB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;CACJ","sourcesContent":["import { UnitFormat, type UnitFormatOptions } from '../index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decimal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,aAAa,CAAC;AAGjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAQ1E;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAoC;IAOvE,YACI,MAAc,EACd,EACI,qBAAqB,GAAG,CAAC,EACzB,qBAAqB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC,EAC1D,SAAS,GAAG,oBAAoB,KACN;QAC1B,qBAAqB,EAAE,CAAC;QACxB,qBAAqB,EAAE,CAAC;QACxB,SAAS,EAAE,oBAAoB;KAClC;QAED,KAAK,EAAE,CAAC;QAdK,yBAAoB,GAAG,IAAI,GAAG,EAA4B,CAAC;QAexE,uFAAuF;QACvF,4EAA4E;QAC5E,6FAA6F;QAC7F,MAAM,WAAW,GAAG,UAAqD,CAAC;QAC1E,MAAM,uBAAuB,GAAG;YAC5B,qBAAqB;YACrB,qBAAqB;YACrB,WAAW;SACd,CAAC;QACF,KAAK,MAAM,UAAU,IAAI,SAAS,CAAC,oBAAoB,EAAE,CAAC;YACtD,IAAI,CAAC,oBAAoB,CAAC,GAAG,CACzB,UAAU,CAAC,WAAW,EACtB,UAAU,CAAC,uBAAuB,CAAC;gBAC/B,MAAM;gBACN,uBAAuB;aAC1B,CAAC,CACL,CAAC;QACN,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACvD,CAAC;IAEe,eAAe;QAC3B,OAAO;YACH,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;YACjD,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;SACpD,CAAC;IACN,CAAC;IAES,SAAS,CAAC,MAAc;QAC9B,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACvE,MAAM,mBAAmB,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,CACrD,UAAU,CAAC,WAAW,CACxB,CAAC;QACH,OAAO,mBAAmB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;CACJ","sourcesContent":["import { UnitFormat, type UnitFormatOptions } from '../index.js';\nimport type { ScaledUnitFormat } from '../scaled-unit-format/index.js';\nimport type { UnitScale } from '../unit-scale/index.js';\nimport { unitScalePassthrough } from '../unit-scale/passthrough/index.js';\n\ninterface UnitFormatDecimalOptions extends UnitFormatOptions {\n minimumFractionDigits?: number;\n maximumFractionDigits?: number;\n}\ntype UnitFormatDecimalResolvedOptions = Required<UnitFormatDecimalOptions>;\n\n/**\n * Format for decimal numbers with units.\n */\nexport class UnitFormatDecimal extends UnitFormat<UnitFormatDecimalOptions> {\n private readonly unitScale: UnitScale;\n private readonly minimumFractionDigits: number;\n private readonly maximumFractionDigits: number;\n\n private readonly scaledUnitFormatters = new Map<number, ScaledUnitFormat>();\n\n public constructor(\n locale: string,\n {\n minimumFractionDigits = 0,\n maximumFractionDigits = Math.max(3, minimumFractionDigits),\n unitScale = unitScalePassthrough\n }: UnitFormatDecimalOptions = {\n minimumFractionDigits: 0,\n maximumFractionDigits: 3,\n unitScale: unitScalePassthrough\n }\n ) {\n super();\n // Workaround to avoid a ts error about signDisplay not accepting the value 'negative'.\n // It has been supported by browsers since 8/23, but TypeScript still hasn't\n // added it to the type definitions. See https://github.com/microsoft/TypeScript/issues/56269\n const signDisplay = 'negative' as Intl.NumberFormatOptions['signDisplay'];\n const intlNumberFormatOptions = {\n maximumFractionDigits,\n minimumFractionDigits,\n signDisplay\n };\n for (const scaledUnit of unitScale.supportedScaledUnits) {\n this.scaledUnitFormatters.set(\n scaledUnit.scaleFactor,\n scaledUnit.scaledUnitFormatFactory({\n locale,\n intlNumberFormatOptions\n })\n );\n }\n this.unitScale = unitScale;\n this.minimumFractionDigits = minimumFractionDigits;\n this.maximumFractionDigits = maximumFractionDigits;\n }\n\n public override resolvedOptions(): UnitFormatDecimalResolvedOptions {\n return {\n unitScale: this.unitScale,\n maximumFractionDigits: this.maximumFractionDigits,\n minimumFractionDigits: this.minimumFractionDigits\n };\n }\n\n protected tryFormat(number: number): string {\n const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);\n const scaledUnitFormatter = this.scaledUnitFormatters.get(\n scaledUnit.scaleFactor\n )!;\n return scaledUnitFormatter.format(scaledValue);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|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CAAC;IAEe,eAAe;QAC3B,OAAO;YACH,SAAS,EAAE,IAAI,CAAC,SAAS;SAC5B,CAAC;IACN,CAAC;IAES,SAAS,CAAC,MAAc;QAC9B,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEvE,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAC5C,MAAM,cAAc,GAAG,aAAa,KAAK,CAAC;eACnC,CAAC,aAAa,IAAI,iBAAiB,CAAC,qBAAqB;mBACrD,aAAa,GAAG,iBAAiB,CAAC,qBAAqB,CAAC,CAAC;QACpE,OAAO,cAAc;YACjB,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,MAAM,CAAC,MAAM,CAAC;YACpD,CAAC,CAAC,IAAI,CAAC,2BAA2B;iBAC7B,GAAG,CAAC,UAAU,CAAC,WAAW,CAAE;iBAC5B,MAAM,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC;;AA7ED,4EAA4E;AACpD,+BAAa,GAAG,CAAC,AAAJ,CAAK;AAE1C,wFAAwF;AACxF,0FAA0F;AAC1F,yEAAyE;AACjD,uCAAqB,GAAG,QAAQ,AAAX,CAAY;AAEzD,uFAAuF;AACvF,yBAAyB;AACD,uCAAqB,GAAG,QAAQ,AAAX,CAAY","sourcesContent":["import { UnitFormat, type UnitFormatOptions } from '../index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/default/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,aAAa,CAAC;AAGjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,sFAAsF;AACtF,4EAA4E;AAC5E,6FAA6F;AAC7F,MAAM,WAAW,GAAG,UAAqD,CAAC;AAO1E;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAqC7C,YACI,M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;eACnC,CAAC,aAAa,IAAI,iBAAiB,CAAC,qBAAqB;mBACrD,aAAa,GAAG,iBAAiB,CAAC,qBAAqB,CAAC,CAAC;QACpE,OAAO,cAAc;YACjB,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,MAAM,CAAC,MAAM,CAAC;YACpD,CAAC,CAAC,IAAI,CAAC,2BAA2B;iBAC7B,GAAG,CAAC,UAAU,CAAC,WAAW,CAAE;iBAC5B,MAAM,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC;;AA7ED,4EAA4E;AACpD,+BAAa,GAAG,CAAC,AAAJ,CAAK;AAE1C,wFAAwF;AACxF,0FAA0F;AAC1F,yEAAyE;AACjD,uCAAqB,GAAG,QAAQ,AAAX,CAAY;AAEzD,uFAAuF;AACvF,yBAAyB;AACD,uCAAqB,GAAG,QAAQ,AAAX,CAAY","sourcesContent":["import { UnitFormat, type UnitFormatOptions } from '../index.js';\nimport type { ScaledUnitFormat } from '../scaled-unit-format/index.js';\nimport type { UnitScale } from '../unit-scale/index.js';\nimport { unitScalePassthrough } from '../unit-scale/passthrough/index.js';\n\n// Workaround to avoid ts errors about signDisplay not accepting the value 'negative'.\n// It has been supported by browsers since 8/23, but TypeScript still hasn't\n// added it to the type definitions. See https://github.com/microsoft/TypeScript/issues/56269\nconst signDisplay = 'negative' as Intl.NumberFormatOptions['signDisplay'];\n\n// Allow consistent pattern for defining Options and ResolvedOptions\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\ninterface UnitFormatDefaultOptions extends UnitFormatOptions {}\ntype UnitFormatDefaultResolvedOptions = Required<UnitFormatDefaultOptions>;\n\n/**\n * Format for numbers with units to show in a tabular form.\n * Large and tiny numbers are shown exponentially and the rest as decimal.\n */\nexport class UnitFormatDefault extends UnitFormat {\n // The maximum number of digits that should be rendered for any given value.\n private static readonly maximumDigits = 6;\n\n // Use exponential notation for numbers that will be rendered with 3 leading 0s or more.\n // Because a maximum of 6 digits are rendered, showing more than 3 leading 0s is not ideal\n // because then at least half of the displayed digits will be leading 0s.\n private static readonly exponentialLowerBound = 0.000995;\n\n // Use exponential formatting for numbers whose magnitude cannot otherwise be displayed\n // with 6 digits or less.\n private static readonly exponentialUpperBound = 999999.5;\n\n private readonly unitScale: UnitScale;\n // Format options to use by default. It renders the number with a maximum of 6 signficant digits (including zero before decimal point).\n private readonly defaultIntlNumberFormatOptions: Intl.NumberFormatOptions = {\n maximumSignificantDigits: UnitFormatDefault.maximumDigits,\n maximumFractionDigits: UnitFormatDefault.maximumDigits - 1,\n roundingPriority: 'lessPrecision',\n signDisplay\n };\n\n private readonly defaultScaledUnitFormatters = new Map<\n number,\n ScaledUnitFormat\n >();\n\n // Format options for numbers that should be displayed in exponential notation. This should be used\n // for numbers with magintudes over 'exponentialUpperBound' or under 'exponentialLowerBound'.\n private readonly exponentialIntlNumberFormatOptions: Intl.NumberFormatOptions = {\n maximumSignificantDigits: UnitFormatDefault.maximumDigits,\n notation: 'scientific',\n signDisplay\n };\n\n private readonly exponentialScaledUnitFormatter: ScaledUnitFormat;\n\n public constructor(\n locale: string,\n { unitScale = unitScalePassthrough }: UnitFormatDefaultOptions = {\n unitScale: unitScalePassthrough\n }\n ) {\n super();\n for (const unit of unitScale.supportedScaledUnits) {\n this.defaultScaledUnitFormatters.set(\n unit.scaleFactor,\n unit.scaledUnitFormatFactory({\n locale,\n intlNumberFormatOptions: this.defaultIntlNumberFormatOptions\n })\n );\n }\n this.exponentialScaledUnitFormatter = unitScale.baseScaledUnit.scaledUnitFormatFactory({\n locale,\n intlNumberFormatOptions: this.exponentialIntlNumberFormatOptions\n });\n this.unitScale = unitScale;\n }\n\n public override resolvedOptions(): UnitFormatDefaultResolvedOptions {\n return {\n unitScale: this.unitScale\n };\n }\n\n protected tryFormat(number: number): string {\n const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);\n\n const absoluteValue = Math.abs(scaledValue);\n const useExponential = absoluteValue !== 0\n && (absoluteValue >= UnitFormatDefault.exponentialUpperBound\n || absoluteValue < UnitFormatDefault.exponentialLowerBound);\n return useExponential\n ? this.exponentialScaledUnitFormatter.format(number)\n : this.defaultScaledUnitFormatters\n .get(scaledUnit.scaleFactor)!\n .format(scaledValue);\n }\n}\n"]}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,OAAgB,UAAU;IAG5B;;;OAGG;IACI,MAAM,CAAC,KAAgC;QAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,EAAE,CAAC;QACd,CAAC;QAED,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC;CAKJ","sourcesContent":["import type { UnitScale } from './unit-scale/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,OAAgB,UAAU;IAG5B;;;OAGG;IACI,MAAM,CAAC,KAAgC;QAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,EAAE,CAAC;QACd,CAAC;QAED,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC;CAKJ","sourcesContent":["import type { UnitScale } from './unit-scale/index.js';\n\nexport interface UnitFormatOptions {\n unitScale?: UnitScale;\n}\n\n/**\n * The base class for unit formats.\n */\nexport abstract class UnitFormat<\n Options extends UnitFormatOptions = UnitFormatOptions\n> {\n /**\n * Formats a number value to a string.\n * For nullish values or values that result in an exception being thrown, empty string is returned\n */\n public format(value: number | undefined | null): string {\n if (typeof value !== 'number') {\n return '';\n }\n\n try {\n return this.tryFormat(value);\n } catch {\n return '';\n }\n }\n\n public abstract resolvedOptions(): Required<Options>;\n\n protected abstract tryFormat(number: number): string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scaled-unit/index.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB,YACoB,WAAmB,EACnB,uBAAgD;QADhD,gBAAW,GAAX,WAAW,CAAQ;QACnB,4BAAuB,GAAvB,uBAAuB,CAAyB;IACjE,CAAC;IAEG,MAAM;QACT,OAAO,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC;IAClC,CAAC;CACJ","sourcesContent":["import type { ScaledUnitFormat } from '../scaled-unit-format/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scaled-unit/index.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB,YACoB,WAAmB,EACnB,uBAAgD;QADhD,gBAAW,GAAX,WAAW,CAAQ;QACnB,4BAAuB,GAAvB,uBAAuB,CAAyB;IACjE,CAAC;IAEG,MAAM;QACT,OAAO,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC;IAClC,CAAC;CACJ","sourcesContent":["import type { ScaledUnitFormat } from '../scaled-unit-format/index.js';\n\nexport interface ScaledUnitFormatFactoryOptions {\n readonly locale: string;\n readonly intlNumberFormatOptions?: Intl.NumberFormatOptions;\n}\n\ntype ScaledUnitFormatFactory = (\n scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions\n) => ScaledUnitFormat;\n\n/**\n * A unit that represents a scaled version of a base unit.\n */\nexport class ScaledUnit {\n public constructor(\n public readonly scaleFactor: number,\n public readonly scaledUnitFormatFactory: ScaledUnitFormatFactory\n ) {}\n\n public isBase(): boolean {\n return this.scaleFactor === 1;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scaled-unit-format/index.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAgB,gBAAgB;IAIlC,YACI,8BAA8D;QAE9D,IAAI,CAAC,MAAM,GAAG,8BAA8B,CAAC,MAAM,CAAC;QACpD,IAAI,CAAC,uBAAuB,GAAG,8BAA8B,CAAC,uBAAuB,CAAC;IAC1F,CAAC;CAGJ","sourcesContent":["import type { ScaledUnitFormatFactoryOptions } from '../scaled-unit/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scaled-unit-format/index.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAgB,gBAAgB;IAIlC,YACI,8BAA8D;QAE9D,IAAI,CAAC,MAAM,GAAG,8BAA8B,CAAC,MAAM,CAAC;QACpD,IAAI,CAAC,uBAAuB,GAAG,8BAA8B,CAAC,uBAAuB,CAAC;IAC1F,CAAC;CAGJ","sourcesContent":["import type { ScaledUnitFormatFactoryOptions } from '../scaled-unit/index.js';\n\n/**\n * A class that knows how to format a numeric value as a string that includes units.\n */\nexport abstract class ScaledUnitFormat {\n protected readonly locale: string;\n protected readonly intlNumberFormatOptions?: Intl.NumberFormatOptions;\n\n protected constructor(\n scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions\n ) {\n this.locale = scaledUnitFormatFactoryOptions.locale;\n this.intlNumberFormatOptions = scaledUnitFormatFactoryOptions.intlNumberFormatOptions;\n }\n\n public abstract format(value: number): string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/scaled-unit-format/intl-number-format/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,gCAAiC,SAAQ,gBAAgB;IAGlE,YACI,8BAA8D,EAC9D,mCAA6D;QAE7D,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE;YAChD,GAAG,mCAAmC;YACtC,gEAAgE;YAChE,GAAG,IAAI,CAAC,uBAAuB;SAClC,CAAC,CAAC;IACP,CAAC;IAEM,MAAM,CAAC,aAAa,CACvB,mCAA6D;QAE7D,OAAO,CACH,8BAA8D,EAC9B,EAAE,CAAC,IAAI,gCAAgC,CACvE,8BAA8B,EAC9B,mCAAmC,CACtC,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,KAAa;QACvB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACJ","sourcesContent":["import type { ScaledUnitFormatFactoryOptions } from '../../scaled-unit/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/scaled-unit-format/intl-number-format/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,gCAAiC,SAAQ,gBAAgB;IAGlE,YACI,8BAA8D,EAC9D,mCAA6D;QAE7D,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE;YAChD,GAAG,mCAAmC;YACtC,gEAAgE;YAChE,GAAG,IAAI,CAAC,uBAAuB;SAClC,CAAC,CAAC;IACP,CAAC;IAEM,MAAM,CAAC,aAAa,CACvB,mCAA6D;QAE7D,OAAO,CACH,8BAA8D,EAC9B,EAAE,CAAC,IAAI,gCAAgC,CACvE,8BAA8B,EAC9B,mCAAmC,CACtC,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,KAAa;QACvB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACJ","sourcesContent":["import type { ScaledUnitFormatFactoryOptions } from '../../scaled-unit/index.js';\nimport { ScaledUnitFormat } from '../index.js';\n\n/**\n * A formatter for units that can be formatted/translated by Intl.NumberFormat\n */\nexport class ScaledUnitFormatIntlNumberFormat extends ScaledUnitFormat {\n private readonly formatter: Intl.NumberFormat;\n\n protected constructor(\n scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions,\n unitSpecificIntlNumberFormatOptions: Intl.NumberFormatOptions\n ) {\n super(scaledUnitFormatFactoryOptions);\n this.formatter = new Intl.NumberFormat(this.locale, {\n ...unitSpecificIntlNumberFormatOptions,\n // Application configured options override unit specific options\n ...this.intlNumberFormatOptions\n });\n }\n\n public static createFactory(\n unitSpecificIntlNumberFormatOptions: Intl.NumberFormatOptions\n ) {\n return (\n scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions\n ): ScaledUnitFormatIntlNumberFormat => new ScaledUnitFormatIntlNumberFormat(\n scaledUnitFormatFactoryOptions,\n unitSpecificIntlNumberFormatOptions\n );\n }\n\n public format(value: number): string {\n return this.formatter.format(value);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/scaled-unit-format/manually-translated/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,eAAe;IACxB,YACoB,QAAgB,EAChB,MAAc,EACd,MAAc;QAFd,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAQ;IAC/B,CAAC;CACP;AAqBD;;GAEG;AACH,MAAM,OAAO,kCAAmC,SAAQ,gBAAgB;IAMpE,YACI,8BAA8D,EAC9D,EACI,gBAAgB,EAChB,gBAAgB,EACwB;QAE5C,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACtC,IAAI,CAAC,gBAAgB,C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CAAC;QAClC,OAAO,GAAG,SAAS,IAAI,SAAS,EAAE,CAAC;IACvC,CAAC;IAEO,mBAAmB,CACvB,gBAAkC,EAClC,MAAc;QAEd,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;QACrD,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC;QACvC,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;QACnC,MAAM,iCAAiC,GAAG,MAAM;YAC5C,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,QAAQ,IAAI,MAAM,EAAE,CAAC;YAC/C,CAAC,CAAC,SAAS,CAAC;QAChB,OAAO,CACH,iCAAiC;eAC9B,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC;eAC9B,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAE,CACjC,CAAC;IACN,CAAC;CACJ;AACD,wCAAwC","sourcesContent":["/* eslint-disable max-classes-per-file */\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/scaled-unit-format/manually-translated/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,eAAe;IACxB,YACoB,QAAgB,EAChB,MAAc,EACd,MAAc;QAFd,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAQ;IAC/B,CAAC;CACP;AAqBD;;GAEG;AACH,MAAM,OAAO,kCAAmC,SAAQ,gBAAgB;IAMpE,YACI,8BAA8D,EAC9D,EACI,gBAAgB,EAChB,gBAAgB,EACwB;QAE5C,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACtC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CACX,yDAAyD,CAC5D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,gBAAkC,EAClC,MAAc;QAEd,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;QACrD,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC;QACvC,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;QACnC,MAAM,iCAAiC,GAAG,MAAM;YAC5C,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,QAAQ,IAAI,MAAM,EAAE,CAAC;YAC/C,CAAC,CAAC,SAAS,CAAC;QAChB,OAAO,CACH,iCAAiC;eAC9B,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC;eAC9B,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAE,CACjC,CAAC;IACN,CAAC;CACJ;AACD,wCAAwC","sourcesContent":["/* eslint-disable max-classes-per-file */\nimport type { ScaledUnitFormatFactoryOptions } from '../../scaled-unit/index.js';\nimport { ScaledUnitFormat } from '../index.js';\n\n/**\n * Representations of a unit in a particular language\n */\nexport class UnitTranslation {\n public constructor(\n public readonly singular: string,\n public readonly plural: string,\n public readonly symbol: string\n ) {}\n}\n/**\n * A map of locales of string format \"[lang]\" or \"[lang]-[region]\", for example \"en\" and / or \"en-us\", to UnitTranslation objects\n */\nexport type UnitTranslations = ReadonlyMap<string, UnitTranslation>;\nexport interface ScaledUnitFormatManuallyTranslatedOptions {\n /**\n * Translations for the unit by locale string.\n * The locale strings must be of the form [lang] or [lang]-[region], for example \"en\" and / or \"en-us\".\n * Other subtags besides lang and region are not supported.\n * Translations for \"en\" must be provided.\n */\n readonly unitTranslations: UnitTranslations;\n /**\n * String for prefix of this scaled unit, for example \"k\" (for kilo-).\n * Assumed the same across languages.\n * Base unit must use \"\", i.e. empty string, as the scaled prefix text.\n */\n readonly scaledPrefixText: string;\n}\n\n/**\n * A formatter for units that are not supported by Intl.NumberFormat\n */\nexport class ScaledUnitFormatManuallyTranslated extends ScaledUnitFormat {\n private readonly pluralRules: Intl.PluralRules;\n private readonly formatter: Intl.NumberFormat;\n private readonly unitTranslation: UnitTranslation;\n private readonly scaledPrefixText: string;\n\n protected constructor(\n scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions,\n {\n unitTranslations,\n scaledPrefixText\n }: ScaledUnitFormatManuallyTranslatedOptions\n ) {\n super(scaledUnitFormatFactoryOptions);\n if (!unitTranslations.get('en')) {\n throw new Error(\n 'English translations must exist with locale string \"en\"'\n );\n }\n this.pluralRules = new Intl.PluralRules(this.locale);\n this.formatter = new Intl.NumberFormat(\n this.locale,\n this.intlNumberFormatOptions\n );\n this.unitTranslation = this.getTranslationToUse(\n unitTranslations,\n this.locale\n );\n this.scaledPrefixText = scaledPrefixText;\n }\n\n public static createFactory(\n scaledUnitFormatManuallyTranslatedOptions: ScaledUnitFormatManuallyTranslatedOptions\n ) {\n return (\n scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions\n ): ScaledUnitFormatManuallyTranslated => new ScaledUnitFormatManuallyTranslated(\n scaledUnitFormatFactoryOptions,\n scaledUnitFormatManuallyTranslatedOptions\n );\n }\n\n public format(value: number): string {\n const formatted = this.formatter.format(value);\n // For non-base units (which are a scaled prefix text of empty string)\n if (this.scaledPrefixText !== '') {\n return `${formatted} ${this.scaledPrefixText}${this.unitTranslation.symbol}`;\n }\n\n // Some languages have more than two forms (singular/plural) of cardinal\n // numbers, but we are treating anything other than the 'one' form as plural.\n // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules#description\n //\n // Because PluralRules.select() takes a number (not a string), it cannot differentiate\n // between 1 and 1.0. When NumberFormat is configured to format with a set number\n // of fractional digits, those fractional digits can have an effect on the pluralization\n // of the unit. E.g. in English, it formats \"1 byte\" vs \"1.0 bytes\". Thus there is\n // sometimes an inconsistency between unit pluralization for the same number, based\n // on whether it's supported by NumberFormat, or manually translated.\n const unitLabel = this.pluralRules.select(value) === 'one'\n ? this.unitTranslation.singular\n : this.unitTranslation.plural;\n return `${formatted} ${unitLabel}`;\n }\n\n private getTranslationToUse(\n unitTranslations: UnitTranslations,\n locale: string\n ): UnitTranslation {\n const localeObject = new Intl.Locale(locale ?? 'en');\n const language = localeObject.language;\n const region = localeObject.region;\n const regionSpecificMatchedTranslations = region\n ? unitTranslations.get(`${language}-${region}`)\n : undefined;\n return (\n regionSpecificMatchedTranslations\n ?? unitTranslations.get(language)\n ?? unitTranslations.get('en')!\n );\n }\n}\n/* eslint-enable max-classes-per-file */\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/byte/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,mBAAmB,GAAG;IACxB,CAAC,IAAI,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC;IAC3B,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEX;;GAEG;AACH,MAAM,aAAc,SAAQ,SAAS;IACjC;QACI,KAAK,CACD,mBAAmB,CAAC,GAAG,CACnB,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAChD,WAAW,EACX,gCAAgC,CAAC,aAAa,CAAC;YAC3C,KAAK,EAAE,MAAM;YACb,IAAI;YACJ,WAAW;SACd,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC","sourcesContent":["import { ScaledUnitFormatIntlNumberFormat } from '../../scaled-unit-format/intl-number-format/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/byte/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,mBAAmB,GAAG;IACxB,CAAC,IAAI,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC;IAC3B,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;IAChC,CAAC,IAAI,IAAI,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEX;;GAEG;AACH,MAAM,aAAc,SAAQ,SAAS;IACjC;QACI,KAAK,CACD,mBAAmB,CAAC,GAAG,CACnB,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAChD,WAAW,EACX,gCAAgC,CAAC,aAAa,CAAC;YAC3C,KAAK,EAAE,MAAM;YACb,IAAI;YACJ,WAAW;SACd,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC","sourcesContent":["import { ScaledUnitFormatIntlNumberFormat } from '../../scaled-unit-format/intl-number-format/index.js';\nimport { ScaledUnit } from '../../scaled-unit/index.js';\nimport { UnitScale } from '../index.js';\n\nconst unitScaleByteConfig = [\n [1000 ** 0, 'byte', 'long'],\n [1000 ** 1, 'kilobyte', 'short'],\n [1000 ** 2, 'megabyte', 'short'],\n [1000 ** 3, 'gigabyte', 'short'],\n [1000 ** 4, 'terabyte', 'short'],\n [1000 ** 5, 'petabyte', 'short']\n] as const;\n\n/**\n * Byte units (1000-based)\n */\nclass UnitScaleByte extends UnitScale {\n public constructor() {\n super(\n unitScaleByteConfig.map(\n ([scaleFactor, unit, unitDisplay]) => new ScaledUnit(\n scaleFactor,\n ScaledUnitFormatIntlNumberFormat.createFactory({\n style: 'unit',\n unit,\n unitDisplay\n })\n )\n )\n );\n }\n}\n\nexport const unitScaleByte = new UnitScaleByte();\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/byte-1024/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACH,kCAAkC,EAElC,eAAe,EAClB,MAAM,uDAAuD,CAAC;AAE/D,MAAM,gBAAgB,GAAqB,IAAI,GAAG,CAAC;IAC/C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;CAC/C,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAG;IACrB,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;IACf,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;CACX,CAAC;AAEX;;GAEG;AACH,MAAM,iBAAkB,SAAQ,SAAS;IACrC;QACI,KAAK,CACD,gBAAgB,CAAC,GAAG,CAChB,CAAC,CAAC,WAAW,EAAE,gBAAgB,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAC/C,WAAW,EACX,kCAAkC,CAAC,aAAa,CAAC;YAC7C,gBAAgB;YAChB,gBAAgB;SACnB,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC","sourcesContent":["import { ScaledUnit } from '../../scaled-unit/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/byte-1024/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACH,kCAAkC,EAElC,eAAe,EAClB,MAAM,uDAAuD,CAAC;AAE/D,MAAM,gBAAgB,GAAqB,IAAI,GAAG,CAAC;IAC/C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;CAC/C,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAG;IACrB,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;IACf,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;CACX,CAAC;AAEX;;GAEG;AACH,MAAM,iBAAkB,SAAQ,SAAS;IACrC;QACI,KAAK,CACD,gBAAgB,CAAC,GAAG,CAChB,CAAC,CAAC,WAAW,EAAE,gBAAgB,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAC/C,WAAW,EACX,kCAAkC,CAAC,aAAa,CAAC;YAC7C,gBAAgB;YAChB,gBAAgB;SACnB,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC","sourcesContent":["import { ScaledUnit } from '../../scaled-unit/index.js';\nimport { UnitScale } from '../index.js';\nimport {\n ScaledUnitFormatManuallyTranslated,\n type UnitTranslations,\n UnitTranslation\n} from '../../scaled-unit-format/manually-translated/index.js';\n\nconst unitTranslations: UnitTranslations = new Map([\n ['en', new UnitTranslation('byte', 'bytes', 'B')],\n ['fr', new UnitTranslation('octet', 'octets', 'o')],\n ['de', new UnitTranslation('Byte', 'Byte', 'B')],\n ['ja', new UnitTranslation('バイト', 'バイト', 'B')],\n ['zh', new UnitTranslation('字节', '字节', 'B')]\n]);\n\nconst byte1024Prefixes = [\n [1024 ** 0, ''],\n [1024 ** 1, 'Ki'],\n [1024 ** 2, 'Mi'],\n [1024 ** 3, 'Gi'],\n [1024 ** 4, 'Ti'],\n [1024 ** 5, 'Pi']\n] as const;\n\n/**\n * Byte units (1024-based)\n */\nclass UnitScaleByte1024 extends UnitScale {\n public constructor() {\n super(\n byte1024Prefixes.map(\n ([scaleFactor, scaledPrefixText]) => new ScaledUnit(\n scaleFactor,\n ScaledUnitFormatManuallyTranslated.createFactory({\n unitTranslations,\n scaledPrefixText\n })\n )\n )\n );\n }\n}\n\nexport const unitScaleByte1024 = new UnitScaleByte1024();\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/celsius/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,sBAAsB,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,CAAU,CAAC;AAElE;;GAEG;AACH,MAAM,gBAAiB,SAAQ,SAAS;IACpC;QACI,KAAK,CACD,sBAAsB,CAAC,GAAG,CACtB,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAChD,WAAW,EACX,gCAAgC,CAAC,aAAa,CAAC;YAC3C,KAAK,EAAE,MAAM;YACb,IAAI;YACJ,WAAW;SACd,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC","sourcesContent":["import { ScaledUnit } from '../../scaled-unit/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/celsius/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,sBAAsB,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,CAAU,CAAC;AAElE;;GAEG;AACH,MAAM,gBAAiB,SAAQ,SAAS;IACpC;QACI,KAAK,CACD,sBAAsB,CAAC,GAAG,CACtB,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAChD,WAAW,EACX,gCAAgC,CAAC,aAAa,CAAC;YAC3C,KAAK,EAAE,MAAM;YACb,IAAI;YACJ,WAAW;SACd,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC","sourcesContent":["import { ScaledUnit } from '../../scaled-unit/index.js';\nimport { ScaledUnitFormatIntlNumberFormat } from '../../scaled-unit-format/intl-number-format/index.js';\nimport { UnitScale } from '../index.js';\n\nconst unitScaleCelsiusConfig = [[1, 'celsius', 'short']] as const;\n\n/**\n * Degrees Celsius units\n */\nclass UnitScaleCelsius extends UnitScale {\n public constructor() {\n super(\n unitScaleCelsiusConfig.map(\n ([scaleFactor, unit, unitDisplay]) => new ScaledUnit(\n scaleFactor,\n ScaledUnitFormatIntlNumberFormat.createFactory({\n style: 'unit',\n unit,\n unitDisplay\n })\n )\n )\n );\n }\n}\n\nexport const unitScaleCelsius = new UnitScaleCelsius();\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/fahrenheit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,yBAAyB,GAAG,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,CAAU,CAAC;AAExE;;GAEG;AACH,MAAM,mBAAoB,SAAQ,SAAS;IACvC;QACI,KAAK,CACD,yBAAyB,CAAC,GAAG,CACzB,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAChD,WAAW,EACX,gCAAgC,CAAC,aAAa,CAAC;YAC3C,KAAK,EAAE,MAAM;YACb,IAAI;YACJ,WAAW;SACd,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,EAAE,CAAC","sourcesContent":["import { ScaledUnit } from '../../scaled-unit/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/fahrenheit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,yBAAyB,GAAG,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,CAAU,CAAC;AAExE;;GAEG;AACH,MAAM,mBAAoB,SAAQ,SAAS;IACvC;QACI,KAAK,CACD,yBAAyB,CAAC,GAAG,CACzB,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAChD,WAAW,EACX,gCAAgC,CAAC,aAAa,CAAC;YAC3C,KAAK,EAAE,MAAM;YACb,IAAI;YACJ,WAAW;SACd,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,EAAE,CAAC","sourcesContent":["import { ScaledUnit } from '../../scaled-unit/index.js';\nimport { ScaledUnitFormatIntlNumberFormat } from '../../scaled-unit-format/intl-number-format/index.js';\nimport { UnitScale } from '../index.js';\n\nconst unitScaleFahrenheitConfig = [[1, 'fahrenheit', 'short']] as const;\n\n/**\n * Degrees Fahrenheit units\n */\nclass UnitScaleFahrenheit extends UnitScale {\n public constructor() {\n super(\n unitScaleFahrenheitConfig.map(\n ([scaleFactor, unit, unitDisplay]) => new ScaledUnit(\n scaleFactor,\n ScaledUnitFormatIntlNumberFormat.createFactory({\n style: 'unit',\n unit,\n unitDisplay\n })\n )\n )\n );\n }\n}\n\nexport const unitScaleFahrenheit = new UnitScaleFahrenheit();\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/unit-scale/index.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAgB,SAAS;IAG3B,YACoB,oBAA2C;QAA3C,yBAAoB,GAApB,oBAAoB,CAAuB;QAE3D,MAAM,WAAW,GAAG,oBAAoB,CAAC,KAAK,CAC1C,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAC1E,CAAC;QACF,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACX,mEAAmE,CACtE,CAAC;QACN,CAAC;QACD,MAAM,cAAc,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QAClE,IAAI,CA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aledUnit } from '../scaled-unit/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/unit-scale/index.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAgB,SAAS;IAG3B,YACoB,oBAA2C;QAA3C,yBAAoB,GAApB,oBAAoB,CAAuB;QAE3D,MAAM,WAAW,GAAG,oBAAoB,CAAC,KAAK,CAC1C,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAC1E,CAAC;QACF,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACX,mEAAmE,CACtE,CAAC;QACN,CAAC;QACD,MAAM,cAAc,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,cAAc,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACX,yEAAyE,CAC5E,CAAC;QACN,CAAC;QACD,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QACjD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IAED,uEAAuE;IACvE,sEAAsE;IACtE,oEAAoE;IACpE,kDAAkD;IAClD,8EAA8E;IAC9E,qGAAqG;IAC9F,WAAW,CAAC,MAAc;QAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnC,MAAM,kBAAkB,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,KAAK,CAAC,CAAC;QAClE,IACI,kBAAkB;eACf,SAAS,KAAK,CAAC;eACf,SAAS,KAAK,QAAQ;eACtB,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAC5B,CAAC;YACC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC;QACpE,CAAC;QACD,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAChE,MAAM,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAE,CAAC;YACjD,IAAI,SAAS,GAAG,UAAU,CAAC,WAAW,IAAI,CAAC,EAAE,CAAC;gBAC1C,OAAO;oBACH,WAAW,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW;oBAC5C,UAAU;iBACb,CAAC;YACN,CAAC;QACL,CAAC;QACD,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAE,CAAC;QACnD,OAAO;YACH,WAAW,EAAE,MAAM,GAAG,YAAY,CAAC,WAAW;YAC9C,UAAU,EAAE,YAAY;SAC3B,CAAC;IACN,CAAC;CACJ","sourcesContent":["import type { ScaledUnit } from '../scaled-unit/index.js';\n\ninterface ScaledNumber {\n readonly scaledValue: number;\n readonly scaledUnit: ScaledUnit;\n}\n\n/**\n * A unit scale consisting of a set of scaled units.\n */\nexport abstract class UnitScale {\n public readonly baseScaledUnit: ScaledUnit;\n\n public constructor(\n public readonly supportedScaledUnits: readonly ScaledUnit[]\n ) {\n const unitsSorted = supportedScaledUnits.every(\n (curr, i, arr) => i === 0 || arr[i - 1]!.scaleFactor < curr.scaleFactor\n );\n if (!unitsSorted) {\n throw new Error(\n 'Supported scaled units must have unique and ordered scale factors'\n );\n }\n const baseScaledUnit = supportedScaledUnits.find(x => x.isBase());\n if (!baseScaledUnit) {\n throw new Error(\n 'Supported scaled units must include a base scaled unit (scale factor=1)'\n );\n }\n this.supportedScaledUnits = supportedScaledUnits;\n this.baseScaledUnit = baseScaledUnit;\n }\n\n // Note that for the sake of reducing complexity in the implementation,\n // we do NOT consider the effects of rounding when picking the unit to\n // use for a given value. If formatting results in rounding, a value\n // may be shown with an unexpected unit. Examples:\n // - 999 bytes with two significant digits => \"1000 bytes\" (instead of \"1 kB\")\n // - 0.00000000000000001 volts (= 0.01 fV) with one fractional digit => \"0 fV\" (instead of \"0 volts\")\n public scaleNumber(number: number): ScaledNumber {\n const magnitude = Math.abs(number);\n const onlyBaseScaledUnit = this.supportedScaledUnits.length === 1;\n if (\n onlyBaseScaledUnit\n || magnitude === 0\n || magnitude === Infinity\n || Number.isNaN(magnitude)\n ) {\n return { scaledValue: number, scaledUnit: this.baseScaledUnit };\n }\n for (let i = this.supportedScaledUnits.length - 1; i >= 0; i -= 1) {\n const scaledUnit = this.supportedScaledUnits[i]!;\n if (magnitude / scaledUnit.scaleFactor >= 1) {\n return {\n scaledValue: number / scaledUnit.scaleFactor,\n scaledUnit\n };\n }\n }\n const smallestUnit = this.supportedScaledUnits[0]!;\n return {\n scaledValue: number / smallestUnit.scaleFactor,\n scaledUnit: smallestUnit\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/passthrough/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;GAEG;AACH,MAAM,oBAAqB,SAAQ,SAAS;IACxC;QACI,KAAK,CAAC;YACF,IAAI,UAAU,CACV,EAAE,IAAI,CAAC,EACP,gCAAgC,CAAC,aAAa,CAAC,EAAE,CAAC,CACrD;SACJ,CAAC,CAAC;IACP,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC","sourcesContent":["import { ScaledUnitFormatIntlNumberFormat } from '../../scaled-unit-format/intl-number-format/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/passthrough/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;GAEG;AACH,MAAM,oBAAqB,SAAQ,SAAS;IACxC;QACI,KAAK,CAAC;YACF,IAAI,UAAU,CACV,EAAE,IAAI,CAAC,EACP,gCAAgC,CAAC,aAAa,CAAC,EAAE,CAAC,CACrD;SACJ,CAAC,CAAC;IACP,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC","sourcesContent":["import { ScaledUnitFormatIntlNumberFormat } from '../../scaled-unit-format/intl-number-format/index.js';\nimport { ScaledUnit } from '../../scaled-unit/index.js';\nimport { UnitScale } from '../index.js';\n\n/**\n * Unit scale that is used to passthrough a number without applying scaling or units\n */\nclass UnitScalePassthrough extends UnitScale {\n public constructor() {\n super([\n new ScaledUnit(\n 10 ** 0,\n ScaledUnitFormatIntlNumberFormat.createFactory({})\n )\n ]);\n }\n}\n\nexport const unitScalePassthrough = new UnitScalePassthrough();\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metric-prefixes.js","sourceRoot":"","sources":["../../../../src/unit-scale/utilities/metric-prefixes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC;IAChB,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC;IAChB,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;IACb,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IACd,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IACd,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IACd,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC;CACT,CAAC","sourcesContent":["export const metricPrefixes = [\
|
|
1
|
+
{"version":3,"file":"metric-prefixes.js","sourceRoot":"","sources":["../../../../src/unit-scale/utilities/metric-prefixes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC;IAChB,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC;IAChB,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;IACb,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IACd,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IACd,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IACd,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC;IACf,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC;CACT,CAAC","sourcesContent":["export const metricPrefixes = [\n [10 ** -15, 'f'],\n [10 ** -12, 'p'],\n [10 ** -9, 'n'],\n [10 ** -6, 'μ'],\n [10 ** -3, 'm'],\n [10 ** -2, 'c'],\n [10 ** -1, 'd'],\n [10 ** 0, ''],\n [10 ** 3, 'k'],\n [10 ** 6, 'M'],\n [10 ** 9, 'G'],\n [10 ** 12, 'T'],\n [10 ** 15, 'P'],\n [10 ** 18, 'E']\n] as const;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/volt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EACH,kCAAkC,EAElC,eAAe,EAClB,MAAM,uDAAuD,CAAC;AAE/D,MAAM,gBAAgB,GAAqB,IAAI,GAAG,CAAC;IAC/C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;CAC/C,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,aAAc,SAAQ,SAAS;IACjC;QACI,KAAK,CACD,cAAc,CAAC,GAAG,CACd,CAAC,CAAC,WAAW,EAAE,gBAAgB,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAC/C,WAAW,EACX,kCAAkC,CAAC,aAAa,CAAC;YAC7C,gBAAgB;YAChB,gBAAgB;SACnB,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC","sourcesContent":["import { ScaledUnit } from '../../scaled-unit/index.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit-scale/volt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EACH,kCAAkC,EAElC,eAAe,EAClB,MAAM,uDAAuD,CAAC;AAE/D,MAAM,gBAAgB,GAAqB,IAAI,GAAG,CAAC;IAC/C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;CAC/C,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,aAAc,SAAQ,SAAS;IACjC;QACI,KAAK,CACD,cAAc,CAAC,GAAG,CACd,CAAC,CAAC,WAAW,EAAE,gBAAgB,CAAC,EAAE,EAAE,CAAC,IAAI,UAAU,CAC/C,WAAW,EACX,kCAAkC,CAAC,aAAa,CAAC;YAC7C,gBAAgB;YAChB,gBAAgB;SACnB,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC","sourcesContent":["import { ScaledUnit } from '../../scaled-unit/index.js';\nimport { UnitScale } from '../index.js';\nimport { metricPrefixes } from '../utilities/metric-prefixes.js';\nimport {\n ScaledUnitFormatManuallyTranslated,\n type UnitTranslations,\n UnitTranslation\n} from '../../scaled-unit-format/manually-translated/index.js';\n\nconst unitTranslations: UnitTranslations = new Map([\n ['en', new UnitTranslation('volt', 'volts', 'V')],\n ['fr', new UnitTranslation('volt', 'volts', 'V')],\n ['de', new UnitTranslation('Volt', 'Volt', 'V')],\n ['ja', new UnitTranslation('ボルト', 'ボルト', 'V')],\n ['zh', new UnitTranslation('伏特', '伏特', 'V')]\n]);\n\n/**\n * Voltage unit scale\n */\nclass UnitScaleVolt extends UnitScale {\n public constructor() {\n super(\n metricPrefixes.map(\n ([scaleFactor, scaledPrefixText]) => new ScaledUnit(\n scaleFactor,\n ScaledUnitFormatManuallyTranslated.createFactory({\n unitTranslations,\n scaledPrefixText\n })\n )\n )\n );\n }\n}\n\nexport const unitScaleVolt = new UnitScaleVolt();\n"]}
|
package/package.json
CHANGED
|
@@ -1,64 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@ni/unit-format",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "NumberFormat aligned library to format numbers with scaled units.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"units",
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@ni/unit-format",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "NumberFormat aligned library to format numbers with scaled units.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"units",
|
|
7
|
+
"formatting",
|
|
8
|
+
"nimble",
|
|
9
|
+
"engineering",
|
|
10
|
+
"metric",
|
|
11
|
+
"si",
|
|
12
|
+
"volts",
|
|
13
|
+
"degrees",
|
|
14
|
+
"bytes"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -b",
|
|
18
|
+
"lint": "eslint .",
|
|
19
|
+
"format": "eslint . --fix",
|
|
20
|
+
"pack": "npm pack",
|
|
21
|
+
"invoke-publish": "npm publish",
|
|
22
|
+
"tdd": "npm run build && npm run test",
|
|
23
|
+
"test": "npm run test:node && npm run test:browser",
|
|
24
|
+
"test:node": "jasmine",
|
|
25
|
+
"test:browser": "karma start karma.conf.cjs --browsers=ChromeHeadlessOpt --single-run",
|
|
26
|
+
"test:browser:debugger": "karma start karma.conf.cjs --browsers=ChromeDebugging"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/ni/nimble.git"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"exports": {
|
|
37
|
+
"./package.json": "./package.json",
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/esm/index.d.ts",
|
|
40
|
+
"import": "./dist/esm/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./*": {
|
|
43
|
+
"types": "./dist/esm/*.d.ts",
|
|
44
|
+
"import": "./dist/esm/*/index.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"typesVersions": {
|
|
48
|
+
"*": {
|
|
49
|
+
"*": [
|
|
50
|
+
"dist/esm/*",
|
|
51
|
+
"dist/esm/*/index.d.ts"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"author": "National Instruments",
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@ni/jasmine-parameterized": "^1.0.8",
|
|
59
|
+
"@ni-private/eslint-config-nimble": "*",
|
|
60
|
+
"@types/jasmine": "^5.1.4",
|
|
61
|
+
"jasmine": "^5.1.0",
|
|
62
|
+
"jasmine-core": "^5.1.2",
|
|
63
|
+
"karma": "^6.3.0",
|
|
64
|
+
"karma-chrome-launcher": "^3.1.0",
|
|
65
|
+
"karma-jasmine": "^5.1.0",
|
|
66
|
+
"karma-jasmine-html-reporter": "^2.0.0",
|
|
67
|
+
"karma-spec-reporter": "^0.0.36",
|
|
68
|
+
"karma-vite": "^1.0.5",
|
|
69
|
+
"playwright": "1.54.1",
|
|
70
|
+
"typescript": "~5.8.3"
|
|
71
|
+
}
|
|
72
|
+
}
|