Price like Humans
![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)
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';
import { formattedPrice, exponentFormatter } from 'price-like-humans';
Examples
formattedPrice
examples
Without separator arguments (putted your local separator)
formattedPrice(12345.6789);
Using with options
formattedPrice(12345.6789, { delimiter: ',' });
formattedPrice(12345.6789, { separator: '.' });
formattedPrice(12345.6789, { delimiter: '.', separator: ',' });
formattedPrice(12345.6789, { lang: 'ru' });
formattedPrice(12345.6789, { lang: 'en' });
formattedPrice(1e-7, { lang: 'en' });
exponentFormatter
examples
exponentFormatter(1e-7);
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.