Giter Site home page Giter Site logo

hustcc / hrn Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 1.0 9 KB

:1234: Type module to format number into Human-Readable-String. e.g. 4567 -> 4.6 k.

Home Page: https://git.hust.cc/hrn

License: MIT License

JavaScript 100.00%
javascript human-readable string hrn

hrn's Introduction

hrn

hrn is short for Human Readable Number, a simple javascript for browserjs / nodejs library to format number into human-readable string.

Build Status npm npm npm

1. Install

npm install --save hrn

2. Import It

var hrn = require('hrn');

//or

import hrn from 'hrn';

3. Usage & API

There is only one API named hrn(number, fixed, formatter).

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.

// 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

hrn's People

Contributors

hustcc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nuriangraini

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.