Easily and automatically cast common datatypes in JavaScript

I was working on parsing output from the command line while creating the Node SMF module. This required me to inspect the elements individually and write case statements to expect certain data types be returned.

What I mean by this is...

When you parse the command line, everything gets returned as a string. So, you must do some post-processing to cast items that look like numbers to numbers, strings that look like keywords to keywords, ie 'false' to false, etc.

So, autocast was born. This module will do all of that inspection for you and return what it thinks the object should be.

Check out the project page here https://github.com/bahamas10/node-autocast

Example

var autocast = require('autocast'),
    x;

x = autocast('5')
// x => 5
x = autocast('5.8')
// x => 5.8
x = autocast('5.8.8')
// x => '5.8.8'
x = autocast('null')
// x => null
x = autocast('true')
// x => true
x = autocast('false')
// x => false
x = autocast('normal string')
// x => 'normal string'

Install

Install locally to use as a module

npm install autocast

License

MIT Licensed