0.0.1 • Published 7 years ago

formaat v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Formaat

Bower version NPM version

Number formatter

Easily format a number to fit in a given space (number of characters).

Compatible with Require.js/AMD and NodeJS.

Usage

The formatted number can be generated given a number of characters to fit in. Commas, periods count as half-spaces. If a number cannot be abbreviated, it will be cropped with tildes.

Initialize formaat

The formaat constructor takes a number of characters to fit in. Commas, periods count as half-spaces.

// pass in number of characters to fit in
var formaat = formaat(3.5);

Generate number

Pass in the number to be formatted.

Numbers over a trillion will be formatted as "1T+".

// Generate number
var formatted = formaat.abbrev(8100);

8.1K

Tests

A Mocha test suite is available.

npm install
npm test
0.0.1

7 years ago