@ni/nimble-components 20.17.7 → 20.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/all-components-bundle.js +643 -163
- package/dist/all-components-bundle.js.map +1 -1
- package/dist/all-components-bundle.min.js +1150 -1107
- package/dist/all-components-bundle.min.js.map +1 -1
- package/dist/esm/all-components.d.ts +2 -0
- package/dist/esm/all-components.js +2 -0
- package/dist/esm/all-components.js.map +1 -1
- package/dist/esm/rich-text/base/index.js +2 -4
- package/dist/esm/rich-text/base/index.js.map +1 -1
- package/dist/esm/table/index.js +2 -4
- package/dist/esm/table/index.js.map +1 -1
- package/dist/esm/table-column/number-text/cell-view/index.js +1 -2
- package/dist/esm/table-column/number-text/cell-view/index.js.map +1 -1
- package/dist/esm/table-column/number-text/group-header-view/index.js +1 -2
- package/dist/esm/table-column/number-text/group-header-view/index.js.map +1 -1
- package/dist/esm/table-column/number-text/index.d.ts +11 -2
- package/dist/esm/table-column/number-text/index.js +61 -14
- package/dist/esm/table-column/number-text/index.js.map +1 -1
- package/dist/esm/table-column/number-text/models/table-column-number-text-validator.d.ts +2 -1
- package/dist/esm/table-column/number-text/models/table-column-number-text-validator.js +6 -1
- package/dist/esm/table-column/number-text/models/table-column-number-text-validator.js.map +1 -1
- package/dist/esm/table-column/number-text/template.d.ts +2 -0
- package/dist/esm/table-column/number-text/template.js +14 -0
- package/dist/esm/table-column/number-text/template.js.map +1 -0
- package/dist/esm/unit/base/template.d.ts +1 -0
- package/dist/esm/unit/base/template.js +3 -0
- package/dist/esm/unit/base/template.js.map +1 -0
- package/dist/esm/unit/base/unit.d.ts +9 -0
- package/dist/esm/unit/base/unit.js +12 -0
- package/dist/esm/unit/base/unit.js.map +1 -0
- package/dist/esm/unit/byte/index.d.ts +19 -0
- package/dist/esm/unit/byte/index.js +36 -0
- package/dist/esm/unit/byte/index.js.map +1 -0
- package/dist/esm/unit/volt/index.d.ts +13 -0
- package/dist/esm/unit/volt/index.js +20 -0
- package/dist/esm/unit/volt/index.js.map +1 -0
- package/dist/esm/utilities/unit-format/base/unit-format.d.ts +16 -0
- package/dist/esm/utilities/unit-format/base/unit-format.js +21 -0
- package/dist/esm/utilities/unit-format/base/unit-format.js.map +1 -0
- package/dist/esm/utilities/unit-format/decimal-unit-format.d.ts +22 -0
- package/dist/esm/utilities/unit-format/decimal-unit-format.js +51 -0
- package/dist/esm/utilities/unit-format/decimal-unit-format.js.map +1 -0
- package/dist/esm/utilities/unit-format/default-unit-format.d.ts +21 -0
- package/dist/esm/utilities/unit-format/default-unit-format.js +102 -0
- package/dist/esm/utilities/unit-format/default-unit-format.js.map +1 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/manually-translated-scaled-unit-format.d.ts +18 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/manually-translated-scaled-unit-format.js +49 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/manually-translated-scaled-unit-format.js.map +1 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/manually-translated-unit-scale.d.ts +10 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/manually-translated-unit-scale.js +19 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/manually-translated-unit-scale.js.map +1 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-prefix.d.ts +10 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-prefix.js +17 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-prefix.js.map +1 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-prefixes-metric.d.ts +5 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-prefixes-metric.js +21 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-prefixes-metric.js.map +1 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-translation.d.ts +9 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-translation.js +11 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-translation.js.map +1 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/byte-1024-unit-scale.d.ts +9 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/byte-1024-unit-scale.js +26 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/byte-1024-unit-scale.js.map +1 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/volt-unit-scale.d.ts +9 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/volt-unit-scale.js +19 -0
- package/dist/esm/utilities/unit-format/manually-translated-unit-scale/volt-unit-scale.js.map +1 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/intl-number-format-scaled-unit-format.d.ts +11 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/intl-number-format-scaled-unit-format.js +21 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/intl-number-format-scaled-unit-format.js.map +1 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/scaled-unit-format.d.ts +10 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/scaled-unit-format.js +10 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/scaled-unit-format.js.map +1 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/scaled-unit.d.ts +16 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/scaled-unit.js +13 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/scaled-unit.js.map +1 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/unit-scale.d.ts +15 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/unit-scale.js +49 -0
- package/dist/esm/utilities/unit-format/unit-scale/base/unit-scale.js.map +1 -0
- package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.d.ts +9 -0
- package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.js +44 -0
- package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.js.map +1 -0
- package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.d.ts +9 -0
- package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.js +15 -0
- package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.js.map +1 -0
- package/dist/esm/utilities/wait-until-custom-elements-defined-async.d.ts +1 -0
- package/dist/esm/utilities/wait-until-custom-elements-defined-async.js +7 -0
- package/dist/esm/utilities/wait-until-custom-elements-defined-async.js.map +1 -0
- package/package.json +1 -1
- package/dist/esm/table-column/number-text/models/decimal-formatter.d.ts +0 -11
- package/dist/esm/table-column/number-text/models/decimal-formatter.js +0 -27
- package/dist/esm/table-column/number-text/models/decimal-formatter.js.map +0 -1
- package/dist/esm/table-column/number-text/models/default-formatter.d.ts +0 -15
- package/dist/esm/table-column/number-text/models/default-formatter.js +0 -55
- package/dist/esm/table-column/number-text/models/default-formatter.js.map +0 -1
- package/dist/esm/table-column/number-text/models/number-formatter.d.ts +0 -11
- package/dist/esm/table-column/number-text/models/number-formatter.js +0 -21
- package/dist/esm/table-column/number-text/models/number-formatter.js.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Unit } from '../base/unit';
|
|
2
|
+
declare global {
|
|
3
|
+
interface HTMLElementTagNameMap {
|
|
4
|
+
'nimble-unit-volt': UnitVolt;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Element representing units for volts
|
|
9
|
+
*/
|
|
10
|
+
export declare class UnitVolt extends Unit {
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
export declare const unitVoltTag = "nimble-unit-volt";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DesignSystem } from '@microsoft/fast-foundation';
|
|
2
|
+
import { template } from '../base/template';
|
|
3
|
+
import { Unit } from '../base/unit';
|
|
4
|
+
import { voltUnitScale } from '../../utilities/unit-format/manually-translated-unit-scale/volt-unit-scale';
|
|
5
|
+
/**
|
|
6
|
+
* Element representing units for volts
|
|
7
|
+
*/
|
|
8
|
+
export class UnitVolt extends Unit {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this.resolvedUnitScale = voltUnitScale;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const nimbleUnitVolt = UnitVolt.compose({
|
|
15
|
+
baseName: 'unit-volt',
|
|
16
|
+
template
|
|
17
|
+
});
|
|
18
|
+
DesignSystem.getOrCreate().withPrefix('nimble').register(nimbleUnitVolt());
|
|
19
|
+
export const unitVoltTag = 'nimble-unit-volt';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit/volt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,4EAA4E,CAAC;AAQ3G;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,IAAI;IAC9B;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,iBAAiB,GAAG,aAAa,CAAC;IAC3C,CAAC;CACJ;AAED,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC;IACpC,QAAQ,EAAE,WAAW;IACrB,QAAQ;CACX,CAAC,CAAC;AAEH,YAAY,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { UnitScale } from '../unit-scale/base/unit-scale';
|
|
2
|
+
export interface UnitFormatOptions {
|
|
3
|
+
unitScale?: UnitScale;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The base class for unit formats.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class UnitFormat<Options extends UnitFormatOptions = UnitFormatOptions> {
|
|
9
|
+
/**
|
|
10
|
+
* Formats a number value to a string.
|
|
11
|
+
* For nullish values or values that result in an exception being thrown, empty string is returned
|
|
12
|
+
*/
|
|
13
|
+
format(value: number | undefined | null): string;
|
|
14
|
+
abstract resolvedOptions(): Required<Options>;
|
|
15
|
+
protected abstract tryFormat(number: number): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base class for unit formats.
|
|
3
|
+
*/
|
|
4
|
+
export class UnitFormat {
|
|
5
|
+
/**
|
|
6
|
+
* Formats a number value to a string.
|
|
7
|
+
* For nullish values or values that result in an exception being thrown, empty string is returned
|
|
8
|
+
*/
|
|
9
|
+
format(value) {
|
|
10
|
+
if (typeof value !== 'number') {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
return this.tryFormat(value);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=unit-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit-format.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/base/unit-format.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,OAAgB,UAAU;IAG5B;;;OAGG;IACI,MAAM,CAAC,KAAgC;QAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,OAAO,EAAE,CAAC;SACb;QAED,IAAI;YACA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SAChC;QAAC,MAAM;YACJ,OAAO,EAAE,CAAC;SACb;IACL,CAAC;CAKJ"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { UnitFormat, UnitFormatOptions } from './base/unit-format';
|
|
2
|
+
import type { UnitScale } from './unit-scale/base/unit-scale';
|
|
3
|
+
interface DecimalUnitFormatOptions extends UnitFormatOptions {
|
|
4
|
+
minimumFractionDigits?: number;
|
|
5
|
+
maximumFractionDigits?: number;
|
|
6
|
+
unitScale?: UnitScale;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Format for decimal numbers with units.
|
|
10
|
+
*/
|
|
11
|
+
export declare class DecimalUnitFormat extends UnitFormat<DecimalUnitFormatOptions> {
|
|
12
|
+
private readonly unitScale;
|
|
13
|
+
private readonly minimumFractionDigits;
|
|
14
|
+
private readonly maximumFractionDigits;
|
|
15
|
+
private readonly scaledUnitFormatters;
|
|
16
|
+
private readonly tenPowDecimalDigits;
|
|
17
|
+
constructor(locale: string, { minimumFractionDigits, maximumFractionDigits, unitScale }?: DecimalUnitFormatOptions);
|
|
18
|
+
resolvedOptions(): Required<DecimalUnitFormatOptions>;
|
|
19
|
+
protected tryFormat(number: number): string;
|
|
20
|
+
private willRoundToZero;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { UnitFormat } from './base/unit-format';
|
|
2
|
+
import { passthroughUnitScale } from './unit-scale/passthrough-unit-scale';
|
|
3
|
+
/**
|
|
4
|
+
* Format for decimal numbers with units.
|
|
5
|
+
*/
|
|
6
|
+
export class DecimalUnitFormat extends UnitFormat {
|
|
7
|
+
constructor(locale, { minimumFractionDigits = 0, maximumFractionDigits = Math.max(3, minimumFractionDigits), unitScale = passthroughUnitScale } = {
|
|
8
|
+
minimumFractionDigits: 0,
|
|
9
|
+
maximumFractionDigits: 3,
|
|
10
|
+
unitScale: passthroughUnitScale
|
|
11
|
+
}) {
|
|
12
|
+
super();
|
|
13
|
+
this.scaledUnitFormatters = new Map();
|
|
14
|
+
const intlNumberFormatOptions = {
|
|
15
|
+
maximumFractionDigits,
|
|
16
|
+
minimumFractionDigits,
|
|
17
|
+
useGrouping: true
|
|
18
|
+
};
|
|
19
|
+
for (const scaledUnit of unitScale.supportedScaledUnits) {
|
|
20
|
+
this.scaledUnitFormatters.set(scaledUnit.scaleFactor, scaledUnit.scaledUnitFormatFactory({
|
|
21
|
+
locale,
|
|
22
|
+
intlNumberFormatOptions
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
this.tenPowDecimalDigits = 10 ** maximumFractionDigits;
|
|
26
|
+
this.unitScale = unitScale;
|
|
27
|
+
this.minimumFractionDigits = minimumFractionDigits;
|
|
28
|
+
this.maximumFractionDigits = maximumFractionDigits;
|
|
29
|
+
}
|
|
30
|
+
resolvedOptions() {
|
|
31
|
+
return {
|
|
32
|
+
unitScale: this.unitScale,
|
|
33
|
+
maximumFractionDigits: this.maximumFractionDigits,
|
|
34
|
+
minimumFractionDigits: this.minimumFractionDigits
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
tryFormat(number) {
|
|
38
|
+
const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);
|
|
39
|
+
const numberNormalized = this.willRoundToZero(scaledValue)
|
|
40
|
+
? 0
|
|
41
|
+
: scaledValue;
|
|
42
|
+
const scaledUnitFormatter = this.scaledUnitFormatters.get(scaledUnit.scaleFactor);
|
|
43
|
+
return scaledUnitFormatter.format(numberNormalized);
|
|
44
|
+
}
|
|
45
|
+
willRoundToZero(number) {
|
|
46
|
+
// Multiply the value by 10 raised to maximumFractionDigits so that Math.round can be used to emulate rounding to
|
|
47
|
+
// maximumFractionDigits decimal places. If that rounded value is 0, then the value will be rendered with only 0s.
|
|
48
|
+
return Math.round(number * this.tenPowDecimalDigits) === 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=decimal-unit-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decimal-unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/decimal-unit-format.ts"],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I,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEvE,MAAM,gBAAgB,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC;YACtD,CAAC,CAAC,CAAC;YACH,CAAC,CAAC,WAAW,CAAC;QAClB,MAAM,mBAAmB,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,CACrD,UAAU,CAAC,WAAW,CACxB,CAAC;QACH,OAAO,mBAAmB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACxD,CAAC;IAEO,eAAe,CAAC,MAAc;QAClC,iHAAiH;QACjH,kHAAkH;QAClH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC/D,CAAC;CACJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UnitFormat, UnitFormatOptions } from './base/unit-format';
|
|
2
|
+
/**
|
|
3
|
+
* Format for numbers with units to show in a tabular form.
|
|
4
|
+
* Large and tiny numbers are shown exponentially and the rest as decimal.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DefaultUnitFormat extends UnitFormat {
|
|
7
|
+
private static readonly maximumDigits;
|
|
8
|
+
private static readonly exponentialLowerBound;
|
|
9
|
+
private static readonly exponentialUpperBound;
|
|
10
|
+
private readonly unitScale;
|
|
11
|
+
private readonly defaultIntlNumberFormatOptions;
|
|
12
|
+
private readonly defaultScaledUnitFormatters;
|
|
13
|
+
private readonly leadingZeroIntlNumberFormatOptions;
|
|
14
|
+
private readonly leadingZeroScaledUnitFormatters;
|
|
15
|
+
private readonly exponentialIntlNumberFormatOptions;
|
|
16
|
+
private readonly exponentialScaledUnitFormatter;
|
|
17
|
+
constructor(locale: string, { unitScale }?: UnitFormatOptions);
|
|
18
|
+
resolvedOptions(): Required<UnitFormatOptions>;
|
|
19
|
+
protected tryFormat(number: number): string;
|
|
20
|
+
private resolveNumberStyle;
|
|
21
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { UnitFormat } from './base/unit-format';
|
|
2
|
+
import { passthroughUnitScale } from './unit-scale/passthrough-unit-scale';
|
|
3
|
+
/**
|
|
4
|
+
* Format for numbers with units to show in a tabular form.
|
|
5
|
+
* Large and tiny numbers are shown exponentially and the rest as decimal.
|
|
6
|
+
*/
|
|
7
|
+
export class DefaultUnitFormat extends UnitFormat {
|
|
8
|
+
constructor(locale, { unitScale = passthroughUnitScale } = {
|
|
9
|
+
unitScale: passthroughUnitScale
|
|
10
|
+
}) {
|
|
11
|
+
super();
|
|
12
|
+
// Format options to use by default. It renders the number with a maximum of 6 signficant digits.
|
|
13
|
+
this.defaultIntlNumberFormatOptions = {
|
|
14
|
+
maximumSignificantDigits: DefaultUnitFormat.maximumDigits,
|
|
15
|
+
useGrouping: true
|
|
16
|
+
};
|
|
17
|
+
this.defaultScaledUnitFormatters = new Map();
|
|
18
|
+
// Format options to use for numbers that have leading zeros. It limits the number of rendered
|
|
19
|
+
// digits using 'maximumFractionDigits', which will result in less than 6 significant digits
|
|
20
|
+
// in order to render no more than 6 total digits.
|
|
21
|
+
this.leadingZeroIntlNumberFormatOptions = {
|
|
22
|
+
maximumFractionDigits: DefaultUnitFormat.maximumDigits - 1,
|
|
23
|
+
useGrouping: true
|
|
24
|
+
};
|
|
25
|
+
this.leadingZeroScaledUnitFormatters = new Map();
|
|
26
|
+
// Format options for numbers that should be displayed in exponential notation. This should be used
|
|
27
|
+
// for numbers with magintudes over 'exponentialUpperBound' or under 'exponentialLowerBound'.
|
|
28
|
+
this.exponentialIntlNumberFormatOptions = {
|
|
29
|
+
maximumSignificantDigits: DefaultUnitFormat.maximumDigits,
|
|
30
|
+
notation: 'scientific'
|
|
31
|
+
};
|
|
32
|
+
for (const unit of unitScale.supportedScaledUnits) {
|
|
33
|
+
this.defaultScaledUnitFormatters.set(unit.scaleFactor, unit.scaledUnitFormatFactory({
|
|
34
|
+
locale,
|
|
35
|
+
intlNumberFormatOptions: this.defaultIntlNumberFormatOptions
|
|
36
|
+
}));
|
|
37
|
+
this.leadingZeroScaledUnitFormatters.set(unit.scaleFactor, unit.scaledUnitFormatFactory({
|
|
38
|
+
locale,
|
|
39
|
+
intlNumberFormatOptions: this.leadingZeroIntlNumberFormatOptions
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
this.exponentialScaledUnitFormatter = unitScale.baseScaledUnit.scaledUnitFormatFactory({
|
|
43
|
+
locale,
|
|
44
|
+
intlNumberFormatOptions: this.exponentialIntlNumberFormatOptions
|
|
45
|
+
});
|
|
46
|
+
this.unitScale = unitScale;
|
|
47
|
+
}
|
|
48
|
+
resolvedOptions() {
|
|
49
|
+
return {
|
|
50
|
+
unitScale: this.unitScale
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
tryFormat(number) {
|
|
54
|
+
// Normalize +0 / -0 --> +0
|
|
55
|
+
const numberNormalized = number === 0 ? 0 : number;
|
|
56
|
+
const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(numberNormalized);
|
|
57
|
+
const numberStyle = this.resolveNumberStyle(scaledValue);
|
|
58
|
+
switch (numberStyle) {
|
|
59
|
+
case 'default': {
|
|
60
|
+
const scaledUnitFormatter = this.defaultScaledUnitFormatters.get(scaledUnit.scaleFactor);
|
|
61
|
+
return scaledUnitFormatter.format(scaledValue);
|
|
62
|
+
}
|
|
63
|
+
case 'leadingZero': {
|
|
64
|
+
const scaledUnitFormatter = this.leadingZeroScaledUnitFormatters.get(scaledUnit.scaleFactor);
|
|
65
|
+
return scaledUnitFormatter.format(scaledValue);
|
|
66
|
+
}
|
|
67
|
+
case 'exponential': {
|
|
68
|
+
const scaledUnitFormatter = this.exponentialScaledUnitFormatter;
|
|
69
|
+
return scaledUnitFormatter.format(numberNormalized);
|
|
70
|
+
}
|
|
71
|
+
default:
|
|
72
|
+
throw new Error('Unexpected number format style');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
resolveNumberStyle(number) {
|
|
76
|
+
if (number === 0) {
|
|
77
|
+
return 'default';
|
|
78
|
+
}
|
|
79
|
+
const absoluteValue = Math.abs(number);
|
|
80
|
+
if (absoluteValue >= DefaultUnitFormat.exponentialUpperBound
|
|
81
|
+
|| absoluteValue < DefaultUnitFormat.exponentialLowerBound) {
|
|
82
|
+
return 'exponential';
|
|
83
|
+
}
|
|
84
|
+
// Ideally, we could set 'roundingPriority: "lessPrecision"' with a formatter that has both 'maximumSignificantDigits' and
|
|
85
|
+
// 'maximumFractionDigits' configured instead of having two different formatters that we conditionally choose between. However,
|
|
86
|
+
// 'roundingPrioirty' is not supported yet in all browsers.
|
|
87
|
+
if (absoluteValue < 1) {
|
|
88
|
+
return 'leadingZero';
|
|
89
|
+
}
|
|
90
|
+
return 'default';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// The maximum number of digits that should be rendered for any given value.
|
|
94
|
+
DefaultUnitFormat.maximumDigits = 6;
|
|
95
|
+
// Use exponential notation for numbers that will be rendered with 3 leading 0s or more.
|
|
96
|
+
// Because a maximum of 6 digits are rendered, showing more than 3 leading 0s is not ideal
|
|
97
|
+
// because then at least half of the displayed digits will be leading 0s.
|
|
98
|
+
DefaultUnitFormat.exponentialLowerBound = 0.000995;
|
|
99
|
+
// Use exponential formatting for numbers whose magnitude cannot otherwise be displayed
|
|
100
|
+
// with 6 digits or less.
|
|
101
|
+
DefaultUnitFormat.exponentialUpperBound = 999999.5;
|
|
102
|
+
//# sourceMappingURL=default-unit-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/default-unit-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,oBAAoB,CAAC;AAGnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAI3E;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAgD7C,YACI,MAAc,EACd,EA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,OAAO,aAAa,CAAC;SACxB;QACD,0HAA0H;QAC1H,+HAA+H;QAC/H,2DAA2D;QAC3D,IAAI,aAAa,GAAG,CAAC,EAAE;YACnB,OAAO,aAAa,CAAC;SACxB;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;;AApID,4EAA4E;AACpD,+BAAa,GAAG,CAAC,CAAC;AAE1C,wFAAwF;AACxF,0FAA0F;AAC1F,yEAAyE;AACjD,uCAAqB,GAAG,QAAQ,CAAC;AAEzD,uFAAuF;AACvF,yBAAyB;AACD,uCAAqB,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ScaledUnitFormatFactoryOptions } from '../../unit-scale/base/scaled-unit';
|
|
2
|
+
import { ScaledUnitFormat } from '../../unit-scale/base/scaled-unit-format';
|
|
3
|
+
import type { UnitPrefix } from './unit-prefix';
|
|
4
|
+
import type { UnitTranslation } from './unit-translation';
|
|
5
|
+
/**
|
|
6
|
+
* A formatter for units that are not supported by Intl.NumberFormat
|
|
7
|
+
*/
|
|
8
|
+
export declare class ManuallyTranslatedScaledUnitFormat extends ScaledUnitFormat {
|
|
9
|
+
private readonly unitTranslations;
|
|
10
|
+
private readonly unitPrefix;
|
|
11
|
+
private readonly pluralRules;
|
|
12
|
+
private readonly formatter;
|
|
13
|
+
private readonly unitTranslation;
|
|
14
|
+
protected constructor(scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions, unitTranslations: ReadonlyMap<string, UnitTranslation>, unitPrefix: UnitPrefix);
|
|
15
|
+
static createFactory(unitTranslations: ReadonlyMap<string, UnitTranslation>, unitPrefix: UnitPrefix): (scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions) => ManuallyTranslatedScaledUnitFormat;
|
|
16
|
+
format(value: number): string;
|
|
17
|
+
private getTranslationToUse;
|
|
18
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ScaledUnitFormat } from '../../unit-scale/base/scaled-unit-format';
|
|
2
|
+
/**
|
|
3
|
+
* A formatter for units that are not supported by Intl.NumberFormat
|
|
4
|
+
*/
|
|
5
|
+
export class ManuallyTranslatedScaledUnitFormat extends ScaledUnitFormat {
|
|
6
|
+
constructor(scaledUnitFormatFactoryOptions, unitTranslations, unitPrefix) {
|
|
7
|
+
super(scaledUnitFormatFactoryOptions);
|
|
8
|
+
this.unitTranslations = unitTranslations;
|
|
9
|
+
this.unitPrefix = unitPrefix;
|
|
10
|
+
this.pluralRules = new Intl.PluralRules(this.locale);
|
|
11
|
+
this.formatter = new Intl.NumberFormat(this.locale, this.intlNumberFormatOptions);
|
|
12
|
+
this.unitTranslation = this.getTranslationToUse(this.locale);
|
|
13
|
+
}
|
|
14
|
+
static createFactory(unitTranslations, unitPrefix) {
|
|
15
|
+
return (scaledUnitFormatFactoryOptions) => new ManuallyTranslatedScaledUnitFormat(scaledUnitFormatFactoryOptions, unitTranslations, unitPrefix);
|
|
16
|
+
}
|
|
17
|
+
format(value) {
|
|
18
|
+
const formatted = this.formatter.format(value);
|
|
19
|
+
if (!this.unitPrefix.isBase()) {
|
|
20
|
+
return `${formatted} ${this.unitPrefix.text}${this.unitTranslation.symbol}`;
|
|
21
|
+
}
|
|
22
|
+
// Some languages have more than two forms (singular/plural) of cardinal
|
|
23
|
+
// numbers, but we are treating anything other than the 'one' form as plural.
|
|
24
|
+
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules#description
|
|
25
|
+
//
|
|
26
|
+
// Because PluralRules.select() takes a number (not a string), it cannot differentiate
|
|
27
|
+
// between 1 and 1.0. When NumberFormat is configured to format with a set number
|
|
28
|
+
// of fractional digits, those fractional digits can have an effect on the pluralization
|
|
29
|
+
// of the unit. E.g. in English, it formats "1 byte" vs "1.0 bytes". Thus there is
|
|
30
|
+
// sometimes an inconsistency between unit pluralization for the same number, based
|
|
31
|
+
// on whether it's supported by NumberFormat, or manually translated.
|
|
32
|
+
const unitLabel = this.pluralRules.select(value) === 'one'
|
|
33
|
+
? this.unitTranslation.singular
|
|
34
|
+
: this.unitTranslation.plural;
|
|
35
|
+
return `${formatted} ${unitLabel}`;
|
|
36
|
+
}
|
|
37
|
+
getTranslationToUse(locale) {
|
|
38
|
+
const localeObject = new Intl.Locale(locale ?? 'en');
|
|
39
|
+
const language = localeObject.language;
|
|
40
|
+
const region = localeObject.region;
|
|
41
|
+
const regionSpecificMatchedTranslations = region
|
|
42
|
+
? this.unitTranslations.get(`${language}-${region}`) // do not include any other subtags that might be in the given locale string
|
|
43
|
+
: null;
|
|
44
|
+
return (regionSpecificMatchedTranslations
|
|
45
|
+
?? this.unitTranslations.get(language)
|
|
46
|
+
?? this.unitTranslations.get('en'));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=manually-translated-scaled-unit-format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manually-translated-scaled-unit-format.js","sourceRoot":"","sources":["../../../../../../src/utilities/unit-format/manually-translated-unit-scale/base/manually-translated-scaled-unit-format.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAI5E;;GAEG;AACH,MAAM,OAAO,kCAAmC,SAAQ,gBAAgB;IAKpE,YACI,8BAA8D,EAC7C,gBAAsD,EACtD,UAAsB;QAEvC,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAHrB,qBAAgB,GAAhB,gBAAgB,CAAsC;QACtD,eAAU,GAAV,UAAU,CAAY;QAGvC,IAAI,CAAC,WAAW,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAClC,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,uBAAuB,CAC/B,CAAC;QACF,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CA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IAAI,CAAC;QACX,OAAO,CACH,iCAAiC;eAC9B,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC;eACnC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAE,CACtC,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UnitPrefix } from './unit-prefix';
|
|
2
|
+
import type { UnitTranslation } from './unit-translation';
|
|
3
|
+
import { UnitScale } from '../../unit-scale/base/unit-scale';
|
|
4
|
+
/**
|
|
5
|
+
* A unit scale that is not supported by Intl.NumberFormat and has manually provided translation strings
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class ManuallyTranslatedUnitScale extends UnitScale {
|
|
8
|
+
constructor(unitTranslations: ReadonlyMap<string, UnitTranslation>, supportedUnitPrefixes: readonly UnitPrefix[]);
|
|
9
|
+
private static createSupportedScaledUnits;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ManuallyTranslatedScaledUnitFormat } from './manually-translated-scaled-unit-format';
|
|
2
|
+
import { ScaledUnit } from '../../unit-scale/base/scaled-unit';
|
|
3
|
+
import { UnitScale } from '../../unit-scale/base/unit-scale';
|
|
4
|
+
/**
|
|
5
|
+
* A unit scale that is not supported by Intl.NumberFormat and has manually provided translation strings
|
|
6
|
+
*/
|
|
7
|
+
export class ManuallyTranslatedUnitScale extends UnitScale {
|
|
8
|
+
constructor(unitTranslations, supportedUnitPrefixes) {
|
|
9
|
+
super(ManuallyTranslatedUnitScale.createSupportedScaledUnits(unitTranslations, supportedUnitPrefixes));
|
|
10
|
+
}
|
|
11
|
+
static createSupportedScaledUnits(unitTranslations, supportedUnitPrefixes) {
|
|
12
|
+
if (!unitTranslations.get('en')) {
|
|
13
|
+
throw new Error('English translations must exist');
|
|
14
|
+
}
|
|
15
|
+
const supportedUnits = supportedUnitPrefixes.map(unitPrefix => new ScaledUnit(unitPrefix.scaleFactor, ManuallyTranslatedScaledUnitFormat.createFactory(unitTranslations, unitPrefix)));
|
|
16
|
+
return supportedUnits;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=manually-translated-unit-scale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manually-translated-unit-scale.js","sourceRoot":"","sources":["../../../../../../src/utilities/unit-format/manually-translated-unit-scale/base/manually-translated-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,0CAA0C,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAG/D,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D;;GAEG;AACH,MAAM,OAAgB,2BAA4B,SAAQ,SAAS;IAC/D,YACI,gBAAsD,EACtD,qBAA4C;QAE5C,KAAK,CACD,2BAA2B,CAAC,0BAA0B,CAClD,gBAAgB,EAChB,qBAAqB,CACxB,CACJ,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,0BAA0B,CACrC,gBAAsD,EACtD,qBAA4C;QAE5C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC7B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;SACtD;QACD,MAAM,cAAc,GAAG,qBAAqB,CAAC,GAAG,CAC5C,UAAU,CAAC,EAAE,CAAC,IAAI,UAAU,CACxB,UAAU,CAAC,WAAW,EACtB,kCAAkC,CAAC,aAAa,CAC5C,gBAAgB,EAChB,UAAU,CACb,CACJ,CACJ,CAAC;QAEF,OAAO,cAAc,CAAC;IAC1B,CAAC;CACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A prefix that represents a scaling factor when applied to a base unit.
|
|
3
|
+
* A base unit is represented as scale factor 1 and empty text.
|
|
4
|
+
*/
|
|
5
|
+
export declare class UnitPrefix {
|
|
6
|
+
readonly scaleFactor: number;
|
|
7
|
+
readonly text: string;
|
|
8
|
+
constructor(scaleFactor: number, text: string);
|
|
9
|
+
isBase(): boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A prefix that represents a scaling factor when applied to a base unit.
|
|
3
|
+
* A base unit is represented as scale factor 1 and empty text.
|
|
4
|
+
*/
|
|
5
|
+
export class UnitPrefix {
|
|
6
|
+
constructor(scaleFactor, text) {
|
|
7
|
+
this.scaleFactor = scaleFactor;
|
|
8
|
+
this.text = text;
|
|
9
|
+
if (scaleFactor === 1 && text !== '') {
|
|
10
|
+
throw new Error('Base scale factor of 1 has unused text and should be empty string');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
isBase() {
|
|
14
|
+
return this.scaleFactor === 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=unit-prefix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit-prefix.js","sourceRoot":"","sources":["../../../../../../src/utilities/unit-format/manually-translated-unit-scale/base/unit-prefix.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,UAAU;IACnB,YACoB,WAAmB,EACnB,IAAY;QADZ,gBAAW,GAAX,WAAW,CAAQ;QACnB,SAAI,GAAJ,IAAI,CAAQ;QAE5B,IAAI,WAAW,KAAK,CAAC,IAAI,IAAI,KAAK,EAAE,EAAE;YAClC,MAAM,IAAI,KAAK,CACX,mEAAmE,CACtE,CAAC;SACL;IACL,CAAC;IAEM,MAAM;QACT,OAAO,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC;IAClC,CAAC;CACJ"}
|
package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-prefixes-metric.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { UnitPrefix } from './unit-prefix';
|
|
2
|
+
/**
|
|
3
|
+
* The metric unit prefixes for at least English, French, German, Japanese, and Chinese.
|
|
4
|
+
*/
|
|
5
|
+
export declare const unitPrefixesMetric: readonly [UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix, UnitPrefix];
|
package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-prefixes-metric.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UnitPrefix } from './unit-prefix';
|
|
2
|
+
/**
|
|
3
|
+
* The metric unit prefixes for at least English, French, German, Japanese, and Chinese.
|
|
4
|
+
*/
|
|
5
|
+
export const unitPrefixesMetric = [
|
|
6
|
+
new UnitPrefix(10 ** -15, 'f'),
|
|
7
|
+
new UnitPrefix(10 ** -12, 'p'),
|
|
8
|
+
new UnitPrefix(10 ** -9, 'n'),
|
|
9
|
+
new UnitPrefix(10 ** -6, 'μ'),
|
|
10
|
+
new UnitPrefix(10 ** -3, 'm'),
|
|
11
|
+
new UnitPrefix(10 ** -2, 'c'),
|
|
12
|
+
new UnitPrefix(10 ** -1, 'd'),
|
|
13
|
+
new UnitPrefix(10 ** 0, ''),
|
|
14
|
+
new UnitPrefix(10 ** 3, 'k'),
|
|
15
|
+
new UnitPrefix(10 ** 6, 'M'),
|
|
16
|
+
new UnitPrefix(10 ** 9, 'G'),
|
|
17
|
+
new UnitPrefix(10 ** 12, 'T'),
|
|
18
|
+
new UnitPrefix(10 ** 15, 'P'),
|
|
19
|
+
new UnitPrefix(10 ** 18, 'E')
|
|
20
|
+
];
|
|
21
|
+
//# sourceMappingURL=unit-prefixes-metric.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit-prefixes-metric.js","sourceRoot":"","sources":["../../../../../../src/utilities/unit-format/manually-translated-unit-scale/base/unit-prefixes-metric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAC9B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC;IAC9B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC;IAC9B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IAC7B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IAC7B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IAC7B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IAC7B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;IAC7B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;IAC3B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IAC5B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IAC5B,IAAI,UAAU,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IAC5B,IAAI,UAAU,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC;IAC7B,IAAI,UAAU,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC;IAC7B,IAAI,UAAU,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC;CACvB,CAAC"}
|
package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-translation.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Representations of a base unit in a particular language
|
|
3
|
+
*/
|
|
4
|
+
export class UnitTranslation {
|
|
5
|
+
constructor(singular, plural, symbol) {
|
|
6
|
+
this.singular = singular;
|
|
7
|
+
this.plural = plural;
|
|
8
|
+
this.symbol = symbol;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=unit-translation.js.map
|
package/dist/esm/utilities/unit-format/manually-translated-unit-scale/base/unit-translation.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit-translation.js","sourceRoot":"","sources":["../../../../../../src/utilities/unit-format/manually-translated-unit-scale/base/unit-translation.ts"],"names":[],"mappings":"AAAA;;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"}
|
package/dist/esm/utilities/unit-format/manually-translated-unit-scale/byte-1024-unit-scale.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ManuallyTranslatedUnitScale } from './base/manually-translated-unit-scale';
|
|
2
|
+
/**
|
|
3
|
+
* Byte units (1024-based)
|
|
4
|
+
*/
|
|
5
|
+
declare class Byte1024UnitScale extends ManuallyTranslatedUnitScale {
|
|
6
|
+
constructor();
|
|
7
|
+
}
|
|
8
|
+
export declare const byte1024UnitScale: Byte1024UnitScale;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ManuallyTranslatedUnitScale } from './base/manually-translated-unit-scale';
|
|
2
|
+
import { UnitPrefix } from './base/unit-prefix';
|
|
3
|
+
import { UnitTranslation } from './base/unit-translation';
|
|
4
|
+
/**
|
|
5
|
+
* Byte units (1024-based)
|
|
6
|
+
*/
|
|
7
|
+
class Byte1024UnitScale extends ManuallyTranslatedUnitScale {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(new Map([
|
|
10
|
+
['en', new UnitTranslation('byte', 'bytes', 'B')],
|
|
11
|
+
['fr', new UnitTranslation('octet', 'octets', 'o')],
|
|
12
|
+
['de', new UnitTranslation('Byte', 'Byte', 'B')],
|
|
13
|
+
['ja', new UnitTranslation('バイト', 'バイト', 'B')],
|
|
14
|
+
['zh', new UnitTranslation('字节', '字节', 'B')]
|
|
15
|
+
]), [
|
|
16
|
+
new UnitPrefix(1024 ** 0, ''),
|
|
17
|
+
new UnitPrefix(1024 ** 1, 'Ki'),
|
|
18
|
+
new UnitPrefix(1024 ** 2, 'Mi'),
|
|
19
|
+
new UnitPrefix(1024 ** 3, 'Gi'),
|
|
20
|
+
new UnitPrefix(1024 ** 4, 'Ti'),
|
|
21
|
+
new UnitPrefix(1024 ** 5, 'Pi')
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export const byte1024UnitScale = new Byte1024UnitScale();
|
|
26
|
+
//# sourceMappingURL=byte-1024-unit-scale.js.map
|
package/dist/esm/utilities/unit-format/manually-translated-unit-scale/byte-1024-unit-scale.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"byte-1024-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/manually-translated-unit-scale/byte-1024-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;GAEG;AACH,MAAM,iBAAkB,SAAQ,2BAA2B;IACvD;QACI,KAAK,CACD,IAAI,GAAG,CAAC;YACJ,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;YACjD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;YACnD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;YAChD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;YAC9C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;SAC/C,CAAC,EACF;YACI,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YAC7B,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;YAC/B,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;YAC/B,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;YAC/B,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;YAC/B,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC;SAClC,CACJ,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ManuallyTranslatedUnitScale } from './base/manually-translated-unit-scale';
|
|
2
|
+
/**
|
|
3
|
+
* Voltage unit scale
|
|
4
|
+
*/
|
|
5
|
+
declare class VoltUnitScale extends ManuallyTranslatedUnitScale {
|
|
6
|
+
constructor();
|
|
7
|
+
}
|
|
8
|
+
export declare const voltUnitScale: VoltUnitScale;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ManuallyTranslatedUnitScale } from './base/manually-translated-unit-scale';
|
|
2
|
+
import { unitPrefixesMetric } from './base/unit-prefixes-metric';
|
|
3
|
+
import { UnitTranslation } from './base/unit-translation';
|
|
4
|
+
/**
|
|
5
|
+
* Voltage unit scale
|
|
6
|
+
*/
|
|
7
|
+
class VoltUnitScale extends ManuallyTranslatedUnitScale {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(new Map([
|
|
10
|
+
['en', new UnitTranslation('volt', 'volts', 'V')],
|
|
11
|
+
['fr', new UnitTranslation('volt', 'volts', 'V')],
|
|
12
|
+
['de', new UnitTranslation('Volt', 'Volt', 'V')],
|
|
13
|
+
['ja', new UnitTranslation('ボルト', 'ボルト', 'V')],
|
|
14
|
+
['zh', new UnitTranslation('伏特', '伏特', 'V')]
|
|
15
|
+
]), unitPrefixesMetric);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export const voltUnitScale = new VoltUnitScale();
|
|
19
|
+
//# sourceMappingURL=volt-unit-scale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volt-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/manually-translated-unit-scale/volt-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;GAEG;AACH,MAAM,aAAc,SAAQ,2BAA2B;IACnD;QACI,KAAK,CACD,IAAI,GAAG,CAAC;YACJ,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;YACjD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;YACjD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;YAChD,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;YAC9C,CAAC,IAAI,EAAE,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;SAC/C,CAAC,EACF,kBAAkB,CACrB,CAAC;IACN,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC"}
|
package/dist/esm/utilities/unit-format/unit-scale/base/intl-number-format-scaled-unit-format.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ScaledUnitFormatFactoryOptions } from './scaled-unit';
|
|
2
|
+
import { ScaledUnitFormat } from './scaled-unit-format';
|
|
3
|
+
/**
|
|
4
|
+
* A formatter for units that can be formatted/translated by Intl.NumberFormat
|
|
5
|
+
*/
|
|
6
|
+
export declare class IntlNumberFormatScaledUnitFormat extends ScaledUnitFormat {
|
|
7
|
+
private readonly formatter;
|
|
8
|
+
protected constructor(scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions, unitSpecificIntlNumberFormatOptions?: Intl.NumberFormatOptions);
|
|
9
|
+
static createFactory(unitSpecificIntlNumberFormatOptions?: Intl.NumberFormatOptions): (scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions) => IntlNumberFormatScaledUnitFormat;
|
|
10
|
+
format(value: number): string;
|
|
11
|
+
}
|
package/dist/esm/utilities/unit-format/unit-scale/base/intl-number-format-scaled-unit-format.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ScaledUnitFormat } from './scaled-unit-format';
|
|
2
|
+
/**
|
|
3
|
+
* A formatter for units that can be formatted/translated by Intl.NumberFormat
|
|
4
|
+
*/
|
|
5
|
+
export class IntlNumberFormatScaledUnitFormat extends ScaledUnitFormat {
|
|
6
|
+
constructor(scaledUnitFormatFactoryOptions, unitSpecificIntlNumberFormatOptions = {}) {
|
|
7
|
+
super(scaledUnitFormatFactoryOptions);
|
|
8
|
+
this.formatter = new Intl.NumberFormat(this.locale, {
|
|
9
|
+
...unitSpecificIntlNumberFormatOptions,
|
|
10
|
+
// Application configured options override unit specific options
|
|
11
|
+
...this.intlNumberFormatOptions
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
static createFactory(unitSpecificIntlNumberFormatOptions = {}) {
|
|
15
|
+
return (scaledUnitFormatFactoryOptions) => new IntlNumberFormatScaledUnitFormat(scaledUnitFormatFactoryOptions, unitSpecificIntlNumberFormatOptions);
|
|
16
|
+
}
|
|
17
|
+
format(value) {
|
|
18
|
+
return this.formatter.format(value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=intl-number-format-scaled-unit-format.js.map
|
package/dist/esm/utilities/unit-format/unit-scale/base/intl-number-format-scaled-unit-format.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl-number-format-scaled-unit-format.js","sourceRoot":"","sources":["../../../../../../src/utilities/unit-format/unit-scale/base/intl-number-format-scaled-unit-format.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD;;GAEG;AACH,MAAM,OAAO,gCAAiC,SAAQ,gBAAgB;IAGlE,YACI,8BAA8D,EAC9D,sCAAgE,EAAE;QAElE,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,sCAAgE,EAAE;QAElE,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"}
|