1.0.1 • Published 9 months ago

factorio-abbreviate-number v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

factorio-abbreviate-number

This is a Deno and Node JS/TS library for abbreviating numbers in the style Factorio does.

Numbers are abbreviated with a suffix for the order of magnitude (k, M, G) if they're great enough. One fraction digit is only shown if there are fewer than 2 digits and the number has a suffix or a fractional part.

NumberAbbreviation
11
1919
199199
200200
19991.9k
20002.0k
1999919k
2000020k
199999199k
19999991.9M
1999999919M
199999999199M
19999999991.9G
1999999999919G
0.990.9
1.91.9
1.991.9

Usage

// Deno
import { abbreviateNumber } from "https://deno.land/x/factorio_abbreviate_number/mod.ts";

console.log(abbreviateNumber(123456789)); // 123M
// Node
import { abbreviateNumber } from "factorio-abbreviate-number";

console.log(abbreviateNumber(123456789)); // 123M

Documentation

This library is made available for Deno on deno.land at https://deno.land/x/factorio_abbreviate_number, and has documentation pages generated at https://deno.land/x/factorio_abbreviate_number/mod.ts.

This library is made available for Node on npm as factorio-abbreviate-number.

1.0.1

9 months ago

1.0.0

9 months ago