auto-parse any value you happen to send in.
auto-parse
any value you happen to send in like: String
, Number
, Boolean
, Array
, Object
, Function
, undefined
and null
and it shall get parsed to the appropriate value.
GET IT: npm install auto-parse
Sample usage:
1
2
3
4
5
6
7
8
9
10
11
12
const autoParse = require ( "auto-parse" )
autoParse ([
'1' , 'TrUe' , ' undefined ' ,
' null ' , '[]' , { age : "50" }
]);
/*
[1, true, undefined, null, [], {age: 50} ]
*/
1
2
3
4
5
6
// Set Type
autoParse ( 1 , 'Boolean' ) => true
autoParse ( 0 , 'Number' ) => 0
autoParse ( 1 , Boolean ) => true
autoParse ( 0 , Number ) => 0
autoParse ( 1234 , String ) => '1234'
1
2
3
// dates
autoParse ( '1989-11-30' , 'date' ) => Thu Nov 30 1989 18 : 00 : 00 GMT - 0600 ( CST )
autoParse ( '1989-11-30' , Date ) => Thu Nov 30 1989 18 : 00 : 00 GMT - 0600 ( CST )
1
2
3
4
5
// Passing Functions to type
function Color ( inputColor ) {
this . color = inputColor
}
autoParse ( '#AAA' , Color ) => { color : '#AAA' }
GIF FTW!