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

@puraty/smart-number-formatter

v1.0.1

Published

TypeScript-first number formatter supporting currency, percent, and automatic K/M/B abbreviation.

Readme

@puraty/smart-number-formatter

npm version License: ISC

A TypeScript-first number formatting utility designed for simplicity and security. It leverages the native JavaScript Intl.NumberFormat API to easily handle currency, percentage, and automatic K/M/B (compact/abbreviated) notation.

Installation

npm install @puraty/smart-number-formatter

or

yarn add @puraty/smart-number-formatter

Usage

The library exports a single, type-safe function: smartNumberFormat.

  1. Abbreviated Notation (K/M/B) Use style: 'abbreviate' to automatically apply locale-specific compact notation (e.g., K for thousands, M for millions, B for billions).
import { smartNumberFormat } from '@puraty/smart-number-formatter';

// English locale abbreviation (1.2M)
console.log(smartNumberFormat(1234567, { style: 'abbreviate', locale: 'en-US' })); 
// => "1.2M"

// French locale abbreviation (1,2 M)
console.log(smartNumberFormat(1234567, { style: 'abbreviate', locale: 'fr-FR' })); 
// => "1,2 M" 

// Abbreviation with no fraction digits (1M)
console.log(smartNumberFormat(1000000, { 
    style: 'abbreviate', 
    maximumFractionDigits: 0 
})); 
// => "1M"
  1. Currency, Percent, and Decimal Formatting Standard formatting options are supported with type safety.
import { smartNumberFormat } from '@puraty/smart-number-formatter';

// Currency formatting (Euro in France)
console.log(smartNumberFormat(9876.543, { 
    style: 'currency', 
    currency: 'EUR', 
    locale: 'fr-FR',
    maximumFractionDigits: 2
})); 
// => "9 876,54 €" 

// Currency formatting (US Dollar)
console.log(smartNumberFormat(12345.67, { 
    style: 'currency', 
    currency: 'USD', 
    locale: 'en-US'
})); 
// => "$12,345.67" 

// Percentage formatting
console.log(smartNumberFormat(0.75, { style: 'percent' })); 
// => "75%"

// Always show sign
console.log(smartNumberFormat(-1000, { signDisplay: 'always' })); 
// => "-1,000"

API Reference

smartNumberFormat(value: number, options?: SmartFormatOptions): string

Formats a number according to the specified locale and style options.

| Parameter | Type | Default | Description | | :--- | :--- | :--- | :--- | | value | number | N/A | The numeric value to format. | | options | SmartFormatOptions | {} | The optional object for formatting. |

SmartFormatOptions Interface

| Property | Type | Default | Description | | :--- | :--- | :--- | :--- | | style | 'decimal' \| 'currency' \| 'percent' \| 'abbreviate' | 'decimal' | The formatting style. 'abbreviate' enables K/M/B compact notation. | | locale | string | 'en-US' | The locale string (e.g., 'en-US', 'fr-FR', 'es-ES'). | | currency | string | N/A | The currency code (e.g., 'USD', 'EUR', 'GBP'). Required if style is 'currency'. | | maximumFractionDigits | number | 1 (if style is 'abbreviate') | The maximum number of digits after the decimal point. | | signDisplay | 'auto' \| 'always' \| 'exceptZero' \| 'never' | 'auto' | Controls the display of the sign (+/-). |

Returns: A secure, alphanumeric, URL-safe string.

License

This project is licensed under the ISC License. See the LICENSE file for details.

Contributing

Contributions, bug reports, and feature suggestions are always welcome! Please feel free to open an Issue or submit a Pull Request.