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

2.0.0 • Public • Published

Build Status Total Downloads Latest Version License

as-type

Convert undetermined data types to the type you want.

Installation

npm install --save as-type

Usage

const as = require('as-type')
 
console.log(as.boolean('true')) // true
console.log(as.boolean('t')) // true
console.log(as.boolean('T')) // true
console.log(as.boolean('yes')) // true
console.log(as.boolean('y')) // true
console.log(as.boolean('Y')) // true
console.log(as.boolean(1)) // true
console.log(as.boolean('asdf')) // false
console.log(as.boolean(5)) // false
 
console.log(as.integer('5')) // 5
console.log(as.integer('5.5')) // 5
console.log(as.integer('five')) // 0
 
console.log(as.float('5')) // 5
console.log(as.float('5.5')) // 5.5
console.log(as.float('five')) // 0

/as-type/

    Package Sidebar

    Install

    npm i as-type

    Weekly Downloads

    43

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    5.41 kB

    Total Files

    6

    Last publish

    Collaborators

    • shnhrrsn