Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including formatte with all npm packages installed. Try it out:

var formatte = require("formatte")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

formatte v1.1.4

Formatte is a value formater for JavaScript.

FORMATTE

Formatte logo

NPM Version NPM Downloads

Lightweight Value Formatter

const formatter = new Formatter('dollar');
const value = formatter.validate('1000000.50');
// value = '$1,000,000.50'

Intro

Formatte is a value formater for JavaScript. It uses rule sets built from utility functions like removeLeadingZeros to produce formated data.

Instaliation

This is a JavaScript module available through the npm registry. Before installing, download and install Node.JS. Installation is done using the npm install command:

npm install formatte

Contributing

Contributing Guide

Creators

The original creator of Formatte is Morgan Brown;

License

MIT

Some of the format types supported are...

  • Dollars
  • Floats
  • Integer
  • Percentage
  • Year
  • Long Percentage

Example

Input

const formated = new Formater('dollar').validate('001234.1234);

Output

'$1,234.12'

Formatte can be used with both NodeJS and Javascript. Formatte Utilizes the ES6 Class Syntax.

Currently Supported Formats

Year

Input

const formated = new Formater('year').validate('00a2014.1');

Output

'2014'

Dollar

Input

const formated = new Formater('dollar').validate('001234.1234');

Output

'$1,234.12'

Percent

Input

const formated = new Formater('percent').validate('001234.1234');

Output

'1,234.12%'

Long Percent

Input

const formated = new Formater('longPercent').validate('001234.1234');

Output

'1,234.1234%'

Integer

Input

const formated = new Formater('integer').validate('hello123402');

Output

'123402'

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free