check-type
Version:
Library to check variable type and properties in object.
2 lines • 1.4 kB
JavaScript
/*! check-type@v0.4.11 - 2014-06-28 */
!function(){"use strict";var a,b,c;a=function(_){var a,b={};return a=function(c){var d={};return d.is=function(a){var d;if(!_.isString(a))throw new Error("Provided type is not a string");if(d=b["is"+a.toLowerCase()],!_.isFunction(d))throw new Error("Unsupported type",a);return d(c)},d.is.not=function(a){return!this(a)},d.has=function(a){var b,d,e=!0;if(!_.isString(a))throw new Error("Provided path is not a string");return b=a.split("."),d=c,b.forEach(function(a){e&&_.isObject(d)&&!_.isUndefined(d[a])?d=d[a]:e=!1}),e},d.matches=function(b){var d=!0;if(!_.isObject(b))throw new Error("Provided stucture is not an object");return _.isObject(c)?(_.each(b,function(b,e){a(c[e]).is.not(b)&&(d=!1)}),d):!1},d},a.init=function(a,c){var d,e;return _.isUndefined(a)?(a=_,e=_.without(_.functions(a),"isEqual")):e=_.functions(a),d=_.reduce(e,function(b,c){return b[c]=a[c],b},{}),Object.keys(d).forEach(function(a){a.match(/^is[A-Z]/)&&(_.isUndefined(b[a.toLowerCase()])||c)&&(b[a.toLowerCase()]=d[a])}),this},a.clear=function(){return b={},this},a},"undefined"!=typeof module&&(module.exports=a(require("underscore"))),"undefined"!=typeof define?define(["underscore"],function(_){return a(_)}):"undefined"!=typeof window&&(b=a(window._),c=function(){var a=window.check;return function(){return b===window.check&&(window.check=a),b}}(),b.noConflict=c,window.check=b)}();