Newlyweds Proposing Marriage
Have ideas to improve npm?Join in the discussion! »

friendly-typesTypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Friendly Types

This ultra-simple library contains just three functions which simplifies primitive types conversion.

Installation

$ npm install --save friendly-types

Usage

const { toBoolean, toNumber, toString } = require("friendly-types");
// import { toBoolean, toNumber, toString } from "friendly-types";
 
toBoolean(undefined);   // false
toBoolean(null);        // false
toBoolean(0);           // false
toBoolean(1);           // true
toBoolean("");          // false
toBoolean(" ");         // true
toBoolean("False");     // false ("0", "false", "off" and "no" strings are converted to false)
toBoolean("True");      // true
toBoolean("whatever");  // true
 
toNumber(undefined);    // 0
toNumber(null);         // 0
toNumber(false);        // 0
toNumber(true);         // 1
toNumber("-123.45");    // -123.45
toNumber("it's 5");     // error!
 
toString(undefined);    // ""
toString(null);         // ""
toString(false);        // "false"
toString(true);         // "true"
toString(0);            // "0"
toString(-123.45);      // "-123.45"

Need more examples? See tests.

Install

npm i friendly-types

DownloadsWeekly Downloads

2

Version

1.0.0

License

UNLICENSED

Unpacked Size

8.54 kB

Total Files

6

Last publish

Collaborators

  • avatar