New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

price-like-humans

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

price-like-humans

JS tools for formatting price or numbers to human likes format.

  • 0.8.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

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

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.

Keywords

FAQs

Package last updated on 24 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc