npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@opuscapita/format-utils

v2.2.6

Published

OpusCapita JS formatting utilities

Downloads

14

Readme

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>
  );
}