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

114k.js

v0.1.3

Published

114k.js is a lightweight number abbreviation library.

Downloads

109

Readme

114k.js

A a lightweight number abbreviation library.

Get Started

Install

Using npm:

npm i 114k.js

Using <script>

<script src="format114k.global.js"></script>

Usage

import { abbreviateNumber, formatNumber } from "114k.js"

console.log(abbreviateNumber(114514)); // 114.5k
console.log(formatNumber(114514)); // 114,514

or

console.log(format114k.abbreviateNumber(114514)); // 114.5k
console.log(format114k.formatNumber(114514)); // 114,514

APIs

formatNumber(num: Number): String

Get the formatted number like 114,514

Params

num: Number

The number to be formatted.

abbreviateNumber(num: Number, digits?: Number, rounding?: String, locale?: String): String

Params

num: Number

The number to be abbreviated.

digits?: Number

Number of decimal places to be retained. An integer is required.

Default: 1

rounding?: String

Rounding method.

Default: "round"

Possible options:

  • "round"
  • "ceil"
  • "floor"
locale?: String

Language of the abbreviated number.

Default: "en"

Possible options:

  • "en" // k, M, B, T...
  • "ru" // тыс., млн...
  • "zh-CN" // 万, 亿, 万亿...
  • "zh-TW" // 萬, 億, 兆, 京...
  • "ja" // 万, 億, 兆, 京...
  • "ko" // 만, 억, 조, 경...
  • "vi" // nghìn, tỷ, nghìn tỷ

Maximum Numbers:

  • Maximum num of zh-CN, zh-TW, ja and ko is 1e25-1.
  • Maximum num of en and ru is 1e16-1.
  • Maximum num of vi is 1e13-1.

Examples

console.log(
    `The population of India in 2023 was ${formatNumber(1428627663)}, about ${abbreviateNumber(1428627663, 2, "round", "en")} people.`
)
// The population of India in 2023 was 1,428,627,663, about 1.43B people.
console.log(
    `台灣共有${abbreviateNumber(36197, 2, "round", "zh-TW")}平方千米的土地。`
)
// 台灣共有3.62萬平方千米的土地。
console.log(
    `中国大陆在约${abbreviateNumber(9596961, 2, "round", "zh-CN")}平方千米的土地中塞入了约${abbreviateNumber(1426389855, 2, "round", "zh-CN")}的人口。`
)
// 中国大陆在约959.7万平方千米的土地中塞入了约14.26亿的人口。