Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/izolate/millify
Convert long numbers to pretty, human-readable strings
https://github.com/izolate/millify
abbreviations human-readable human-readable-units javascript pretty units
Last synced: about 2 months ago
JSON representation
Convert long numbers to pretty, human-readable strings
- Host: GitHub
- URL: https://github.com/izolate/millify
- Owner: izolate
- License: mit
- Created: 2015-11-12T22:52:15.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2023-07-19T00:52:24.000Z (about 1 year ago)
- Last Synced: 2024-07-01T15:54:24.928Z (3 months ago)
- Topics: abbreviations, human-readable, human-readable-units, javascript, pretty, units
- Language: TypeScript
- Homepage: https://npmjs.com/package/millify
- Size: 988 KB
- Stars: 176
- Watchers: 2
- Forks: 13
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Millify
Converts long `numbers` into pretty, human-readable `strings`.
Before :unamused: | After :tada:
--- | ---
`2000` | `'2K'`
`10000` | `'10k'`
`42500` | `'42.5 kg'`
`1250000` | `'1.25 MB'`
`2700000000` | `'2.7 bil'`## Install
Get it on [npm](https://www.npmjs.com/package/millify):
```bash
npm install millify
```
## Usage### Command line
```bash
$ millify 12345
12.3K
```See `millify --help` for options.
### Programmatically
#### `millify(value: number, options: MillifyOptions)`
```js
import millify from "millify";// For CommonJS: `const { millify } = require("millify");`
millify(2500); // 2.5K
millify(1024000, {
precision: 3,
lowercase: true
});
// 1.024mmillify(39500, {
precision: 2,
locales: "de-DE"
});
// 3,95Kmillify(1440000, {
units: ["B", "KB", "MB", "GB", "TB"],
space: true,
});
// 1.44 MB
```## Options
Name | Type | Default | Description
--- | --- | --- | ---
`precision` | `number` | `1` | Number of decimal places to use
`locales` | `string \| Array` | browser language | Formats the number in different languages
`lowercase` | `boolean` | `false` | Use lowercase abbreviations
`space` | `boolean` | `false` | Add a space between number and abbreviation
`units` | `Array` | `['', 'K', 'M', 'B', 'T', 'P', 'E']` | Unit abbreviations