Git Product home page Git Product logo

format-utils's Introduction

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 name Description Input Output
getCurrencyDecimals Get a number of decimal digits for a currency currency code :: string decimals :: number
getFXRateDecimals Get a number of decimal digits for a FX rate FX rate :: [number, string] decimals :: number
getLocalDateTime Get local date and time from ISO 8601 timestamp UTC timestamp :: string timestamp :: date
formatCurrencyAmount Format amount according to its currency amount :: [number, string], options :: object (optional) amount :: string
formatDate Format date to a chosen format date :: string, date format :: string date :: string
formatDateToISO Format localized date string to ISO timestamp date :: string, date format :: string (optional), sign of strict date format :: boolean (optional), default value :: string (optional), default date format :: string (optional) ISO date :: string
formatFloatToFixedDecimals Format an input to a float with fixed number of decimals value to format :: [number, string], decimals :: number formatted value :: string
formatFXRate Format FX rate FX rate :: [string, number] FX rate :: string
formatNumber Format number with separators and decimals value :: [number, float, string], options :: object (optional) amount :: string
escapeSpecialCharacters Format string containing special characters by escaping them string string

formatCurrencyAmount option object

Option key Value Default Description
currency string (optional) Currency code to get number of decimals from
decimals string (optional) 2 Number of decimals, overrides currency decimals
thousandSeparator string (optional) Thousand separator
decimalSeparator string (optional) '.' Decimal separator

formatNumber option object

Option key Value Default Description
decimals string (optional) 0 Number of decimals
thousandSeparator string (optional) Thousand separator
decimalSeparator string (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>
  );
}

format-utils's People

Contributors

elefantino avatar naniantero avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

format-utils's Issues

formatDateToISO returns invalid value on IE

Input:
FormatUtils.formatDateToISO(
'1.4.2018',
'D.M.YYYY',
true,
'1.4.2018',
'DD/MM/YYYY',
)

Output:
Chrome & Firefox: '2018-04-01T00:00:00.000Z'
IE: '1.4.2018'

Expected outcome:
'2018-04-01T00:00:00.000Z'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.