Socket
Socket
Sign inDemoInstall

@opuscapita/format-utils

Package Overview
Dependencies
1
Maintainers
27
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @opuscapita/format-utils

OpusCapita JS formatting utilities


Version published
Maintainers
27
Install size
1.73 MB
Created

Changelog

Source

2.2.6

  • added escapeSpecialCharacters function. Escape special characters from the string.

Readme

Source

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, string]decimals :: 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, number]FX 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>
  );
}

FAQs

Last updated on 17 Apr 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc