@ni/nimble-components 34.10.3 → 35.0.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.
Files changed (67) hide show
  1. package/dist/all-components-bundle.js +48 -48
  2. package/dist/all-components-bundle.js.map +1 -1
  3. package/dist/all-components-bundle.min.js +10 -11
  4. package/dist/all-components-bundle.min.js.map +1 -1
  5. package/dist/esm/table-column/number-text/index.d.ts +1 -1
  6. package/dist/esm/table-column/number-text/index.js +2 -2
  7. package/dist/esm/table-column/number-text/index.js.map +1 -1
  8. package/dist/esm/table-column/number-text/models/{number-text-unit-format.d.ts → unit-format-number-text.d.ts} +7 -7
  9. package/dist/esm/table-column/number-text/models/{number-text-unit-format.js → unit-format-number-text.js} +14 -14
  10. package/dist/esm/table-column/number-text/models/unit-format-number-text.js.map +1 -0
  11. package/dist/esm/unit/base/unit.d.ts +1 -1
  12. package/dist/esm/unit/base/unit.js.map +1 -1
  13. package/dist/esm/unit/byte/index.js +5 -5
  14. package/dist/esm/unit/byte/index.js.map +1 -1
  15. package/dist/esm/unit/celsius/index.js +2 -2
  16. package/dist/esm/unit/celsius/index.js.map +1 -1
  17. package/dist/esm/unit/fahrenheit/index.js +2 -2
  18. package/dist/esm/unit/fahrenheit/index.js.map +1 -1
  19. package/dist/esm/unit/volt/index.js +2 -2
  20. package/dist/esm/unit/volt/index.js.map +1 -1
  21. package/package.json +2 -1
  22. package/dist/esm/table-column/number-text/models/number-text-unit-format.js.map +0 -1
  23. package/dist/esm/utilities/unit-format/decimal-unit-format.d.ts +0 -19
  24. package/dist/esm/utilities/unit-format/decimal-unit-format.js +0 -46
  25. package/dist/esm/utilities/unit-format/decimal-unit-format.js.map +0 -1
  26. package/dist/esm/utilities/unit-format/default-unit-format.d.ts +0 -22
  27. package/dist/esm/utilities/unit-format/default-unit-format.js +0 -70
  28. package/dist/esm/utilities/unit-format/default-unit-format.js.map +0 -1
  29. package/dist/esm/utilities/unit-format/scaled-unit/scaled-unit.d.ts +0 -16
  30. package/dist/esm/utilities/unit-format/scaled-unit/scaled-unit.js +0 -13
  31. package/dist/esm/utilities/unit-format/scaled-unit/scaled-unit.js.map +0 -1
  32. package/dist/esm/utilities/unit-format/scaled-unit-format/intl-number-format-scaled-unit-format.d.ts +0 -11
  33. package/dist/esm/utilities/unit-format/scaled-unit-format/intl-number-format-scaled-unit-format.js +0 -21
  34. package/dist/esm/utilities/unit-format/scaled-unit-format/intl-number-format-scaled-unit-format.js.map +0 -1
  35. package/dist/esm/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.d.ts +0 -43
  36. package/dist/esm/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.js +0 -63
  37. package/dist/esm/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.js.map +0 -1
  38. package/dist/esm/utilities/unit-format/scaled-unit-format/scaled-unit-format.d.ts +0 -10
  39. package/dist/esm/utilities/unit-format/scaled-unit-format/scaled-unit-format.js +0 -10
  40. package/dist/esm/utilities/unit-format/scaled-unit-format/scaled-unit-format.js.map +0 -1
  41. package/dist/esm/utilities/unit-format/unit-format.d.ts +0 -16
  42. package/dist/esm/utilities/unit-format/unit-format.js +0 -21
  43. package/dist/esm/utilities/unit-format/unit-format.js.map +0 -1
  44. package/dist/esm/utilities/unit-format/unit-scale/byte-1024-unit-scale.d.ts +0 -9
  45. package/dist/esm/utilities/unit-format/unit-scale/byte-1024-unit-scale.js +0 -31
  46. package/dist/esm/utilities/unit-format/unit-scale/byte-1024-unit-scale.js.map +0 -1
  47. package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.d.ts +0 -9
  48. package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.js +0 -25
  49. package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.js.map +0 -1
  50. package/dist/esm/utilities/unit-format/unit-scale/celsius-unit-scale.d.ts +0 -9
  51. package/dist/esm/utilities/unit-format/unit-scale/celsius-unit-scale.js +0 -18
  52. package/dist/esm/utilities/unit-format/unit-scale/celsius-unit-scale.js.map +0 -1
  53. package/dist/esm/utilities/unit-format/unit-scale/fahrenheit-unit-scale.d.ts +0 -9
  54. package/dist/esm/utilities/unit-format/unit-scale/fahrenheit-unit-scale.js +0 -18
  55. package/dist/esm/utilities/unit-format/unit-scale/fahrenheit-unit-scale.js.map +0 -1
  56. package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.d.ts +0 -9
  57. package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.js +0 -15
  58. package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.js.map +0 -1
  59. package/dist/esm/utilities/unit-format/unit-scale/unit-scale.d.ts +0 -15
  60. package/dist/esm/utilities/unit-format/unit-scale/unit-scale.js +0 -49
  61. package/dist/esm/utilities/unit-format/unit-scale/unit-scale.js.map +0 -1
  62. package/dist/esm/utilities/unit-format/unit-scale/utilities/metrix-prefixes.d.ts +0 -1
  63. package/dist/esm/utilities/unit-format/unit-scale/utilities/metrix-prefixes.js +0 -17
  64. package/dist/esm/utilities/unit-format/unit-scale/utilities/metrix-prefixes.js.map +0 -1
  65. package/dist/esm/utilities/unit-format/unit-scale/volt-unit-scale.d.ts +0 -9
  66. package/dist/esm/utilities/unit-format/unit-scale/volt-unit-scale.js +0 -24
  67. package/dist/esm/utilities/unit-format/unit-scale/volt-unit-scale.js.map +0 -1
