Skip to content

Commit

Permalink
Make register of isisnt sort-of-public
Browse files Browse the repository at this point in the history
  • Loading branch information
José Moreira committed Sep 1, 2014
1 parent b679782 commit 3a27de3
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/is-isnt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = (function ( Util ){

// For internal API
Util._isisnt = {};

Util.is = {};
Util.isnt = {};

Expand All @@ -9,7 +13,7 @@ module.exports = (function ( Util ){
return instance && instance.constructor ? instance.constructor !== ClassToEval : ! ( instance instanceof ClassToEval );
};

var addEvaluator = function ( ClassToEval, keys ) {
var register = Util._isisnt.register = function ( ClassToEval, keys ) {
if( ! ClassToEval ) return;

var isFn = function ( instance ) {
Expand All @@ -28,7 +32,7 @@ module.exports = (function ( Util ){
Util.isnt[ key ] = isntFn;
});
},
addCustomEvaluator = function ( keys, isFn, isntFn ) {
registerCustom = Util._isisnt.registerCustom = function ( keys, isFn, isntFn ) {

if( Util.isnt.function( isFn ) ) {
throw new TypeError("isFn must be a function");
Expand All @@ -52,19 +56,19 @@ module.exports = (function ( Util ){
};

// Default Javascript Classes
addEvaluator( Function, [ 'Function', 'function' ] );
addEvaluator( Array, [ 'Array', 'array' ] );
addEvaluator( Object, [ 'Object', 'object' ] );
addEvaluator( String, [ 'String', 'string' ] );
addEvaluator( Error, [ 'Error', 'error' ] );
register( Function, [ 'Function', 'function' ] );
register( Array, [ 'Array', 'array' ] );
register( Object, [ 'Object', 'object' ] );
register( String, [ 'String', 'string' ] );
register( Error, [ 'Error', 'error' ] );

// Default Browser Classes
if( typeof HTMLElement !== 'undefined' ) {
addEvaluator( HTMLElement, [ 'HTMLElement', 'HTMLelement' ] );
register( HTMLElement, [ 'HTMLElement', 'HTMLelement' ] );
}

// Custom evaluators
addCustomEvaluator( [ 'numeric', 'number', 'Number' ], function ( instance ) {
registerCustom( [ 'numeric', 'number', 'Number' ], function ( instance ) {
return typeof instance === 'number' || ! isNaN( parseInt( instance ) );
});

Expand Down

0 comments on commit 3a27de3

Please sign in to comment.