Giter Site home page Giter Site logo

formatus's Introduction

formatus

GitHub package.json version npm GitHub repo size NPM

Do more write less

Table of Contents

  1. Why formatus
  2. Installation
  3. Basic Usage
  4. License

Installation

Using npm:

$ npm install formatus
$ npm install --save formatus

Why Formatus

There are snippets of code we keep writing everytime we want to create one tiny or huge app. Why keep repeating this snippets when you can get them all from one place? This is what formatus hopes to accomplish.

Basic Usage

First, import the package into the JavaScript file:

// importing formatus.
const formatus = require("formatus");
// or
const _ = require("formatus");
// either way works

// On Temperature
const kelvin = 2000;

kelcin.kelvinToCelcius();
// result => -73.15

// On Numbers
const count = 500000;
count.withSuffix();
// result => 500K

// On Array
const arrayList = [7000, 900, 10000, 49300];

list.arrayWithComma();
// result => [ '7,000', '900', '10,000', '49,300' ]

On Numbers

The functions from the numbers API are prototypes of the Number data type in JavaScript. The API functions will throw an error if used on value other than a number

// First import formatus
const _ = require("formatus");

const count = 200000;

count.withSuffix();
// result => 200K

The return type is a string

On Array

The functions from the array API are prototypes of the Array data type in JavaScript. The API functions will throw an error if used on value other than a array

// First import formatus
const _ = require("formatus");

const list = [2000, 100, 50000, 59300];

list.arrayWithComma();
// result => [ '2,000', '100', '50,000', '59,300' ]

The return values the array are of a string data type

For Temperature

The 4 supported temperature scales for conversion are Celcius, Kelvin, Fehrenheit, and Rankine.

Here is an example of how to convert between the 4

// From Kelvin to Celcius
const temp = 200;
// Conver from kelvin to celcius
const newTemp = temp.kelvinToCelcius();
// result => -73.15

// To convert back to celcius
newTemp.celciusToKelvin();
// result => 200

Pls note: The value returned always a string By default, the number of digit after the decimal point is always 2.

You can specify how many number of digit after the decimal you want by passing it in the function.

Example

// From Kelvin to Celcius
const temp = 200;

// One decimal place
temp.kelvinToCelcius(1);
// result => -73.1

// Integer
temp.kelvinToCelcius(0);
// result => -73

Also, checkout the full documention on Temperature API

License

MIT

formatus's People

Contributors

refjosh avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.