Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dynatrace-sdk/units

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dynatrace-sdk/units - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

8

CHANGELOG.md

@@ -5,2 +5,10 @@ # Units

## 0.5.2
### Patch Changes
- Fixes the calculation of a month.
- Fixes a bug where negative numbers have been transformed to positive numbers.
- Improve documentation
## 0.5.1

@@ -7,0 +15,0 @@

26

cjs/index.js

@@ -189,3 +189,3 @@ /**

...time("week", 1 / (day * 7)),
...time("month", 1 / (day * 30.41666)),
...time("month", 1 / (day * 30.436875)),
...time("year", 1 / (day * 365.2425)),

@@ -203,3 +203,3 @@ ...unit("count")("count", 1, 10),

// packages/util/units/src/util-convert/convert.ts
function convert(number, from, to) {
function convert(input, from, to) {
if (from.length !== to.length)

@@ -220,8 +220,8 @@ throw Error("Not the same units");

const v2 = p2.value * p2.base ** -u2.index;
number *= (v2 / v1) ** u1.exponent;
input *= (v2 / v1) ** u1.exponent;
continue;
}
number *= p1.base ** ((u1.index - u2.index) * u1.exponent);
input *= p1.base ** ((u1.index - u2.index) * u1.exponent);
}
return number;
return input;
}

@@ -612,5 +612,5 @@

var MAX_DIGITS = 20;
function adjustMaximumFractionDigits(value, options) {
function adjustMaximumFractionDigits(input, options) {
const _precision = Number.isInteger(options?.precision) ? options?.precision : void 0;
const calcValue = Math.abs(value);
const calcValue = Math.abs(input);
if (calcValue === 0) {

@@ -621,3 +621,3 @@ return "0";

if (calcValue < minValue) {
return value < 0 ? `-${minValue}` : `< ${minValue}`;
return input < 0 ? `-${minValue}` : `< ${minValue}`;
}

@@ -643,3 +643,3 @@ let maximumFractionDigits = 0;

});
return formatter.format(value);
return formatter.format(input);
}

@@ -688,9 +688,9 @@

};
function abbreviateNumber(sourceValue, scale = ExponentialDecimalLevels, options) {
const isNegative = sourceValue < 0;
let value = Math.abs(sourceValue);
function abbreviateNumber(input, scale = ExponentialDecimalLevels, options) {
const isNegative = input < 0;
let value = Math.abs(input);
let postfix = "";
const level = scale.sort((a, b) => b.multiplier - a.multiplier).find((m) => m.multiplier <= value);
if (level !== void 0) {
value = sourceValue / level.multiplier;
value = value / level.multiplier;
postfix = level.postfix;

@@ -697,0 +697,0 @@ }

# Units
SDK package version **0.5.1**
SDK package version **0.5.2**

@@ -11,2 +11,199 @@ ```bash

## Interfaces
### AbbreviateOptions
<!-- default child "Interface" -->
#### Properties
<div class="padding-left--md padding-bottom--md">
<strong>locale</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a> | Array&lt;<a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a>&gt;
<div class="padding-left--md">
The locale according to which the number will abbreviate.
</div>
</div>
<div class="padding-left--md padding-bottom--md">
<strong>precision</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<div class="padding-left--md">
Number of decimal places.
</div>
</div>
### AdjustMaximumFractionDigitsOptions
<!-- default child "Interface" -->
#### Properties
<div class="padding-left--md padding-bottom--md">
<strong>locale</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a> | Array&lt;<a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a>&gt;
<div class="padding-left--md">
The locale according to which the number will be adjusted.
</div>
</div>
<div class="padding-left--md padding-bottom--md">
<strong>precision</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<div class="padding-left--md">
Number of decimal places.
</div>
</div>
### FormatDateOptions
<!-- default child "Interface" -->
Interface that extends Intl.DateTimeFormatOptions to pass an optional property to overwrite the default locale.
See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_options).
#### Properties
<div class="padding-left--md padding-bottom--md">
<strong>locale</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a> | Array&lt;<a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a>&gt;
<div class="padding-left--md">
The locale according to which the number will be formatted.
</div>
</div>
### FormatOptions
<!-- default child "Interface" -->
#### Properties
<div class="padding-left--md padding-bottom--md">
<strong>abbreviate</strong>: boolean
<div class="padding-left--md">
It will shorten the number to a shorter format.
(e.g. `input: 1500, output: 1.5k`).
</div>
</div>
<div class="padding-left--md padding-bottom--md">
<strong>cascade</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<div class="padding-left--md">
Will search for the biggest unit within its group and cascade it down the the specified dept.
The last number will get rounded to `maximumFractionDigits`.
(e.g. `format(1500, { input: units.length.meter, cascade: 3}), output: "1 km 5 hm 5 dam")`).
</div>
</div>
<div class="padding-left--md padding-bottom--md">
<strong>input</strong>: <a href="#fromunit">FromUnit</a>
<div class="padding-left--md">
If input unit is defined, it will convert it to the best fitting unit.
(e.g. `format(1500, { input: units.length.meter }), output: "1.5 km")`).
</div>
</div>
<div class="padding-left--md padding-bottom--md">
<strong>locale</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a> | Array&lt;<a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a>&gt;
<div class="padding-left--md">
The locale that will be used to format the number.
By default it will use the platform locale specified by the user.
</div>
</div>
<div class="padding-left--md padding-bottom--md">
<strong>maximumFractionDigits</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<div class="padding-left--md">
The amount of maximumFractionDigits points.
See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#maximumfractiondigits).
</div>
</div>
<div class="padding-left--md padding-bottom--md">
<strong>output</strong>: <a href="#tounit">ToUnit</a>
<div class="padding-left--md">
If not specified, the conversion is disabled
(e.g. `format(1500), output: 1.5K`).
</div>
</div>
<div class="padding-left--md padding-bottom--md">
<strong>suffix</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a>
<div class="padding-left--md">
A custom suffix that overwrites the unit symbol.
</div>
</div>
## Variables

@@ -60,3 +257,3 @@

All the units supported by this package. Use these for the format and convert api.
Grouped collection of all the supported units

@@ -75,9 +272,8 @@ </div>

<div class="padding-bottom--md">
<strong>abbreviateNumber(sourceValue,scale,options?): Object</strong>
<strong>abbreviateNumber(input,scale,options?): Object</strong>
<div class="padding-left--md">
Abbreviates a number larger than/equal than the base (kilo) value provided by the
levels property and shifts the fraction to the left.
10^x with quantifiers like K, M, B, T...
Abbreviates large numbers to a shorter format.
- `input: 1500, output: 1.5K`

@@ -88,7 +284,6 @@

<div class="padding-left--md padding-bottom--md">
<strong>sourceValue</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<strong>input</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<div class="padding-left--md">
Source number to be transformed.
Should be in the smallest unit (as a 10^1 base value).
Number that will get abbreviated.

@@ -105,6 +300,6 @@ </div>

Scale on which the numbers will be abbreviated on.
Defaults to ExponentialDecimalLevels:
- 1_000 = 1K
- 1_000_0000 = 1M
Scale for the abbreviation.
Default is decimal scale:
- `input: 1_000, output: 1K`
- `input: 1_000_0000, output: 1M`

@@ -147,8 +342,7 @@ </div>

<div class="padding-bottom--md">
<strong>adjustMaximumFractionDigits(value,options?): <a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a></strong>
<strong>adjustMaximumFractionDigits(input,options?): <a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a></strong>
<div class="padding-left--md">
Adjust precision in floating point numbers.
If no precision is passed this function automatically decides what fits best for the passed value.
Adjust number of decimap places.

@@ -159,3 +353,3 @@

<div class="padding-left--md padding-bottom--md">
<strong>value</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<strong>input</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<div class="padding-left--md">

@@ -172,3 +366,3 @@

<div class="padding-left--md padding-bottom--md">
<strong>options</strong>: Object
<strong>options</strong>: <a href="#adjustmaximumfractiondigitsoptions">AdjustMaximumFractionDigitsOptions</a>
<div class="padding-left--md">

@@ -184,28 +378,4 @@

<div class="padding-left--md padding-bottom--md">
<strong>options.locale</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a> | Array&lt;<a href="https://developer.mozilla.org/en-US/docs/Glossary/String">string</a>&gt;
<div class="padding-left--md">
Locale to format the number
</div>
</div>
<div class="padding-left--md padding-bottom--md">
<strong>options.precision</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<div class="padding-left--md">
Precision of the fraction amount.
</div>
</div>
<!-- no returns -->

@@ -227,8 +397,8 @@

<div class="padding-bottom--md">
<strong>convert(number,from,to): <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a></strong>
<strong>convert(input,from,to): <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a></strong>
<div class="padding-left--md">
Converts a given number to the specified unit. E.g. If you pass the number 1500 as meters and want to get the number as kilometers, you get 1.5.
See the description of the type for a better understanding of how unit conversion works in this package.
Converts a given number to the specified unit.
(e.g. `convert(1500, units.length.meter, unit.length.kilometer), output: 1.5`).

@@ -239,6 +409,6 @@

<div class="padding-left--md padding-bottom--md">
<strong>number</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<strong>input</strong>: <a href="https://developer.mozilla.org/en-US/docs/Glossary/Number">number</a>
<div class="padding-left--md">
the number to be converted into another unit.
The number that will get converted.

@@ -252,6 +422,6 @@ </div>

<div class="padding-left--md padding-bottom--md">
<strong>from</strong>: <a href="#t">T</a>
<strong>from</strong>: <a href="#fromunit">FromUnit</a>
<div class="padding-left--md">
the current unit of the specified number (e.g. units.length.meter).
The unit of the input (e.g. `units.length.meter`).

@@ -265,6 +435,6 @@ </div>

<div class="padding-left--md padding-bottom--md">
<strong>to</strong>: <a href="#check">Check</a>&lt;<a href="#t">T</a> | <a href="#u">U</a>&gt;
<strong>to</strong>: <a href="#convertabletarget">ConvertableTarget</a>&lt;<a href="#fromunit">FromUnit</a> | <a href="#tounit">ToUnit</a>&gt;
<div class="padding-left--md">
the unit to which the number is to be converted (e.g. units.length.kilometer).
The unit of the output (e.g. `units.length.kilometer`).

@@ -282,3 +452,3 @@ </div>

<div class="padding-left--md">
the result of the conversion (e.g. 1.5);
The result of the conversion (e.g. `1.5`).

@@ -307,3 +477,3 @@ </div>

Formats and optionally converts a number with or without its unit.
Converts and formats the provided number.

@@ -317,4 +487,4 @@

The number to be formatted
</div>

@@ -327,6 +497,6 @@

<div class="padding-left--md padding-bottom--md">
<strong>options</strong>: <a href="#options">Options</a>&lt;<a href="#t">T</a> | <a href="#tounit">ToUnit</a>&lt;<a href="#t">T</a> | <a href="#u">U</a>&gt; | <a href="#tocascade">ToCascade</a>&lt;<a href="#t">T</a>&gt;&gt;
<strong>options</strong>: <a href="#formatoptions">FormatOptions</a>&lt;<a href="#units">Units</a> | <a href="#tounit">ToUnit</a>&lt;<a href="#units">Units</a> | <a href="#fromunit">FromUnit</a>&gt;&gt;
<div class="padding-left--md">
options to define how the number should be formatted
Formatting options.

@@ -344,3 +514,3 @@ </div>

<div class="padding-left--md">
a string containing the formatted number and its unit.
A string containing the formatted number.

@@ -466,3 +636,3 @@ </div>

Provides the names of all units that a unit can be converted to.
Provides all the unit names to which the provided unit can be converted to.

@@ -502,7 +672,7 @@

<div class="padding-bottom--md">
<strong>variantUnits(unit): Array&lt;<a href="#cunit">CUnit</a>&gt;</strong>
<strong>variantUnits(unit): Array&lt;<a href="#fromunit">FromUnit</a>&gt;</strong>
<div class="padding-left--md">
Provides all units a unit can be converted to.
Provides all the units to which the provided unit can be converted to.

@@ -537,1 +707,26 @@

### FromUnit
<div class="padding-bottom--md">
All supported units. For more details see a <a href="#conversionexample">conversion example</a>.
</div>
### ToUnit
<div class="padding-bottom--md">
All units to which the `FromUnit` can be converted. For more details see a <a href="#conversionexample">conversion example</a>.
</div>
### ConvertableTarget
TypeScript helper that returns all the possible convertable targets, where the first generic is <a href="#fromunit">FromUnit</a>, and second is <a href="#tounit">ToUnit</a>.
### Conversion example
```javascript
import * as units from '@dynatrace-sdk/units';
// units.{unitGroup}.{unit}
convert(1000, /* FromUnit */ units.length.meter, /* ToUnit */units.length.kilometer)
```

@@ -158,3 +158,3 @@ /**

...time("week", 1 / (day * 7)),
...time("month", 1 / (day * 30.41666)),
...time("month", 1 / (day * 30.436875)),
...time("year", 1 / (day * 365.2425)),

@@ -172,3 +172,3 @@ ...unit("count")("count", 1, 10),

// packages/util/units/src/util-convert/convert.ts
function convert(number, from, to) {
function convert(input, from, to) {
if (from.length !== to.length)

@@ -189,8 +189,8 @@ throw Error("Not the same units");

const v2 = p2.value * p2.base ** -u2.index;
number *= (v2 / v1) ** u1.exponent;
input *= (v2 / v1) ** u1.exponent;
continue;
}
number *= p1.base ** ((u1.index - u2.index) * u1.exponent);
input *= p1.base ** ((u1.index - u2.index) * u1.exponent);
}
return number;
return input;
}

@@ -581,5 +581,5 @@

var MAX_DIGITS = 20;
function adjustMaximumFractionDigits(value, options) {
function adjustMaximumFractionDigits(input, options) {
const _precision = Number.isInteger(options?.precision) ? options?.precision : void 0;
const calcValue = Math.abs(value);
const calcValue = Math.abs(input);
if (calcValue === 0) {

@@ -590,3 +590,3 @@ return "0";

if (calcValue < minValue) {
return value < 0 ? `-${minValue}` : `< ${minValue}`;
return input < 0 ? `-${minValue}` : `< ${minValue}`;
}

@@ -612,3 +612,3 @@ let maximumFractionDigits = 0;

});
return formatter.format(value);
return formatter.format(input);
}

@@ -657,9 +657,9 @@

};
function abbreviateNumber(sourceValue, scale = ExponentialDecimalLevels, options) {
const isNegative = sourceValue < 0;
let value = Math.abs(sourceValue);
function abbreviateNumber(input, scale = ExponentialDecimalLevels, options) {
const isNegative = input < 0;
let value = Math.abs(input);
let postfix = "";
const level = scale.sort((a, b) => b.multiplier - a.multiplier).find((m) => m.multiplier <= value);
if (level !== void 0) {
value = sourceValue / level.multiplier;
value = value / level.multiplier;
postfix = level.postfix;

@@ -666,0 +666,0 @@ }

{
"name": "@dynatrace-sdk/units",
"version": "0.5.1",
"version": "0.5.2",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "main": "./cjs/index.js",

@@ -16,7 +16,7 @@ /**

*/
export { format, formatDate, formatUnit } from './util-format/format';
export { format, formatDate, formatUnit, FormatDateOptions, FormatOptions, } from './util-format/format';
export { convert } from './util-convert/convert';
export { variantNames, variantUnits } from './util-convert/variants';
export { units } from './util-units/index';
export { ExponentialDecimalLevels, ExponentialOctalBitLevels, ExponentialOctalByteLevels, abbreviateNumber, } from './util-format/abbreviate-number';
export { adjustMaximumFractionDigits } from './util-format/adjust-maximum-fraction-digits';
export { ExponentialDecimalLevels, ExponentialOctalBitLevels, ExponentialOctalByteLevels, AbbreviateOptions, abbreviateNumber, } from './util-format/abbreviate-number';
export { adjustMaximumFractionDigits, AdjustMaximumFractionDigitsOptions, } from './util-format/adjust-maximum-fraction-digits';

@@ -1,10 +0,10 @@

import { CUnit, Check } from './types';
import { CUnit, ConvertableTarget } from './types';
/**
* Converts a given number to the specified unit. E.g. If you pass the number 1500 as meters and want to get the number as kilometers, you get 1.5.
* See the description of the {@link CUnit} type for a better understanding of how unit conversion works in this package.
* @param number the number to be converted into another unit.
* @param from the current unit of the specified number (e.g. units.length.meter).
* @param to the unit to which the number is to be converted (e.g. units.length.kilometer).
* @returns the result of the conversion (e.g. 1.5);
* Converts a given number to the specified unit.
* (e.g. `convert(1500, units.length.meter, unit.length.kilometer), output: 1.5`).
* @param input The number that will get converted.
* @param from The unit of the input (e.g. `units.length.meter`).
* @param to The unit of the output (e.g. `units.length.kilometer`).
* @returns The result of the conversion (e.g. `1.5`).
*/
export declare function convert<T extends CUnit, U extends CUnit>(number: number, from: T, to: Check<T, U>): number;
export declare function convert<FromUnit extends CUnit, ToUnit extends CUnit>(input: number, from: FromUnit, to: ConvertableTarget<FromUnit, ToUnit>): number;

@@ -79,3 +79,3 @@ import { properties } from './properties';

export declare type isConvertable<T extends Unit | string> = (T extends CUnit ? true : false) extends true ? true : false;
export declare type ToUnit<T extends Unit | string, U extends CUnit> = T extends CUnit ? Check<T, U> : never;
export declare type ToUnit<T extends Unit | string, U extends CUnit> = T extends CUnit ? ConvertableTarget<T, U> : never;
export declare type ToCascade<T extends Unit | string> = isConvertable<T> extends true ? number : never;

@@ -91,3 +91,3 @@ export declare type ValueUnit = {

export declare type CompareIndex<T extends CUnit, U extends CUnit, I extends number> = T[I]['exponent'] extends U[I]['exponent'] ? Quantities[T[I]['group']] extends Quantities[U[I]['group']] ? true : false : false;
export declare type Check<T extends CUnit, U extends CUnit> = CompareIndex<T, U, 0> extends true ? CompareIndex<T, U, 1> extends true ? CompareIndex<T, U, 2> extends true ? CompareIndex<T, U, 3> extends true ? U : never : never : never : never;
export declare type ConvertableTarget<T extends CUnit, U extends CUnit> = CompareIndex<T, U, 0> extends true ? CompareIndex<T, U, 1> extends true ? CompareIndex<T, U, 2> extends true ? CompareIndex<T, U, 3> extends true ? U : never : never : never : never;
export declare type Invert<T extends number | string> = ({

@@ -94,0 +94,0 @@ '-15': 15;

@@ -1,14 +0,14 @@

import { CUnit } from './types';
export declare function variants(unit: CUnit): string[];
import { CUnit as FromUnit } from './types';
export declare function variants(unit: FromUnit): string[];
/**
* Provides the names of all units that a unit can be converted to.
* Provides all the unit names to which the provided unit can be converted to.
* @param unit
* @returns
*/
export declare function variantNames(unit: CUnit): string[];
export declare function variantNames(unit: FromUnit): string[];
/**
* Provides all units a unit can be converted to.
* Provides all the units to which the provided unit can be converted to.
* @param unit
* @returns
*/
export declare function variantUnits(unit: CUnit): CUnit[];
export declare function variantUnits(unit: FromUnit): FromUnit[];

@@ -31,8 +31,8 @@ /** Units of exponential numbers, i.e. kilo, million, ect. */

}>;
export declare type AbbreviateOptions = {
/** The amount of fraction digits to be used, if provided. */
export interface AbbreviateOptions {
/** Number of decimal places. */
precision?: number;
/** The amount of fraction digits to be used, if provided. */
/** The locale according to which the number will abbreviate. */
locale?: string | string[];
};
}
export declare const defaultAbbreviateOptions: {

@@ -46,17 +46,15 @@ scale: {

/**
* Abbreviates a number larger than/equal than the base (kilo) value provided by the
* levels property and shifts the fraction to the left.
* 10^x with quantifiers like K, M, B, T...
* Abbreviates large numbers to a shorter format.
* - `input: 1500, output: 1.5K`
*/
export declare function abbreviateNumber<T>(
/**
* Source number to be transformed.
* Should be in the smallest unit (as a 10^1 base value).
* Number that will get abbreviated.
*/
sourceValue: number,
input: number,
/**
* Scale on which the numbers will be abbreviated on.
* Defaults to ExponentialDecimalLevels:
* - 1_000 = 1K
* - 1_000_0000 = 1M
* Scale for the abbreviation.
* Default is decimal scale:
* - `input: 1_000, output: 1K`
* - `input: 1_000_0000, output: 1M`
*/

@@ -63,0 +61,0 @@ scale?: Array<{

@@ -16,13 +16,13 @@ /**

*/
export interface AdjustMaximumFractionDigitsOptions {
/** Number of decimal places. */
precision?: number;
/** The locale according to which the number will be adjusted. */
locale?: string | string[];
}
/**
* Adjust precision in floating point numbers.
* If no precision is passed this function automatically decides what fits best for the passed value.
* Adjust number of decimap places.
*/
export declare function adjustMaximumFractionDigits(
/** Input number that should be abbreviated. */
value: number, options?: {
/** Precision of the fraction amount. */
precision?: number;
/** Locale to format the number */
locale?: string | string[];
}): string;
input: number, options?: AdjustMaximumFractionDigitsOptions): string;

@@ -1,2 +0,2 @@

import type { Unit, FUnit, CUnit, ToUnit, ToCascade, CPack, Convertable } from '../util-convert/types';
import type { Unit, FUnit, CUnit, ToUnit, CPack, Convertable } from '../util-convert/types';
export declare function formatPack({ group, index, exponent }: CPack<Convertable, number>): string;

@@ -10,40 +10,50 @@ export declare function formatPacks(packs: FUnit): string;

export declare function formatUnit(unit: FUnit): string;
declare type Options<T extends Unit, U extends CUnit, V extends number> = {
/** The cascading depth. Setting this enables cascading.
* Will search for the biggest unit within a unit group, converting to which will result in a number >= 1. Tries the next _depth_ numbers or until no units are left. (e.g. format(1500, { input: units.length.meter, cascade: 3}) => "1 km 5 hm 5 dam")
* The last number will get rounded to `maximumFractionDigits`, the other ones truncated.
* Ignored if `output` is set.
export interface FormatOptions<FromUnit extends Unit, ToUnit extends CUnit> {
/**
* Will search for the biggest unit within its group and cascade it down the the specified dept.
* The last number will get rounded to `maximumFractionDigits`.
* (e.g. `format(1500, { input: units.length.meter, cascade: 3}), output: "1 km 5 hm 5 dam")`).
*/
cascade?: V;
/** The input unit. `unspecified.none` by default. If you only define the input, it will automatically convert the unit to another readable unit and format the result of the conversion (e.g. format(1500, { input: units.length.meter }) => "1.5 km").*/
input?: T;
/** The output unit.
* * If both input and output are not set, it will format just the number without adding any suffix at the end (e.g. format(1500) => 1.5K).
* * If you define both the input and the output, it will always convert to a fixed unit and format it in a readable way (e.g. format(1500, { input: units.length.meter, output: units.length.centimeter }) => "150K cm").
cascade?: number;
/**
* If input unit is defined, it will convert it to the best fitting unit.
* (e.g. `format(1500, { input: units.length.meter }), output: "1.5 km")`).
*/
output?: U;
/** A custom suffix that overwrites a potential unit symbol. Will get padded if not an empty string. */
input?: FromUnit;
/**
* If not specified, the conversion is disabled
* (e.g. `format(1500), output: 1.5K`).
*/
output?: ToUnit;
/** A custom suffix that overwrites the unit symbol. */
suffix?: string;
/** The amount of maximumFractionDigits points to round to. See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#maximumfractiondigits). */
/**
* The amount of maximumFractionDigits points.
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#maximumfractiondigits).
*/
maximumFractionDigits?: number;
/** The locale which should be used to format the number. By default it uses the locale of the globalThis.dtSdk object. */
/**
* The locale that will be used to format the number.
* By default it will use the platform locale specified by the user.
*/
locale?: string | string[];
/** Automatically abbreviate the number to a readable quantity. By default abbreviate is activated. If you deactivate it a result would look like this 1500 instead of this 1.5K */
/**
* It will shorten the number to a shorter format.
* (e.g. `input: 1500, output: 1.5k`).
* */
abbreviate?: boolean;
};
}
/**
* Formats and optionally converts a number with or without its unit.
* @param number The number to be formatted
* @param options options to define how the number should be formatted
* @returns a string containing the formatted number and its unit.
* Converts and formats the provided number.
* @param input The number that will get formatted.
* @param options Formatting options.
* @returns A string containing the formatted number.
*/
export declare function format<T extends Unit, U extends CUnit>(number: number, options?: Options<T, ToUnit<T, U>, ToCascade<T>>): string;
export declare function format<Units extends Unit, FromUnit extends CUnit>(number: number, options?: FormatOptions<Units, ToUnit<Units, FromUnit>>): string;
/**
* Interface that extends Intl.DateTimeFormatOptions to pass an optional property to overwrite the default locale.
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_options)
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_options).
*/
interface FormatDateOptions extends Intl.DateTimeFormatOptions {
/**
* A BCP 47 language tag or an array of language tags to overwrite the default locale set by the Dynatrace platform.
*/
export interface FormatDateOptions extends Intl.DateTimeFormatOptions {
/** The locale according to which the number will be formatted. */
locale?: string | string[];

@@ -59,2 +69,1 @@ }

export declare function getRegionalLocale(): string;
export {};

@@ -17,3 +17,3 @@ /**

/**
* All the units supported by this package. Use these for the format and convert api.
* Grouped collection of all the supported units
*/

@@ -20,0 +20,0 @@ export declare const units: {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc