price-like-humans
TypeScript icon, indicating that this package has built-in type declarations

0.8.0 • Public • Published

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

Methods Returns Description
formattedPrice(value, options) string Formatting incoming numbers to humans like price with user locale delimiter
exponentFormatter(value) string Formatting exponential numbers to human likes numbers. Exponent free

formattedPrice

Argument Required Argument type Description
value *required number, string Incoming numbers which will be formatted (exponential friendly)
options optional object Settings list, see formattedPrice options

exponentformatter

Argument Required Argument type Description
value *required number, string Incoming exponential numbers which will be formatted

formattedPrice options

Argument Argument type Description
delimiter string Delimiter symbol. Number which split decimal. Can be replaced
separator string Symbol which separates grouped number. Can be replaced
lang string You 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

Show changelog v0.8.0 - formattedPrice can formats exponential too v0.7.0 - Changed arguments in formattedPrice - Add more coverage and tests - Remove debian lang detector v0.6.7 - Added prettier - Added dev unit tests - Fix imports with methods only v0.6.1 - Added typescript - Added custom locale to formattedPrice - Added several tests - Added minifying - Removed excessZero function (if you need that func, just parseFloat your number) - Removed babel, compiling by rollup & typescript v0.5.0 - Built with RollUp and Babel v0.4.0 - Updated jest dependencies v0.3.5 - Minor fixes v0.3.1 - Changed priceFormatter incoming arguments type. Now it takes an object or once value - Tested with Jest - Refactored locale.js - Refactored formattedPrice: Add default values

License

Price Like Humans is MIT licensed.

Package Sidebar

Install

npm i price-like-humans

Weekly Downloads

0

Version

0.8.0

License

MIT

Unpacked Size

12 kB

Total Files

4

Last publish

Collaborators

  • irodger