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

js-number-formatter

v2.1.0

Published

A javascript module that scans through string to remove non-numerals and formats out any found numbers based on configuration passed to it.

Downloads

68

Readme

Number Formatter

A javascript module that scans through string to remove non-numerals and formats out any found numbers based on configuration passed to it.

💾 Setup

You need to have NodeJS installed on your computer before using npm. Open a terminal/command prompt and enter the codes below to install the package:

npm install js-number-formatter

🔨 Usage

// -- Require the module
import numberFormat from 'js-number-formatter';

const value = '3.142857';

const options = {
  // ... check the parameters section for more info on options
};

// -- Call function and pass the value to format and options to it or just the value
numberFormat(value, options);

📙 Parameters

🎨 Examples

numberFormat(3892); // Result: 3,892.00

numberFormat('140hajs7'); // Result: 1,407.00

numberFormat("you can't be serious ..."); // Result: 0

numberFormat("Hello World 20-06-2019", {
  opAllowSign: false
}); // Result: 20,062,019.00

numberFormat('-00034dj^nkjlsd$knls4h%bj.34.5', {
  // Returns zero '0' if string contains no digits
  // default: true, [test: '-00034.dj^nkjls.d$knls.4h%bj345' | true: -34.4345 | false: -34.4345]
  opReturnZeroIfNoDigit: true,
  // Return the absolute number without possible preceeding zeros '0'
  // default: true, [test: '-00034.dj^nkjls.d$knls.4h%bj345' | true: -34.4345 | false: -00,034.4345]
  opReturnAbsoluteNumber: true,
  // Allows sign (-) if true, removes any present sign if false
  // default: true [test: '-00034.dj^nkjls.d$knls.4h%bj345' | true = -34.4345 | false = 34.4345]
  opAllowSign: true, 
  // If decimal should be allowed or not
  // default: true [test: '-00034.dj^nkjls.d$knls.4h%bj345' | true = -34.4345 | false = -34]
  opAllowDecimal: true, 
  // Forces decimal even if string contains no decimal points (but only if opAllowDecimal is true)
  // default: true [test: '-00034dj^nkjlsd$knls4h%bj345' | true: -344,345.00 | false: -344,345]
  opForceDecimal: true,
  // Ignores any already existing decimal point in the string (very useful for formatting number in input field)
  // default: false
  opIgnoreDecimal: true,  
  // Appends zero '0' to result if just one digit is found after the last decimal point
  // default: true [test: '-00034dj^nkjlsd$knls4h%bj34.5' | true: -34,434.50 | false: -34,434.5]
  opAppendZeroToDecimal: true,
  // Character to use im place of the decimal period symbol
  // default: '.'
  opDecimalDelimiterChar: '.',
  // Thousands separator
  // default: ','
  opDelimiterChar: ',',
  // Thousands character spacing with ' '
  // default: false [test: '-00034dj^nkjlsd$knls4h%bj.34.5' | true: -34, 434.50 | false: -34,434.50]
  opAddSpaceToDelimiter: true
});