UNPKG

jstools-utils

Version:
2 lines 3.16 kB
/*! jstools-utils 2015-05-02 */ !function(a,b){"use strict";"undefined"!=typeof module?module.exports=b():a.define?a.define("$utils",b):a.angular?a.angular.module("jstools.utils",[]).factory(b):a.$utils||(a.$utils=b(),a._||(a._=a.$utils))}(this,function(){"use strict";function a(a){return function(b){return typeof b===a}}function b(a){return function(b){return b instanceof a}}function c(a,b,c){if(!a instanceof Object)return!1;var d,e=b.split(".");if(void 0!==c){if(e.length){d=e.shift();for(var f=e.shift();f;)a[d]||(a[d]={}),a=a[d],d=f,f=e.shift();return a[d]=c,c}return!1}for(var g=0,h=e.length,i=a||{};h>g;g++){if(d=e[g],!(d in i))return!1;i=i[e[g]]||{}}return i}function d(){for(var a,b=u.call(arguments),c=u.call(arguments);c;){if(typeof b!=typeof c&&(b=c instanceof Array?[]:c instanceof Object?{}:c),c instanceof Object)for(a in c)void 0!==c[a]&&(typeof b[a]!=typeof c[a]?b[a]=d(void 0,c[a]):b[a]instanceof Array?[].push.apply(b[a],c[a]):b[a]=b[a]instanceof Object?d(b[a],c[a]):c[a]);c=u.call(arguments)}return b}function e(){for(var a,b=u.call(arguments),c=u.call(arguments);c;){for(a in c)b[a]=typeof b[a]!=typeof c[a]?c[a]:c[a];c=u.call(arguments)}return b}function f(a){return d(void 0,a)}function g(){for(var a=(arguments[0]||"").replace(/\/$/,""),b=1,c=arguments.length-1;c>b;b++)a+="/"+arguments[c].replace(/^\/|\/$/,"");return c&&(a+=arguments[c]?"/"+arguments[c].replace(/^\//,""):""),a}function h(a,b){for(var c=a[0].apply(null,b),d=1,e=a.length;e>d;d++)c=a[d](c);return c}function i(a,b){for(var c=0,d=b.length;d>c;c++){if(!b[c]instanceof Function)throw"only Functions are allowed as pipe arguments";a.push(b[c])}}function j(a,b,c){for(var d=0,e=a.length;e>d;d++)b.apply(c,[a[d],d])}function k(a,b,c){for(var d in a)b.call(c,[a[d],d])}function l(a,b,c){a instanceof Array?j(a,b,c):a instanceof Object&&k(a,b,c)}function m(a,b){if(!(b instanceof Function))return a.indexOf(b);for(var c=0,d=a.length;d>c;c++)if(b(a[c]))return c;return-1}function n(a,b){var c,d;if(b instanceof Function)for(c=0,d=a.length;d>c;c++)b(a[c])&&(a.splice(c,1),c--);else for(c=0,d=a.length;d>c;c++)a[c]===b&&(a.splice(c,1),c--)}function o(a,b){for(var c in b)if(a[c]!==b[c])return!1;return!0}function p(a,b){for(var c in b)if(a[c]===b[c])return!0;return!1}function q(a,b){for(var c=0,d=a.length;d>c;c++)if(o(a[c],b))return a[c];return!1}function r(a,b){for(var c=[],d=0,e=a.length;e>d;d++)o(a[d],b)&&c.push(a[d]);return c}function s(a){this.value=a}function t(a){return new s(a)}var u=[].shift,v={isFunction:a("function"),isString:a("string"),isNumber:a("number"),isArray:b(Array),isDate:b(Date),isRegExp:b(RegExp),isObject:function(a,b){return a instanceof Object?"any"===b?!0:typeof a===(b||"object"):!1},key:c,keys:Object.keys,extend:e,merge:d,copy:f,matchAll:o,matchAny:p,find:q,filter:r,joinPath:g,each:l,indexOf:m,remove:n,pipe:function(){var a=[];i(a,arguments);var b=function(){return h(a,arguments)};return b.pipe=function(){return i(a,arguments),b},b},chain:function(a){return new s(a)}};return j(["key","keys","each","indexOf","remove"],function(a){s.prototype[a]=function(){[].unshift.call(arguments,this.value),t[a].apply(null,arguments)}}),e(t,v),t});