WebGAP Format Utils
README
This is the format utilities module for WebGAP.
Contains formatter for Dates, String, Numbers, Bytes and Percentage.
Dependencies
Loads default configuration using @webgap/configuration.
Depends on String for string format.
Depends on Numeral for number format.
Requirements
A configuration file must exist (check @webgap/configuration documentation).
API
Installation
npm install @webgap/format-utils --save
Usage
var format = require('@webgap/format-utils').format();
...
format.bytes(256000);
format.percentage(1);
format.number(10);
format.currentDateTimeUnix();
format.date(1318781876406);
format.dateTime(1318781876406);
format.dateFromNow(1318781876406);
format.truncate('This is a long string that should be truncated...lets make it a bit longer...and a bit longer...', 20);
Options
var options = {
dateFormat: "YYYY-MM-DD Z",
dateTimeFormat: "YYYY-MM-DDTHH:mm:ss Z",
timeFormat: "HH:mm:ss Z",
decimalFormat: "0,0.00",
percentageFormat: "0.00%",
byteFormat: "0.0b"
};
var format = require('@webgap/format-utils').format(options);
...
format.percentage(1);
...
Check tests for more examples.
License
Apache License, Version 2.0