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

price-like-humans

v0.8.0

Published

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

Downloads

14

Readme

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

License

Price Like Humans is MIT licensed.