Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.
/ two-digit Public archive

๐Ÿ”Ÿ Format the number to two digits

License

Notifications You must be signed in to change notification settings

JB1905/two-digit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

81 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

NPM version NPM downloads NPM license Codecov Travis Bundle size

About

Format the number to two digits

Alternatives

How to Install

First, install the library in your project by npm:

$ npm install two-digit

Or Yarn:

$ yarn add two-digit

Getting Started

Connect the library to the project with ES6 import:

import twoDigit from 'two-digit';

Or CommonJS:

const twoDigit = require('two-digit');

Next use the library:

const formattedValue = twoDigit(/* value */);

Params

Type Description
string or number (if a value of a different type is passed, the function returns the value passed) Value to be formatted

Example

Example results for different data:

twoDigit(5); // '05'
twoDigit(15); // 15
twoDigit(120); // 120
twoDigit(2.51); // '02.51'
twoDigit(Math.PI); // '03.141592653589793'
twoDigit(-1); // -1
twoDigit('2'); // '02'
twoDigit('04'); // '04'
twoDigit('10'); // '10'
twoDigit('204'); // '204'
twoDigit('2.1.3'); // '2.1.3'
twoDigit(0b111); // '07'
twoDigit(0b1100); // 0b1100 (12 decimal)
twoDigit(0o5); // '05'
twoDigit(0o12); // 0o12 (10 decimal)
twoDigit(0x8); // '08'
twoDigit(0xf2); // 0xf2 (242 decimal)
twoDigit('J'); // 'J'
twoDigit('Hello World!'); // 'Hello World!'
twoDigit({ name: 'John' }); // { name: 'John' }
twoDigit(Infinity); // Infinity
twoDigit(null); // null

License

This project is licensed under the MIT License ยฉ 2020-present Jakub Biesiada