1.0.3 • Published 5 years ago

int-format v1.0.3

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

Codecov Coverage

int-format

Helper library for formatting integer numbers

let str = new IntFormat("# # #").format("123");
//1 2 3

Installation

npm install int-format

Constructor

IntFormat({
	format,
	padWith,
	sigil,
	anchor
})

or

IntFormat(format)

Options

format - the format

padWith - which symbol to use to pad empty placeholders, default empty string

sigil - symbol to substitute, default #

anchor - symbol to escape sigil, default is backslash

Methods

setFormat

setSigil

setAnchor

setPad

format - takes string or number as argument

Examples

let str = new IntFormat({ padWith: '?', format: "\\## \\\\# #" }).format(12);
//#1 \\2 ?
let str = new IntFormat('+# (###) ###-##-##').format('78037764302');
//+7 (803) 776-43-02

Testing

npm run test npm run cover

Architecture

IntFormat is a simple state machine