https://github.com/hustcc/hrn
:1234: Type module to format number into Human-Readable-String. e.g. 4567 -> 4.6 k.
https://github.com/hustcc/hrn
hrn human-readable javascript string
Last synced: 3 months ago
JSON representation
:1234: Type module to format number into Human-Readable-String. e.g. 4567 -> 4.6 k.
- Host: GitHub
- URL: https://github.com/hustcc/hrn
- Owner: hustcc
- License: mit
- Created: 2016-10-12T08:05:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-02T05:38:26.000Z (over 7 years ago)
- Last Synced: 2025-03-17T07:51:26.673Z (3 months ago)
- Topics: hrn, human-readable, javascript, string
- Language: JavaScript
- Homepage: https://git.hust.cc/hrn
- Size: 8.79 KB
- Stars: 23
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hrn
> **hrn** is short for **H**uman **R**eadable **N**umber, a simple javascript for browserjs / nodejs library to format number into human-readable string.
[](https://travis-ci.org/hustcc/hrn) [](https://www.npmjs.com/package/hrn) [](https://www.npmjs.com/package/hrn) [](https://www.npmjs.com/package/hrn)
# 1. Install
> **npm install --save hrn**
# 2. Import It
```js
var hrn = require('hrn');//or
import hrn from 'hrn';
```# 3. Usage & API
There is only one API named `hrn(number, fixed, formatter)`.
```js
hrn(1234000); // '1.2 M'
hrn(1234000, 3); // '1.234 M'
hrn(1234000, 3, 'en'); // '1.234 M'
hrn(12340, 2, 'zh_CN'); // '1.23 万', `en` / `zh_CN` supported, `en` is default.```
You can customize the number formatter.
```js
// format number
var formatter = ['kmgtpezy'.split(''), 1e3];
hrn('1234000', 1, formatter) // '1.2 m'// format time diff
formatter = [['s', 'm', 'h', 'd'], [1, 60, 60, 24]];
hrn(23, 1, formatter); // '23.0 s' -> 23 seconds
hrn(23 * 60, 1, formatter); // '23.0 m' -> 23 minutes
hrn(23 * 60 * 60, 1, formatter); // '23.0 h' -> 23 hours
hrn(23 * 60 * 60 * 24, 1, formatter); // '23.0 d' -> 23 days
```# 4. Test
> npm install
>
> npm test# 5. LICENSE
MIT@[hustcc](https://github.com)