@dynatrace-sdk/units
Advanced tools
Comparing version 0.18.0 to 0.18.2
@@ -5,2 +5,16 @@ # Units | ||
## 0.18.2 | ||
### Patch Changes | ||
- Add formatCurrency function. APPDEV-10478 | ||
- Add support for years in the `offsetExpression` when using the `__STRATO__DO_NOT_USE__ENABLE_ROUND_DOWN_EXPRESSION` feature flag. | ||
- Add support for `@y` `@q` `@w` `@h` `@m` `@s` in `roundDownExpression`s. | ||
## 0.18.1 | ||
### Patch Changes | ||
- Fix near zero numbers being formatted as empty string | ||
## 0.18.0 | ||
@@ -7,0 +21,0 @@ |
236
docs/DOCS.md
@@ -18,3 +18,3 @@ --- | ||
<div class="col" style={{textAlign: 'right'}}> | ||
<a href="https://www.npmjs.com/package/@dynatrace-sdk/units/v/0.18.0" target="_blank" rel="noopener noreferrer">v0.18.0</a> | ||
<a href="https://www.npmjs.com/package/@dynatrace-sdk/units/v/0.18.2" target="_blank" rel="noopener noreferrer">v0.18.2</a> | ||
</div> | ||
@@ -273,2 +273,161 @@ </div> | ||
### _getDateFromExpression | ||
<div class="padding-bottom--md"> | ||
<strong>_getDateFromExpression(__namedParameters,relativeDate): Date | null</strong> | ||
<div class="padding-left--md"> | ||
Converts expression details into a date object | ||
</div> | ||
#### Parameters | ||
| Name | Type | | ||
| --- | --- | | ||
|__namedParameters<sup>*required</sup>|ExpressionDetails| | ||
|relativeDate<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)| | ||
</div> | ||
### _getTimeframeExpression | ||
<div class="padding-bottom--md"> | ||
<strong>_getTimeframeExpression(): RegExp</strong> | ||
<div class="padding-left--md"> | ||
Returns the TimeframeExpression regex. | ||
</div> | ||
</div> | ||
### _parseDatetimeInput | ||
<div class="padding-bottom--md"> | ||
<strong>_parseDatetimeInput(candidate): Date | null</strong> | ||
<div class="padding-left--md"> | ||
Generates a date object out of the input string if provided in one of the accepted formats | ||
</div> | ||
#### Parameters | ||
| Name | Type | | ||
| --- | --- | | ||
|candidate<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| | ||
</div> | ||
### _parseISOWithExtendedPrecision | ||
<div class="padding-bottom--md"> | ||
<strong>_parseISOWithExtendedPrecision(candidate): TimeValue | null</strong> | ||
<div class="padding-left--md"> | ||
Checks if the provided value is a valid ISO string with support for extended (up tp nano) precision. | ||
We cannot use dateFns parseISO because it returns native Date object, which do not support extended precision. | ||
</div> | ||
#### Parameters | ||
| Name | Type | | ||
| --- | --- | | ||
|candidate<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| | ||
</div> | ||
### _parseTimeExpression | ||
<div class="padding-bottom--md"> | ||
<strong>_parseTimeExpression(candidate): ExpressionDetails | undefined</strong> | ||
<div class="padding-left--md"> | ||
Parses the input for expression details. | ||
</div> | ||
#### Parameters | ||
| Name | Type | | ||
| --- | --- | | ||
|candidate<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| | ||
</div> | ||
### abbreviateNumber | ||
@@ -438,2 +597,43 @@ | ||
### formatCurrency | ||
<div class="padding-bottom--md"> | ||
<strong>formatCurrency(number,currency,options?): [string](https://developer.mozilla.org/en-US/docs/Glossary/String)</strong> | ||
<div class="padding-left--md"> | ||
Formats a number with the currency indicated | ||
</div> | ||
#### Parameters | ||
| Name | Type | Description | | ||
| --- | --- | --- | | ||
|number<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)|The value to be formatted | | ||
|currency<sup>*required</sup>|undefined | [string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The ISO 4217 currency codes, such as 'USD' or 'EUR', to which the number will be formatted | | ||
|options|FormatCurrencyOptions|Options to adapt the formatting (locale and properties accepted by Intl.NumberFormat) | | ||
#### Returns | ||
| Description | | ||
|---| | ||
|the formatted number to the specified currency| | ||
</div> | ||
### formatDate | ||
@@ -479,2 +679,36 @@ | ||
### formatLong | ||
<div class="padding-bottom--md"> | ||
<strong>formatLong(value,options?): [string](https://developer.mozilla.org/en-US/docs/Glossary/String)</strong> | ||
<div class="padding-left--md"> | ||
</div> | ||
#### Parameters | ||
| Name | Type | | ||
| --- | --- | | ||
|value<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String) | [number](https://developer.mozilla.org/en-US/docs/Glossary/Number) | bigint| | ||
|options|FormatLong| | ||
</div> | ||
### formatUnit | ||
@@ -481,0 +715,0 @@ |
{ | ||
"name": "@dynatrace-sdk/units", | ||
"version": "0.18.0", | ||
"version": "0.18.2", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "description": "Package for converting and formatting units and numerical values.", |
@@ -1,5 +0,5 @@ | ||
export { getFormatting, format, formatDate, formatUnit, FormatDateOptions, FormatOptions, } from './util-format/format'; | ||
export { getFormatting, format, formatDate, formatUnit, FormatDateOptions, FormatOptions, formatCurrency, formatLong, } from './util-format/format'; | ||
export { convert } from './util-convert/convert'; | ||
export { variantNames, variantUnits } from './util-convert/variants'; | ||
export { units } from './util-units/index'; | ||
export { units } from './util-units/units'; | ||
export { ExponentialDecimalLevels, ExponentialOctalBitLevels, ExponentialOctalByteLevels, abbreviateNumber, } from './util-format/abbreviate-number'; | ||
@@ -12,4 +12,4 @@ export { adjustFractionDigits, AdjustFractionDigitsOptions, AdjustFractionDigitsOptions as AbbreviateOptions, } from './util-format/adjust-maximum-fraction-digits'; | ||
export { parseTime } from './util-format/time-Parser'; | ||
export { parseTime as parseTimeAsTimeValue } from './util-format/time'; | ||
export { _getDateFromExpression, _getTimeframeExpression, _parseDatetimeInput, _parseISOWithExtendedPrecision, parseTime as parseTimeAsTimeValue, _parseTimeExpression, } from './util-format/time'; | ||
export { convertTemperature as _convertTemperature } from './util-convert/temperature'; | ||
export { cascade as _cascade } from './util-convert/cascade'; |
@@ -14,2 +14,6 @@ import { AdjustFractionDigitsOptions } from './adjust-maximum-fraction-digits'; | ||
}; | ||
export declare const ExponentialCurrencyLevels: { | ||
base: number; | ||
levels: string[]; | ||
}; | ||
/** | ||
@@ -31,2 +35,6 @@ * Abbreviation levels for bit binary prefixes from kilobit to quebibit, | ||
}; | ||
export declare function calculatePostfix(value: number, { base, levels }: Scale): { | ||
value: number; | ||
postfix: string; | ||
}; | ||
/** | ||
@@ -33,0 +41,0 @@ * Abbreviate large numbers to a shorter format. Example: |
@@ -77,2 +77,3 @@ import type { Unit, FormattableUnit, ConvertibleUnit, OutputUnit, FormattablePack, UndefinedCoalescing } from '../util-convert/types'; | ||
} | ||
type FormatLong = Pick<FormatOptions<Unit, ConvertibleUnit>, 'locale' | 'maximumFractionDigits' | 'maximumSignificantDigits' | 'minimumFractionDigits' | 'minimumSignificantDigits' | 'useGrouping'>; | ||
/** | ||
@@ -100,2 +101,6 @@ * Converts and formats the provided number. | ||
} | ||
export interface FormatCurrencyOptions extends Omit<Intl.NumberFormatOptions, 'currency' | 'style'> { | ||
/** The locale according to which the number will be formatted. */ | ||
locale?: string | string[]; | ||
} | ||
/** | ||
@@ -108,2 +113,11 @@ * Formats a date according to locale. | ||
export declare function formatDate(input: number | Date, options?: FormatDateOptions): string; | ||
/** | ||
* Formats a number with the currency indicated | ||
* @param number The value to be formatted | ||
* @param currency The ISO 4217 currency codes, such as 'USD' or 'EUR', to which the number will be formatted | ||
* @param options Options to adapt the formatting (locale and properties accepted by Intl.NumberFormat) | ||
* @returns the formatted number to the specified currency | ||
*/ | ||
export declare function formatCurrency(number: number, currency: Intl.NumberFormatOptions['currency'], options?: FormatCurrencyOptions): string; | ||
export declare function formatLong(value: number | bigint | string, options?: FormatLong): string; | ||
export {}; |
@@ -12,3 +12,34 @@ /** | ||
} | ||
type OffsetUnit = 'y' | 'q' | 'M' | 'w' | 'd' | 'h' | 'm' | 's' | 'ms'; | ||
type RoundDownUnit = 'y' | 'q' | 'M' | 'w' | 'w0' | 'w1' | 'w2' | 'w3' | 'w4' | 'w5' | 'w6' | 'd' | 'h' | 'm' | 's'; | ||
type ExpressionDetails = { | ||
offsetAmount: number; | ||
offsetUnit?: OffsetUnit; | ||
roundDownUnit?: RoundDownUnit; | ||
}; | ||
/** Returns the TimeframeExpression regex. | ||
* @internal | ||
*/ | ||
export declare function _getTimeframeExpression(): RegExp; | ||
/** | ||
* Parses the input for expression details. | ||
* @internal | ||
*/ | ||
export declare function _parseTimeExpression(candidate: string): ExpressionDetails | undefined; | ||
/** | ||
* Converts expression details into a date object | ||
* @internal | ||
*/ | ||
export declare function _getDateFromExpression({ offsetAmount, offsetUnit, roundDownUnit }: ExpressionDetails, relativeDate: number): Date | null; | ||
/** Generates a date object out of the input string if provided in one of the accepted formats | ||
* @internal | ||
*/ | ||
export declare function _parseDatetimeInput(candidate: string): Date | null; | ||
/** | ||
* Checks if the provided value is a valid ISO string with support for extended (up tp nano) precision. | ||
* We cannot use dateFns parseISO because it returns native Date object, which do not support extended precision. | ||
* @internal | ||
*/ | ||
export declare function _parseISOWithExtendedPrecision(candidate: string): TimeValue | null; | ||
/** | ||
* You can use the `parseTime` utility function to convert a string into | ||
@@ -21,1 +52,2 @@ * `TimeValue`, giving you a normalized version of the input string (trimmed | ||
export declare function parseTime(candidate?: string | null, relativeDate?: number): TimeValue | null; | ||
export {}; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @deprecated please use formatCurrency function to handle formatting of currencies | ||
*/ | ||
export declare const units: { | ||
@@ -2,0 +5,0 @@ readonly cny: [Readonly<{ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
627489
61
20839