2.2.6 • Published 4 years ago

@opuscapita/format-utils v2.2.6

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

format-utils

Description

Formatting functions in JS

Installation

npm install --save @opuscapita/format-utils

Demo

View the DEMO

Builds

UMD

The default build with compiled styles in the .js file. Also minified version available in the lib/umd directory.

CommonJS/ES Module

You need to configure your module loader to use cjs or es fields of the package.json to use these module types. Also you need to configure sass loader, since all the styles are in sass format.

API

Function nameDescriptionInputOutput
getCurrencyDecimalsGet a number of decimal digits for a currencycurrency code :: stringdecimals :: number
getFXRateDecimalsGet a number of decimal digits for a FX rateFX rate :: number, stringdecimals :: number
getLocalDateTimeGet local date and time from ISO 8601 timestampUTC timestamp :: stringtimestamp :: date
formatCurrencyAmountFormat amount according to its currencyamount :: number, string, options :: object (optional)amount :: string
formatDateFormat date to a chosen formatdate :: string, date format :: stringdate :: string
formatDateToISOFormat localized date string to ISO timestampdate :: string, date format :: string (optional), sign of strict date format :: boolean (optional), default value :: string (optional), default date format :: string (optional)ISO date :: string
formatFloatToFixedDecimalsFormat an input to a float with fixed number of decimalsvalue to format :: number, string, decimals :: numberformatted value :: string
formatFXRateFormat FX rateFX rate :: string, numberFX rate :: string
formatNumberFormat number with separators and decimalsvalue :: number, float, string, options :: object (optional)amount :: string
escapeSpecialCharactersFormat string containing special characters by escaping themstringstring

formatCurrencyAmount option object

Option keyValueDefaultDescription
currencystring (optional)Currency code to get number of decimals from
decimalsstring (optional)2Number of decimals, overrides currency decimals
thousandSeparatorstring (optional)Thousand separator
decimalSeparatorstring (optional)'.'Decimal separator

formatNumber option object

Option keyValueDefaultDescription
decimalsstring (optional)0Number of decimals
thousandSeparatorstring (optional)Thousand separator
decimalSeparatorstring (optional)'.'Decimal separator

Code example

Import only the parts you need

import React from 'react';
import { getCurrencyDecimals } from '@opuscapita/format-utils';

export default function FormatUtilsExamples() {
  return (
    <p>
      getCurrencyDecimals('EUR') = {getCurrencyDecimals('EUR')}
    </p>
  );
}

Import whole utils library

import React from 'react';
import FormatUtils from '@opuscapita/format-utils';

export default function FormatUtilsExamples() {
  return (
    <p>
      FormatUtils.formatCurrencyAmount(432432.23423, { currency: 'EUR' }) = {FormatUtils.formatCurrencyAmount(432432.23423, { currency: 'EUR' })}
    </p>
    <p>
      FormatUtils.formatFloatToFixedDecimals(1234.12345, 2) = {FormatUtils.formatFloatToFixedDecimals(1234.12345, 2)}
    </p>
  );
}
2.2.6

4 years ago

2.2.5

4 years ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

6 years ago

1.0.0

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago