0.8.0 • Published 4 years ago

price-like-humans v0.8.0

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

Price like Humans

Build Status Codacy Badge Code Grade Codacy Badge Coverage NPM version Dist size Downloads License Issues PRs Welcome

JS kit for formatting price or numbers to human likes format. Also kit will be useful for crypto-currency with 7+ numbers after a delimiter

⚠️ Breaking changes from 0.6.0 to 0.7.0 see the changelog

Spoiler: changed arguments in formattedPrice

Table of contents

Install

NPM users:

npm i --save-dev price-like-humans

Yarn users:

yarn add price-like-humans -D

Methods

MethodsReturnsDescription
formattedPrice(value, options)stringFormatting incoming numbers to humans like price with user locale delimiter
exponentFormatter(value)stringFormatting exponential numbers to human likes numbers. Exponent free

formattedPrice

ArgumentRequiredArgument typeDescription
value*requirednumber, stringIncoming numbers which will be formatted (exponential friendly)
optionsoptionalobjectSettings list, see formattedPrice options

exponentformatter

ArgumentRequiredArgument typeDescription
value*requirednumber, stringIncoming exponential numbers which will be formatted

formattedPrice options

ArgumentArgument typeDescription
delimiterstringDelimiter symbol. Number which split decimal. Can be replaced
separatorstringSymbol which separates grouped number. Can be replaced
langstringYou can set locale option. Using user locale by default

⚠️ Warning: When works in Nodejs environment, intl.NumberFormat contains 'en-US' locale only, so use the separator with delimiter when the code needs to run on a server-side.

Usage

NodeJS

const priceLikeHumans = require('price-like-humans');

ES6

import priceLikeHumans from 'price-like-humans';
// or methods only
import { formattedPrice, exponentFormatter } from 'price-like-humans';

Examples

formattedPrice examples

Without separator arguments (putted your local separator)

formattedPrice(12345.6789);

//> "12,345.678,9" // EU Locale
//> "12 345.678 9" // RU Locale

Using with options

formattedPrice(12345.6789, { delimiter: ',' });

//> "12.345,678.9" // EN Locale
//> "12 345,678 9" // RU Locale
formattedPrice(12345.6789, { separator: '.' });

//> "12.345,678.9" // EN Locale
//> "12.345,678.9" // RU Locale
formattedPrice(12345.6789, { delimiter: '.', separator: ',' });

//> "12,345.678,9"
formattedPrice(12345.6789, { lang: 'ru' });

//> "12 345,678 9"
formattedPrice(12345.6789, { lang: 'en' });

//> "12,345.678,9"
formattedPrice(1e-7, { lang: 'en' });

//> "0.000,000,1"

exponentFormatter examples

exponentFormatter(1e-7);

//> "0.0000001"

Changelog

License

Price Like Humans is MIT licensed.

0.8.0

4 years ago

0.7.6

4 years ago

0.7.5

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.0

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.9

4 years ago

0.6.8

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago