Numerous Philanthropic Misanthropes

    castit

    1.2.0 • Public • Published

    castit Build Status via Travis CI NPM version

    Opinionated Javascript variable casting with deep structures support for easily and automatically cast some common datatypes in JavaScript

    Based on https://github.com/bahamas10/node-autocast but adapted for Fluid Configure existing JSON configurations. This version is meant to be used in CommonJS environments.

    The main differences with autocast are:

    • hexadecimal and octals are not automatically casted, they remain as string values. Casing them is as simple as adding a plus sign in front of the string +"0xff".
    • "" and "-" are both casted to an empty string.
    • functions objects and array are not casted by default
    • supports deep casting by passing an optional deep flag.

    Install

    npm install castit --save

    Usage

    var cast = require("castit");

    Example

    > var cast = require("castit");
    [Function: cast]
    > cast("5")
    5
    > cast("5.8")
    5.8
    > cast("5.8.8")
    "5.8.8"
    > cast("null")
    null
    > cast("undefined")
    undefined
    > cast("NaN")
    NaN
    > cast("true")
    true
    > cast("false")
    false
    > cast("normal string")
    "normal string"
    > cast(fn)
    fn
    > cast({nested: ["false"]}, true)
    {nested: [false]}

    Tests

    npm test
    

    License

    MIT Licensed

    Install

    npm i castit

    DownloadsWeekly Downloads

    29

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    7.53 kB

    Total Files

    4

    Last publish

    Collaborators

    • aearly
    • bermi
    • jhartman86