Home handlebars.numeral

Handlebars Numeral helper

{{number n}}

Content helpers providing Numeral and Wolsey functionality for Handlebars

Version

0.1.1

Installation

npm install handlebars.numeral

Registering the helpers

 var Handlebars = require("handlebars");
 var NumeralHelper = require("handlebars.numeral");
 NumeralHelper.registerHelpers(Handlebars);

Using the helpers

number

Formats a number

Assuming default en format 0,0[.]00

{{number 3000}}                   → «3,000»

{{number 3000.2}}                 → «3,000.20»

{{number 3000.234}}               → «3,000.23»

{{number 3000.236}}               → «3,000.24»

{{number 30000000}}               → «30,000,000»

Formats with an explicit format

{{number "3000.2" "0"}}           → «3000»

{{number "3000.2" "0.0"}}         → «3000.2»

{{number "3000.234" "0,0[.]0"}}   → «3,000.2»

{{number 30000000 "0a"}}          → «30m»

See number

numeral

Outputs a number as words

{{numeral 2001}}                  → «two thousand and one»

See numeral

ordinal

Outputs a number as an ordinal

{{ordinal 2001}}                  → «two thousand and first»

As a number

{{ordinal true}}
{{ordinal number=true}}           → «2001st»

See ordinal

currency

Formats a number as a currency

{{currency 3000}}                 → «£3,000.00»
{{currency 3000.236}}             → «£3,000.24»

See currency

byte

Outputs a number as an ordinal

{{byte 2000000}}                  → «2MB»

See byte

Tests

npm test

To see output generated by tests

npm run test:output