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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@samuil4/dirty-number

v1.0.1

Published

Parse dirty string to number

Downloads

7

Readme

dirty-number

Extract correct number from dirty string like -100,000 00 . 00.

Usage

Install the library:

npm install @samuil4/dirty-number

Then, in the file where you want to use it:

//ES6 / TypeScript

import { DirtyNumber } from '@samuil4/dirty-number';

//...
const numberParser = new DirtyNumber();
numberParser.parse('1,000,000.45') // => 1000000.45 as Number
//node.js

const DirtyNumber = require('@samuil4/dirty-number/node').default;

//...
const numberParser = new DirtyNumber();
numberParser.parse('1,000,000.45') // => 1000000.45 as Number

Default configuration works as follows

// 1. strip any non numerical characters excluding +-.,
// 2. Assuming denominator is . character
// 3. Assimung separator is , character
const numberParser = new DirtyNumber();

numberParse.parse('3.14'); // => 3.14
numberParse.parse('3,14'); // => 314
numberParse.parse('3,140.142'); // => 3140.142
numberParse.parse('3,000,140.142'); // => 3000140.142
numberParse.parse('3 , 000 , 140.142'); // => 3000140.142

// 4. Note: When denominator is matched multiple times, denominator becomes separator
numberParse.parse('3.140.142'); // => 3140142

// 5. Use on any dirty strings, like crawled prices
numberParse.parse('3.14 USD'); // => 3.14
numberParse.parse('Price: 3.14 USD'); // => 3.14

Configurable options

Configure the denominator symbol

//ES6 / TypeScript
// Denominator

import { DirtyNumber } from '@samuil4/dirty-number';

//...
const numberParser = new DirtyNumber({
  denominator: '#'
});
numberParser.parse('1,000,000#45') // => 1000000.45 as Number

Configure separator symbol

//ES6 / TypeScript
// Separator

import { DirtyNumber } from '@samuil4/dirty-number';

//...
const numberParser = new DirtyNumber({
  separator: '#'
});
numberParser.parse('1#000#000.45') // => 1000000.45 as Number

Weird examples

//ES6 / TypeScript
// Denominator ,

import { DirtyNumber } from '@samuil4/dirty-number';

const numberParser = new DirtyNumber({
  denominator: ','
});

const num = numberParser.parse('3,14'); // => 3.14

Local Development

  1. Fork the project and clone it locally
  2. npm install to install the library dependencies
  3. npm install -g typescript to install TypeScript globally
  4. npm test to run tests
  5. npm run build to build for production