diff --git a/lib/util.js b/lib/util.js index a609a2f5..bcfe8ada 100644 --- a/lib/util.js +++ b/lib/util.js @@ -526,97 +526,30 @@ } /** - * functions check is variable is array + * functions check is variable is type of name + * * @param variable */ - type.array = function(variable) { - var result; - - if (Array.isArray) - result = Array.isArray(variable) ; - else - result = type(variable) === 'array'; - - return result; - }; + function typeOf(name, variable) { + return type(variable) === name; + } - /** - * functions check is variable is arrayBuffer - * @param variable - */ - type.arrayBuffer = function(variable) { - return type(variable) === 'arraybuffer'; - }; + function typeOfSimple(name, variable) { + return typeof variable === name; + } - /** - * functions check is variable is boolean - * @param variable - */ - type.boolean = function(variable) { - return typeof variable === 'boolean'; - }; + ['arrayBuffer', 'object', 'file', 'array'] + .forEach(function(name) { + type[name] = typeOf.bind(null, name); + }); - /** - * functions check is variable is function - * @param variable - */ - type.function = function(variable) { - return typeof variable === 'function'; - }; - - /** - * functions check is variable is number - * @param variable - */ - type.number = function(variable) { - return typeof variable === 'number'; - }; - - /** - * functions check is variable is object - * @param variable - */ - type.object = function(variable) { - var type = Util.type(variable), - is = type === 'object'; - - return is; - }; - - /** - * functions check is variable is string - * @param variable - */ - type.string = function(variable) { - return typeof variable === 'string'; - }; - - /** - * functions check is variable is string - * @param variable - */ - type.undefined = function(variable) { - return typeof variable === 'undefined'; - }; - - /** - * functions check is variable is File - * @param variable - */ - type.file = function(variable) { - var FILE = '[object File]', - name, is; - - name = Util.exec.ifExist(variable, 'toString'); - - is = name === FILE; - - return is; - }; + ['string', 'undefined', 'boolean', 'number', 'function'] + .forEach(function(name) { + type[name] = typeOfSimple.bind(null, name); + }); return type; } - /** * function return false */