two-digit
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

two-digit

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 libary to project using ES6 import:

import twoDigit from 'two-digit';

Or CommonJS:

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

Next use 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

Package Sidebar

Install

npm i two-digit

Weekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

6.8 kB

Total Files

9

Last publish

Collaborators

  • jbiesiada