@@ -1,13 +0,0 @@
1
- /**
2
- * A unit that represents a scaled version of a base unit.
3
- */
4
- export class ScaledUnit {
5
- constructor(scaleFactor, scaledUnitFormatFactory) {
6
- this.scaleFactor = scaleFactor;
7
- this.scaledUnitFormatFactory = scaledUnitFormatFactory;
8
- }
9
- isBase() {
10
- return this.scaleFactor === 1;
11
- }
12
- }
13
- //# sourceMappingURL=scaled-unit.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scaled-unit.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/scaled-unit/scaled-unit.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/scaled-unit-format';\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,11 +0,0 @@
1
- import type { ScaledUnitFormatFactoryOptions } from '../scaled-unit/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
- }
@@ -1,21 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"intl-number-format-scaled-unit-format.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/scaled-unit-format/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,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/scaled-unit';\nimport { ScaledUnitFormat } from './scaled-unit-format';\n\n/**\n * A formatter for units that can be formatted/translated by Intl.NumberFormat\n */\nexport class IntlNumberFormatScaledUnitFormat 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 ): IntlNumberFormatScaledUnitFormat => new IntlNumberFormatScaledUnitFormat(\n scaledUnitFormatFactoryOptions,\n unitSpecificIntlNumberFormatOptions\n );\n }\n\n public format(value: number): string {\n return this.formatter.format(value);\n }\n}\n"]}
@@ -1,43 +0,0 @@
1
- import type { ScaledUnitFormatFactoryOptions } from '../scaled-unit/scaled-unit';
2
- import { ScaledUnitFormat } from './scaled-unit-format';
3
- /**
4
- * Representations of a unit in a particular language
5
- */
6
- export declare class UnitTranslation {
7
- readonly singular: string;
8
- readonly plural: string;
9
- readonly symbol: string;
10
- constructor(singular: string, plural: string, symbol: string);
11
- }
12
- /**
13
- * A map of locales of string format "[lang]" or "[lang]-[region]", for example "en" and / or "en-us", to UnitTranslation objects
14
- */
15
- export type UnitTranslations = ReadonlyMap<string, UnitTranslation>;
16
- export interface ManuallyTranslatedScaledUnitFormatOptions {
17
- /**
18
- * Translations for the unit by locale string.
19
- * The locale strings must be of the form [lang] or [lang]-[region], for example "en" and / or "en-us".
20
- * Other subtags besides lang and region are not supported.
21
- * Translations for "en" must be provided.
22
- */
23
- readonly unitTranslations: UnitTranslations;
24
- /**
25
- * String for prefix of this scaled unit, for example "k" (for kilo-).
26
- * Assumed the same across languages.
27
- * Base unit must use "", i.e. empty string, as the scaled prefix text.
28
- */
29
- readonly scaledPrefixText: string;
30
- }
31
- /**
32
- * A formatter for units that are not supported by Intl.NumberFormat
33
- */
34
- export declare class ManuallyTranslatedScaledUnitFormat extends ScaledUnitFormat {
35
- private readonly pluralRules;
36
- private readonly formatter;
37
- private readonly unitTranslation;
38
- private readonly scaledPrefixText;
39
- protected constructor(scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions, { unitTranslations, scaledPrefixText }: ManuallyTranslatedScaledUnitFormatOptions);
40
- static createFactory(manuallyTranslatedScaledUnitFormatOptions: ManuallyTranslatedScaledUnitFormatOptions): (scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions) => ManuallyTranslatedScaledUnitFormat;
41
- format(value: number): string;
42
- private getTranslationToUse;
43
- }
@@ -1,63 +0,0 @@
1
- import { ScaledUnitFormat } from './scaled-unit-format';
2
- /**
3
- * Representations of a unit in a particular language
4
- */
5
- export class UnitTranslation {
6
- constructor(singular, plural, symbol) {
7
- this.singular = singular;
8
- this.plural = plural;
9
- this.symbol = symbol;
10
- }
11
- }
12
- /**
13
- * A formatter for units that are not supported by Intl.NumberFormat
14
- */
15
- export class ManuallyTranslatedScaledUnitFormat extends ScaledUnitFormat {
16
- constructor(scaledUnitFormatFactoryOptions, { unitTranslations, scaledPrefixText }) {
17
- super(scaledUnitFormatFactoryOptions);
18
- if (!unitTranslations.get('en')) {
19
- throw new Error('English translations must exist with locale string "en"');
20
- }
21
- this.pluralRules = new Intl.PluralRules(this.locale);
22
- this.formatter = new Intl.NumberFormat(this.locale, this.intlNumberFormatOptions);
23
- this.unitTranslation = this.getTranslationToUse(unitTranslations, this.locale);
24
- this.scaledPrefixText = scaledPrefixText;
25
- }
26
- static createFactory(manuallyTranslatedScaledUnitFormatOptions) {
27
- return (scaledUnitFormatFactoryOptions) => new ManuallyTranslatedScaledUnitFormat(scaledUnitFormatFactoryOptions, manuallyTranslatedScaledUnitFormatOptions);
28
- }
29
- format(value) {
30
- const formatted = this.formatter.format(value);
31
- // For non-base units (which are a scaled prefix text of empty string)
32
- if (this.scaledPrefixText !== '') {
33
- return `${formatted} ${this.scaledPrefixText}${this.unitTranslation.symbol}`;
34
- }
35
- // Some languages have more than two forms (singular/plural) of cardinal
36
- // numbers, but we are treating anything other than the 'one' form as plural.
37
- // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules#description
38
- //
39
- // Because PluralRules.select() takes a number (not a string), it cannot differentiate
40
- // between 1 and 1.0. When NumberFormat is configured to format with a set number
41
- // of fractional digits, those fractional digits can have an effect on the pluralization
42
- // of the unit. E.g. in English, it formats "1 byte" vs "1.0 bytes". Thus there is
43
- // sometimes an inconsistency between unit pluralization for the same number, based
44
- // on whether it's supported by NumberFormat, or manually translated.
45
- const unitLabel = this.pluralRules.select(value) === 'one'
46
- ? this.unitTranslation.singular
47
- : this.unitTranslation.plural;
48
- return `${formatted} ${unitLabel}`;
49
- }
50
- getTranslationToUse(unitTranslations, locale) {
51
- const localeObject = new Intl.Locale(locale ?? 'en');
52
- const language = localeObject.language;
53
- const region = localeObject.region;
54
- const regionSpecificMatchedTranslations = region
55
- ? unitTranslations.get(`${language}-${region}`)
56
- : undefined;
57
- return (regionSpecificMatchedTranslations
58
- ?? unitTranslations.get(language)
59
- ?? unitTranslations.get('en'));
60
- }
61
- }
62
- /* eslint-enable max-classes-per-file */
63
- //# sourceMappingURL=manually-translated-scaled-unit-format.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manually-translated-scaled-unit-format.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD;;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,CAAC;QACN,CAAC;QACD,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,CAC3C,gBAAgB,EAChB,IAAI,CAAC,MAAM,CACd,CAAC;QACF,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC7C,CAAC;IAEM,MAAM,CAAC,aAAa,CACvB,yCAAoF;QAEpF,OAAO,CACH,8BAA8D,EAC5B,EAAE,CAAC,IAAI,kCAAkC,CAC3E,8BAA8B,EAC9B,yCAAyC,CAC5C,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,KAAa;QACvB,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/C,sEAAsE;QACtE,IAAI,IAAI,CAAC,gBAAgB,KAAK,EAAE,EAAE,CAAC;YAC/B,OAAO,GAAG,SAAS,IAAI,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;QACjF,CAAC;QAED,wEAAwE;QACxE,6EAA6E;QAC7E,oHAAoH;QACpH,EAAE;QACF,sFAAsF;QACtF,iFAAiF;QACjF,wFAAwF;QACxF,kFAAkF;QAClF,mFAAmF;QACnF,qEAAqE;QACrE,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK;YACtD,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ;YAC/B,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,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 */\nimport type { ScaledUnitFormatFactoryOptions } from '../scaled-unit/scaled-unit';\nimport { ScaledUnitFormat } from './scaled-unit-format';\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 ManuallyTranslatedScaledUnitFormatOptions {\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 ManuallyTranslatedScaledUnitFormat 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 }: ManuallyTranslatedScaledUnitFormatOptions\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 manuallyTranslatedScaledUnitFormatOptions: ManuallyTranslatedScaledUnitFormatOptions\n ) {\n return (\n scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions\n ): ManuallyTranslatedScaledUnitFormat => new ManuallyTranslatedScaledUnitFormat(\n scaledUnitFormatFactoryOptions,\n manuallyTranslatedScaledUnitFormatOptions\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,10 +0,0 @@
1
- import type { ScaledUnitFormatFactoryOptions } from '../scaled-unit/scaled-unit';
2
- /**
3
- * A class that knows how to format a numeric value as a string that includes units.
4
- */
5
- export declare abstract class ScaledUnitFormat {
6
- protected readonly locale: string;
7
- protected readonly intlNumberFormatOptions?: Intl.NumberFormatOptions;
8
- protected constructor(scaledUnitFormatFactoryOptions: ScaledUnitFormatFactoryOptions);
9
- abstract format(value: number): string;
10
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * A class that knows how to format a numeric value as a string that includes units.
3
- */
4
- export class ScaledUnitFormat {
5
- constructor(scaledUnitFormatFactoryOptions) {
6
- this.locale = scaledUnitFormatFactoryOptions.locale;
7
- this.intlNumberFormatOptions = scaledUnitFormatFactoryOptions.intlNumberFormatOptions;
8
- }
9
- }
10
- //# sourceMappingURL=scaled-unit-format.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scaled-unit-format.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/scaled-unit-format/scaled-unit-format.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/scaled-unit';\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,16 +0,0 @@
1
- import type { UnitScale } from './unit-scale/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
- }
@@ -1,21 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/unit-format.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/unit-scale';\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,9 +0,0 @@
1
- import { UnitScale } from './unit-scale';
2
- /**
3
- * Byte units (1024-based)
4
- */
5
- declare class Byte1024UnitScale extends UnitScale {
6
- constructor();
7
- }
8
- export declare const byte1024UnitScale: Byte1024UnitScale;
9
- export {};
@@ -1,31 +0,0 @@
1
- import { ScaledUnit } from '../scaled-unit/scaled-unit';
2
- import { UnitScale } from './unit-scale';
3
- import { ManuallyTranslatedScaledUnitFormat, UnitTranslation } from '../scaled-unit-format/manually-translated-scaled-unit-format';
4
- const unitTranslations = new Map([
5
- ['en', new UnitTranslation('byte', 'bytes', 'B')],
6
- ['fr', new UnitTranslation('octet', 'octets', 'o')],
7
- ['de', new UnitTranslation('Byte', 'Byte', 'B')],
8
- ['ja', new UnitTranslation('バイト', 'バイト', 'B')],
9
- ['zh', new UnitTranslation('字节', '字节', 'B')]
10
- ]);
11
- const byte1024Prefixes = [
12
- [1024 ** 0, ''],
13
- [1024 ** 1, 'Ki'],
14
- [1024 ** 2, 'Mi'],
15
- [1024 ** 3, 'Gi'],
16
- [1024 ** 4, 'Ti'],
17
- [1024 ** 5, 'Pi']
18
- ];
19
- /**
20
- * Byte units (1024-based)
21
- */
22
- class Byte1024UnitScale extends UnitScale {
23
- constructor() {
24
- super(byte1024Prefixes.map(([scaleFactor, scaledPrefixText]) => new ScaledUnit(scaleFactor, ManuallyTranslatedScaledUnitFormat.createFactory({
25
- unitTranslations,
26
- scaledPrefixText
27
- }))));
28
- }
29
- }
30
- export const byte1024UnitScale = new Byte1024UnitScale();
31
- //# sourceMappingURL=byte-1024-unit-scale.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"byte-1024-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/unit-scale/byte-1024-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACH,kCAAkC,EAElC,eAAe,EAClB,MAAM,8DAA8D,CAAC;AAEtE,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/scaled-unit';\nimport { UnitScale } from './unit-scale';\nimport {\n ManuallyTranslatedScaledUnitFormat,\n type UnitTranslations,\n UnitTranslation\n} from '../scaled-unit-format/manually-translated-scaled-unit-format';\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 Byte1024UnitScale extends UnitScale {\n public constructor() {\n super(\n byte1024Prefixes.map(\n ([scaleFactor, scaledPrefixText]) => new ScaledUnit(\n scaleFactor,\n ManuallyTranslatedScaledUnitFormat.createFactory({\n unitTranslations,\n scaledPrefixText\n })\n )\n )\n );\n }\n}\n\nexport const byte1024UnitScale = new Byte1024UnitScale();\n"]}
@@ -1,9 +0,0 @@
1
- import { UnitScale } from './unit-scale';
2
- /**
3
- * Byte units (1000-based)
4
- */
5
- declare class ByteUnitScale extends UnitScale {
6
- constructor();
7
- }
8
- export declare const byteUnitScale: ByteUnitScale;
9
- export {};
@@ -1,25 +0,0 @@
1
- import { IntlNumberFormatScaledUnitFormat } from '../scaled-unit-format/intl-number-format-scaled-unit-format';
2
- import { ScaledUnit } from '../scaled-unit/scaled-unit';
3
- import { UnitScale } from './unit-scale';
4
- const byteUnitScaleOptions = [
5
- [1000 ** 0, 'byte', 'long'],
6
- [1000 ** 1, 'kilobyte', 'short'],
7
- [1000 ** 2, 'megabyte', 'short'],
8
- [1000 ** 3, 'gigabyte', 'short'],
9
- [1000 ** 4, 'terabyte', 'short'],
10
- [1000 ** 5, 'petabyte', 'short']
11
- ];
12
- /**
13
- * Byte units (1000-based)
14
- */
15
- class ByteUnitScale extends UnitScale {
16
- constructor() {
17
- super(byteUnitScaleOptions.map(([scaleFactor, unit, unitDisplay]) => new ScaledUnit(scaleFactor, IntlNumberFormatScaledUnitFormat.createFactory({
18
- style: 'unit',
19
- unit,
20
- unitDisplay
21
- }))));
22
- }
23
- }
24
- export const byteUnitScale = new ByteUnitScale();
25
- //# sourceMappingURL=byte-unit-scale.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"byte-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/unit-scale/byte-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,6DAA6D,CAAC;AAC/G,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,oBAAoB,GAAG;IACzB,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,oBAAoB,CAAC,GAAG,CACpB,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 { IntlNumberFormatScaledUnitFormat } from '../scaled-unit-format/intl-number-format-scaled-unit-format';\nimport { ScaledUnit } from '../scaled-unit/scaled-unit';\nimport { UnitScale } from './unit-scale';\n\nconst byteUnitScaleOptions = [\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 ByteUnitScale extends UnitScale {\n public constructor() {\n super(\n byteUnitScaleOptions.map(\n ([scaleFactor, unit, unitDisplay]) => new ScaledUnit(\n scaleFactor,\n IntlNumberFormatScaledUnitFormat.createFactory({\n style: 'unit',\n unit,\n unitDisplay\n })\n )\n )\n );\n }\n}\n\nexport const byteUnitScale = new ByteUnitScale();\n"]}
@@ -1,9 +0,0 @@
1
- import { UnitScale } from './unit-scale';
2
- /**
3
- * Degrees Celsius units
4
- */
5
- declare class CelsiusUnitScale extends UnitScale {
6
- constructor();
7
- }
8
- export declare const celsiusUnitScale: CelsiusUnitScale;
9
- export {};
@@ -1,18 +0,0 @@
1
- import { ScaledUnit } from '../scaled-unit/scaled-unit';
2
- import { IntlNumberFormatScaledUnitFormat } from '../scaled-unit-format/intl-number-format-scaled-unit-format';
3
- import { UnitScale } from './unit-scale';
4
- const celsiusUnitScaleOptions = [[1, 'celsius', 'short']];
5
- /**
6
- * Degrees Celsius units
7
- */
8
- class CelsiusUnitScale extends UnitScale {
9
- constructor() {
10
- super(celsiusUnitScaleOptions.map(([scaleFactor, unit, unitDisplay]) => new ScaledUnit(scaleFactor, IntlNumberFormatScaledUnitFormat.createFactory({
11
- style: 'unit',
12
- unit,
13
- unitDisplay
14
- }))));
15
- }
16
- }
17
- export const celsiusUnitScale = new CelsiusUnitScale();
18
- //# sourceMappingURL=celsius-unit-scale.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"celsius-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/unit-scale/celsius-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gCAAgC,EAAE,MAAM,6DAA6D,CAAC;AAC/G,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,uBAAuB,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,CAAU,CAAC;AAEnE;;GAEG;AACH,MAAM,gBAAiB,SAAQ,SAAS;IACpC;QACI,KAAK,CACD,uBAAuB,CAAC,GAAG,CACvB,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/scaled-unit';\nimport { IntlNumberFormatScaledUnitFormat } from '../scaled-unit-format/intl-number-format-scaled-unit-format';\nimport { UnitScale } from './unit-scale';\n\nconst celsiusUnitScaleOptions = [[1, 'celsius', 'short']] as const;\n\n/**\n * Degrees Celsius units\n */\nclass CelsiusUnitScale extends UnitScale {\n public constructor() {\n super(\n celsiusUnitScaleOptions.map(\n ([scaleFactor, unit, unitDisplay]) => new ScaledUnit(\n scaleFactor,\n IntlNumberFormatScaledUnitFormat.createFactory({\n style: 'unit',\n unit,\n unitDisplay\n })\n )\n )\n );\n }\n}\n\nexport const celsiusUnitScale = new CelsiusUnitScale();\n"]}
@@ -1,9 +0,0 @@
1
- import { UnitScale } from './unit-scale';
2
- /**
3
- * Degrees Fahrenheit units
4
- */
5
- declare class FahrenheitUnitScale extends UnitScale {
6
- constructor();
7
- }
8
- export declare const fahrenheitUnitScale: FahrenheitUnitScale;
9
- export {};
@@ -1,18 +0,0 @@
1
- import { ScaledUnit } from '../scaled-unit/scaled-unit';
2
- import { IntlNumberFormatScaledUnitFormat } from '../scaled-unit-format/intl-number-format-scaled-unit-format';
3
- import { UnitScale } from './unit-scale';
4
- const fahrenheitUnitScaleOptions = [[1, 'fahrenheit', 'short']];
5
- /**
6
- * Degrees Fahrenheit units
7
- */
8
- class FahrenheitUnitScale extends UnitScale {
9
- constructor() {
10
- super(fahrenheitUnitScaleOptions.map(([scaleFactor, unit, unitDisplay]) => new ScaledUnit(scaleFactor, IntlNumberFormatScaledUnitFormat.createFactory({
11
- style: 'unit',
12
- unit,
13
- unitDisplay
14
- }))));
15
- }
16
- }
17
- export const fahrenheitUnitScale = new FahrenheitUnitScale();
18
- //# sourceMappingURL=fahrenheit-unit-scale.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fahrenheit-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/unit-scale/fahrenheit-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gCAAgC,EAAE,MAAM,6DAA6D,CAAC;AAC/G,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,0BAA0B,GAAG,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,CAAU,CAAC;AAEzE;;GAEG;AACH,MAAM,mBAAoB,SAAQ,SAAS;IACvC;QACI,KAAK,CACD,0BAA0B,CAAC,GAAG,CAC1B,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/scaled-unit';\nimport { IntlNumberFormatScaledUnitFormat } from '../scaled-unit-format/intl-number-format-scaled-unit-format';\nimport { UnitScale } from './unit-scale';\n\nconst fahrenheitUnitScaleOptions = [[1, 'fahrenheit', 'short']] as const;\n\n/**\n * Degrees Fahrenheit units\n */\nclass FahrenheitUnitScale extends UnitScale {\n public constructor() {\n super(\n fahrenheitUnitScaleOptions.map(\n ([scaleFactor, unit, unitDisplay]) => new ScaledUnit(\n scaleFactor,\n IntlNumberFormatScaledUnitFormat.createFactory({\n style: 'unit',\n unit,\n unitDisplay\n })\n )\n )\n );\n }\n}\n\nexport const fahrenheitUnitScale = new FahrenheitUnitScale();\n"]}
@@ -1,9 +0,0 @@
1
- import { UnitScale } from './unit-scale';
2
- /**
3
- * Unit scale that is used to passthrough a number without applying scaling or units
4
- */
5
- declare class PassthroughUnitScale extends UnitScale {
6
- constructor();
7
- }
8
- export declare const passthroughUnitScale: PassthroughUnitScale;
9
- export {};
@@ -1,15 +0,0 @@
1
- import { IntlNumberFormatScaledUnitFormat } from '../scaled-unit-format/intl-number-format-scaled-unit-format';
2
- import { ScaledUnit } from '../scaled-unit/scaled-unit';
3
- import { UnitScale } from './unit-scale';
4
- /**
5
- * Unit scale that is used to passthrough a number without applying scaling or units
6
- */
7
- class PassthroughUnitScale extends UnitScale {
8
- constructor() {
9
- super([
10
- new ScaledUnit(10 ** 0, IntlNumberFormatScaledUnitFormat.createFactory({}))
11
- ]);
12
- }
13
- }
14
- export const passthroughUnitScale = new PassthroughUnitScale();
15
- //# sourceMappingURL=passthrough-unit-scale.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"passthrough-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/unit-scale/passthrough-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,6DAA6D,CAAC;AAC/G,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;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 { IntlNumberFormatScaledUnitFormat } from '../scaled-unit-format/intl-number-format-scaled-unit-format';\nimport { ScaledUnit } from '../scaled-unit/scaled-unit';\nimport { UnitScale } from './unit-scale';\n\n/**\n * Unit scale that is used to passthrough a number without applying scaling or units\n */\nclass PassthroughUnitScale extends UnitScale {\n public constructor() {\n super([\n new ScaledUnit(\n 10 ** 0,\n IntlNumberFormatScaledUnitFormat.createFactory({})\n )\n ]);\n }\n}\n\nexport const passthroughUnitScale = new PassthroughUnitScale();\n"]}
@@ -1,15 +0,0 @@
1
- import type { ScaledUnit } from '../scaled-unit/scaled-unit';
2
- interface ScaledNumber {
3
- readonly scaledValue: number;
4
- readonly scaledUnit: ScaledUnit;
5
- }
6
- /**
7
- * A unit scale consisting of a set of scaled units.
8
- */
9
- export declare abstract class UnitScale {
10
- readonly supportedScaledUnits: readonly ScaledUnit[];
11
- readonly baseScaledUnit: ScaledUnit;
12
- constructor(supportedScaledUnits: readonly ScaledUnit[]);
13
- scaleNumber(number: number): ScaledNumber;
14
- }
15
- export {};
@@ -1,49 +0,0 @@
1
- /**
2
- * A unit scale consisting of a set of scaled units.
3
- */
4
- export class UnitScale {
5
- constructor(supportedScaledUnits) {
6
- this.supportedScaledUnits = supportedScaledUnits;
7
- const unitsSorted = supportedScaledUnits.every((curr, i, arr) => i === 0 || arr[i - 1].scaleFactor < curr.scaleFactor);
8
- if (!unitsSorted) {
9
- throw new Error('Supported scaled units must have unique and ordered scale factors');
10
- }
11
- const baseScaledUnit = supportedScaledUnits.find(x => x.isBase());
12
- if (!baseScaledUnit) {
13
- throw new Error('Supported scaled units must include a base scaled unit (scale factor=1)');
14
- }
15
- this.supportedScaledUnits = supportedScaledUnits;
16
- this.baseScaledUnit = baseScaledUnit;
17
- }
18
- // Note that for the sake of reducing complexity in the implementation,
19
- // we do NOT consider the effects of rounding when picking the unit to
20
- // use for a given value. If formatting results in rounding, a value
21
- // may be shown with an unexpected unit. Examples:
22
- // - 999 bytes with two significant digits => "1000 bytes" (instead of "1 kB")
23
- // - 0.00000000000000001 volts (= 0.01 fV) with one fractional digit => "0 fV" (instead of "0 volts")
24
- scaleNumber(number) {
25
- const magnitude = Math.abs(number);
26
- const onlyBaseScaledUnit = this.supportedScaledUnits.length === 1;
27
- if (onlyBaseScaledUnit
28
- || magnitude === 0
29
- || magnitude === Infinity
30
- || Number.isNaN(magnitude)) {
31
- return { scaledValue: number, scaledUnit: this.baseScaledUnit };
32
- }
33
- for (let i = this.supportedScaledUnits.length - 1; i >= 0; i -= 1) {
34
- const scaledUnit = this.supportedScaledUnits[i];
35
- if (magnitude / scaledUnit.scaleFactor >= 1) {
36
- return {
37
- scaledValue: number / scaledUnit.scaleFactor,
38
- scaledUnit
39
- };
40
- }
41
- }
42
- const smallestUnit = this.supportedScaledUnits[0];
43
- return {
44
- scaledValue: number / smallestUnit.scaleFactor,
45
- scaledUnit: smallestUnit
46
- };
47
- }
48
- }
49
- //# sourceMappingURL=unit-scale.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/unit-scale/unit-scale.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/scaled-unit';\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 +0,0 @@
1
- export declare const metricPrefixes: readonly [readonly [number, "f"], readonly [number, "p"], readonly [number, "n"], readonly [number, "μ"], readonly [number, "m"], readonly [number, "c"], readonly [number, "d"], readonly [number, ""], readonly [number, "k"], readonly [number, "M"], readonly [number, "G"], readonly [number, "T"], readonly [number, "P"], readonly [number, "E"]];
@@ -1,17 +0,0 @@
1
- export const metricPrefixes = [
2
- [10 ** -15, 'f'],
3
- [10 ** -12, 'p'],
4
- [10 ** -9, 'n'],
5
- [10 ** -6, 'μ'],
6
- [10 ** -3, 'm'],
7
- [10 ** -2, 'c'],
8
- [10 ** -1, 'd'],
9
- [10 ** 0, ''],
10
- [10 ** 3, 'k'],
11
- [10 ** 6, 'M'],
12
- [10 ** 9, 'G'],
13
- [10 ** 12, 'T'],
14
- [10 ** 15, 'P'],
15
- [10 ** 18, 'E']
16
- ];
17
- //# sourceMappingURL=metrix-prefixes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"metrix-prefixes.js","sourceRoot":"","sources":["../../../../../../src/utilities/unit-format/unit-scale/utilities/metrix-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,9 +0,0 @@
1
- import { UnitScale } from './unit-scale';
2
- /**
3
- * Voltage unit scale
4
- */
5
- declare class VoltUnitScale extends UnitScale {
6
- constructor();
7
- }
8
- export declare const voltUnitScale: VoltUnitScale;
9
- export {};
@@ -1,24 +0,0 @@
1
- import { ScaledUnit } from '../scaled-unit/scaled-unit';
2
- import { UnitScale } from './unit-scale';
3
- import { metricPrefixes } from './utilities/metrix-prefixes';
4
- import { ManuallyTranslatedScaledUnitFormat, UnitTranslation } from '../scaled-unit-format/manually-translated-scaled-unit-format';
5
- const unitTranslations = new Map([
6
- ['en', new UnitTranslation('volt', 'volts', 'V')],
7
- ['fr', new UnitTranslation('volt', 'volts', 'V')],
8
- ['de', new UnitTranslation('Volt', 'Volt', 'V')],
9
- ['ja', new UnitTranslation('ボルト', 'ボルト', 'V')],
10
- ['zh', new UnitTranslation('伏特', '伏特', 'V')]
11
- ]);
12
- /**
13
- * Voltage unit scale
14
- */
15
- class VoltUnitScale extends UnitScale {
16
- constructor() {
17
- super(metricPrefixes.map(([scaleFactor, scaledPrefixText]) => new ScaledUnit(scaleFactor, ManuallyTranslatedScaledUnitFormat.createFactory({
18
- unitTranslations,
19
- scaledPrefixText
20
- }))));
21
- }
22
- }
23
- export const voltUnitScale = new VoltUnitScale();
24
- //# sourceMappingURL=volt-unit-scale.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"volt-unit-scale.js","sourceRoot":"","sources":["../../../../../src/utilities/unit-format/unit-scale/volt-unit-scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EACH,kCAAkC,EAElC,eAAe,EAClB,MAAM,8DAA8D,CAAC;AAEtE,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/scaled-unit';\nimport { UnitScale } from './unit-scale';\nimport { metricPrefixes } from './utilities/metrix-prefixes';\nimport {\n ManuallyTranslatedScaledUnitFormat,\n type UnitTranslations,\n UnitTranslation\n} from '../scaled-unit-format/manually-translated-scaled-unit-format';\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 VoltUnitScale extends UnitScale {\n public constructor() {\n super(\n metricPrefixes.map(\n ([scaleFactor, scaledPrefixText]) => new ScaledUnit(\n scaleFactor,\n ManuallyTranslatedScaledUnitFormat.createFactory({\n unitTranslations,\n scaledPrefixText\n })\n )\n )\n );\n }\n}\n\nexport const voltUnitScale = new VoltUnitScale();\n"]}