Stereotype.js
Cast a string (where possible) to a primitive type.
Usage
; //=> undefined; //=> null; //=> NaN; //=> Infinity; //=> true; //=> 3.14; //=> 255 ; //=> {}; //=> 'foo'
More usage examples are in the tests.
API
stereotype(obj)
Returns, where possible, obj
cast to a primitive type. Otherwise returns obj
if obj
is not a string
, or if obj
cannot be cast to a primitive.
Installation
Install via npm:
$ npm i --save stereotype