@emartech/ui-framework-utils

Utilities for UI Framework Services

Usage no npm install needed!

<script type="module">
  import emartechUiFrameworkUtils from 'https://cdn.skypack.dev/@emartech/ui-framework-utils';
</script>

README

UI Framework Utils

HTMLCustomElement

Base class for Emarsys UI webcomponents.

formatNumber

Utility function for formatting numbers.

Syntax:

formatNumber(options)(value);

formatNumber(options, value);

If multiple values are formatted with the same options, it is more performant to first create a formatter with the options and then reuse it for formatting the values.

Parameters

  • options
    • options.style: Can be decimal, percent or currency. Default: decimal
    • options.precision: When a natural number is given, it specifies a fix precision. If -1 is given, all valuable decimals are kept. Default: 0
    • options.trimFractionZeros: Trim fraction zeros after applying precision. Default: false
    • options.currency: Specifies the currency to be used when options.style is currency. Known currency codes are converted to symbols. Default: EUR.
    • options.humanize: If set, the number will be converted to the given unit. Can be auto, k, m, b ot t. When auto is given, the most meaningful unit will be used.
    • options.language: Specifies the language of units when humanize is set. Can be en, de, es, fr, ru, tr or cn. Default: en.
  • value: The number which will be formatted.

formatDuration

Utility function for formatting durations.

Syntax:

formatDuration(value, options);

Parameters

  • value: The number which will be formatted, interpreted as number of seconds, can be either Number or String.
  • options: Object of options to override default behavior, optional. Unset options will use their default value.
    • pad: Specifies whether to pad values to fix length. Can be true or false. Default: false.
    • showZeroParts: Specifies whether to show zero parts if there are non-zero parts as well. Default: false.
    • precision: Specifies detail to show. Either smallest unit to show, e.g. minutes or auto. When auto is given, the highest non-zero unit and the next will be shown. Default: seconds.
    • language: Specifies language to localize unit abbreviations. Can be en, de, es, fr, ru, tr or cn. Default: en.