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 🙏

© 2026 – Pkg Stats / Ryan Hefner

amount-formatter

v1.1.0

Published

Format amount to currency and currency to amount

Downloads

10

Readme

amount-formatter

A lightweight package to format amounts to currency format and convert back to numeric values.

Installation

npm install amount-formatter

or if you use yarn:

yarn add amount-formatter

Features

  • Convert numbers to currency format
  • Convert currency formatted strings to numeric values

Usage

currency()

Converts a number or string to currency format:

import { currency } from 'amount-formatter';

currency(1000); // "1,000.00"
currency('1000'); // "1,000.00"
currency('1,000'); // "1,000.00"
currency('1000.5'); // "1,000.50"
currency('$1,000.50'); // "1,000.50"
currency(''); // ""
currency(undefined); // ""
currency(null); // ""
currency(); // ""

You can optionally truncate decimals and add currency symbols:

currency(123.4567, { truncate: 2 }); // "123.45"
currency(123.4567, { truncate: 0 }); // "123"
currency(123.4567, { truncate: 4 }); // "123.4567"

double()

Converts a currency formatted string to a number:

import { double } from 'amount-formatter';

double(1000); // 1000
double('1000'); // 1000
double('1,000'); // 1000
double('$1,000.50'); // 1000.5

API

currency(value: number | string, options?: { truncate?: number }): string

Formats a number or string to currency format.

Parameters:

  • value: The value to format. Can be a number or a string.
  • options: Optional parameter to control formatting:
    • truncate: Number of decimals to truncate to.

Returns:

  • A string in currency format (e.g., "1,000.00").

double(value: number | string): number

Converts a currency formatted string to a number.

Parameters:

  • value: The value to convert. Can be a number or a string.

Returns:

  • A number.

Examples

import { currency, double } from 'amount-formatter';

// Format a number to currency
const price = 1234.5;
const formattedPrice = currency(price);
console.log(formattedPrice); // "1,234.50"

// Convert a string to number
const priceString = '$1,234.50';
const numberPrice = double(priceString);
console.log(numberPrice); // 1234.5

// Format a string that already has currency format
console.log(currency('$1,234.50')); // "1,234.50"

Compatibility

This package works in:

  • Node.js
  • Modern browsers

License

MIT