Package Exports
- utils-type
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (utils-type) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
documentation - install - todo
simple
var type = require('utils-type');
type( 42 ); // -> { number: 42 }
type( NaN ); // -> { nan: true }
type( null ); // -> { null: true }
type( true ); // -> { boolean: true }
type( false ); // -> { boolean: true }
type( Infinity ); // -> { infinity: Infinity }
type( undefined ); // -> { undefined: true }
type( 'a string'); // -> { string: 'a string' }
type( /a regex/ ); // -> { object: /a regex/, regexp: /a regex/ } }
type( function(){ } ); // -> { object: [Function], function: [Function] }
type({ type : 'toy' }); // -> { object: { type: 'toy' } }
type( new Date() ); // -> { object: Mon Sep 08 2014 19:10:32, date: Mon Sep 08 2014 19:10:32 GMT+0200 (CEST) }
type( new Error() ); // -> { object: [Error], error: [Error] }
// and more!
type( new Stream() ); // ->
// {
// object: { domain: null, _events: {}, _maxListeners: 10 },
// stream: { domain: null, _events: {}, _maxListeners: 10 },
// eventemitter: { domain: null, _events: {}, _maxListeners: 10 }
// }
type( new EventEmitter() ); // ->
// {
// object: { domain: null, _events: {}, _maxListeners: 10 },
// eventemitter: { domain: null, _events: {}, _maxListeners: 10 }
// }one to many
type(function one(){}).match(/function|object/);
// => [Function: one]composition
The function returns an object. The type matched by that type returns itself. That is:
type(1).number // -> 1 (that is truthy)
type([1,2,3]).array // -> [1,2,3] (truthy)
type(type([1,2,3]).array[1]).number // -> 1 (truthy)falsy values maintain the value if makes sense
var arr = [false, 0, NaN, '', null, undefined];
type(type(arr).array[0]).boolean // -> true
type(type(arr).array[1]).number // -> 0
type(type(arr).array[2]).number // -> undefined
type(type(arr).array[3]).string // -> ' '
type(type(arr).array[5]).undefined // -> true
type(type(arr).array[4]).null // -> trueWhy:
NaNis not a numberfalseis a boolean, returning it will be misleading0is a number yes, but if is changed to true you can't add to it afterwardsthe empty stringis changed to an space so is truthy and operations can be made on itnullandundefinedare self explanatory
install
With npm
$ npm install utils-typetest
$ npm testtodo
- Include browser tests