stereotype

1.0.1 • Public • Published

Stereotype.js npm Version Build Status Coverage Status

Cast a string (where possible) to a primitive type.

Usage

stereotype('undefined'); //=> undefined
stereotype('null');      //=> null
stereotype('NaN');       //=> NaN
stereotype('Infinity');  //=> Infinity
stereotype('true');      //=> true
stereotype('3.14');      //=> 3.14
stereotype('0xFF');      //=> 255
 
stereotype({});          //=> {}
stereotype('foo');       //=> '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

License

MIT license

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    7,584
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    7,584
  • 1.0.0
    1

Package Sidebar

Install

npm i stereotype

Weekly Downloads

7,585

Version

1.0.1

License

MIT

Last publish

Collaborators

  • yuanqing