This repository has been archived by the owner on Dec 28, 2017. It is now read-only.
/
clone.min.js
19 lines (19 loc) · 8.99 KB
/
clone.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'use strict';(function(n){function t(){Object.defineProperties(Object.prototype,f.describe(f));f=Object.prototype;Object.defineProperty(p,"$object",{value:f})}var f={clone:function(k,h){if(arguments.length)var c=f.describe.apply(this,arguments);return Object.create(this,c)},create:function(f,h){var c=this.clone();return c.constructor.apply(c,arguments)||c},constructor:function(f,h){if("object"==typeof f)this.defineProperties(f,h);else if(arguments.length)return Object(f)},describe:function(f,h){var c=
{},a=h?h:{configurable:!0,enumerable:!0,writable:!0},d=!(h&&h.enumerable),b;for(b in f){var e=f[b],g=Object.create(a);if("("==b[0]){var i=b.match(/^\((((get|set|const|hidden|final|writable) *)+)\) +(.+)$/);if(i){var j=i[1].split(" ").sort();b=i[4];c[b]&&(g=c[b]);for(var m in j)switch(j[m]){case "const":g.writable=!1;break;case "final":g.configurable=!1;g.writable=!1;break;case "get":g.get=e;break;case "hidden":g.enumerable=!1;break;case "set":g.set=e;break;case "writable":g.writable=!0}}}if(g.get||
g.set){if("string"==typeof e){var r=e;"string"==typeof g.get?g.get=function(){return this[r]}:g.set=function(a){this[r]=a}}g.value=void 0;g.get&&(e=void 0)}else g.value=e;if(d&&"function"==typeof e||"_"==b[0])g.enumerable=!1;b.toUpperCase()==b&&(g.writable=!1);c[b]=g}c.hasOwnProperty("constructor")&&(a=c.constructor.value,"string"==typeof a?(d=a,a=Function("return function "+d+"(){return this.applySuper(arguments)}")(),a.typeName=d,c.constructor.value=a):a.typeName||(a.typeName=a.name||"CloneOf"+
this.constructor.typeName),a.prototype=this,c.constructor.enumerable=!1);return c},applySuper:function(f,h){"string"!=typeof f&&(h=f,f="constructor");"__super__"in this||this.getSuper(!0);var c=this.__super__;this.__super__=Object.getPrototypeOf(c);var a=c[f].apply(this,h);this.__super__=c;return a},callSuper:function(f,h,c){var a=Array.prototype.slice.call(arguments,1);return this.applySuper(f,a)},getSuper:function(f){var h=Object.getPrototypeOf(Object.getPrototypeOf(this));f&&this.defineProperty("__super__",
{value:h,writable:!0,configurable:!0});return h},createSuperSafeCallback:function(f,h){if("string"==typeof f){var c=this[f];"undefined"==typeof h&&(h=this)}else c=f;var a=this,d=this.__super__;return function(){if(a.__super__===d)return c.apply(h||this,arguments);var b=a.__super__;a.__super__=d;var e=c.apply(h||this,arguments);a.__super__=b;return e}},getState:function(k){for(var h=f.create(),k=k?Object.getOwnPropertyNames(this):Object.keys(this),c=0,a=k.length;c<a;c++){var d=k[c];h[d]=this[d]}return h},
copy:function(k,h,c,a){for(var d=0,b=arguments[d],e=arguments.length;d<e;b=arguments[++d])switch(typeof b){case "string":k=b;break;case "function":h=b.prototype;break;case "object":h=b;break;case "number":c=b;break;case "boolean":a=b}if("deepCopy"!=k||"deepClone"!=k)k=null;"undefined"==typeof h&&(h=f);b=this;"function"==typeof b&&Object.getOwnPropertyNames(b.prototype)&&(b=b.prototype);var g=Object.create(h),i=[];do i.push(b),b=Object.getPrototypeOf(b);while(c--&&b!=Object.prototype);i=i.reverse();
d=0;for(e=i.length;d<e;d++){var b=i[d],j=Object.getOwnPropertyNames(b);!a&&(d&&j.length)&&(g=f.apply(g,"clone"));for(var m=0,r=j.length;m<r;m++){var q=j[m],l=Object.getOwnPropertyDescriptor(b,q);k&&("object"==typeof b[q]&&null!==b[q])&&(l.value=f[k].call(b[q]));Object.defineProperty(g,q,l)}}return g},deepCopy:function h(){for(var c=arguments.length?f.apply(this,"copy",arguments):f.clone(),a=Object.getOwnPropertyNames(this),d=0,b=a.length;d<b;d++){var e=a[d],g=Object.getOwnPropertyDescriptor(this,
e);"object"==typeof this[e]&&null!==this[e]&&(g.value=h.call(this[e]));Object.defineProperty(c,e,g)}return c},deepClone:function c(a,d){for(var b=f.apply(this,"clone",arguments),e=Object.getOwnPropertyNames(this),g=0,i=e.length;g<i;g++){var j=e[g];if("object"==typeof this[j]&&null!==this[j]){var m=Object.getOwnPropertyDescriptor(this,j);m.value=c.call(this[j]);Object.defineProperty(b,j,m)}}return b},paste:function(c,a){return f.apply(c,"concat",[this,a])},concat:function(c,a){if(void 0==a)a=c.getOwnPropertyNames();
else if("object"!=typeof a&&!0==a)for(var a=c.getOwnPropertyNames(),d=c;(d=Object.getPrototypeOf(d))!==Object.prototype;)a=a.concat(d.getOwnPropertyNames());d=c;do for(var b=0,e=a.length;b<e;b++){var f=a[b],i=Object.getOwnPropertyDescriptor(d,f);i&&(Object.defineProperty(this,f,i),delete a[b])}while(a.length&&(d=Object.getPrototypeOf(d))!==Object.prototype);return this},apply:function(c,a,d,b){b?"function"==typeof b&&b.prototype&&(b=b.prototype):b="function"==typeof c[a]&&c[a].length==this[a].length&&
c||this;return b[a].apply(c,d)},can:function(c,a){var d=this;return{valueOf:function(){return a^"function"==typeof d[c]},like:function(b){b=b[c];return this.valueOf()&&a^("function"==typeof b&&b.length==d[c].length)},as:function(b){return this.valueOf()&&a^d[c]===b[c]}}},cant:function(c){return this.can(c,1)},getPrototypes:function(c,a){var d=[],b=this,e=a?"push":"unshift";for("undefined"==typeof c&&(c=f);(b=Object.getPrototypeOf(b))!=c;)d[e](b);return d},forEach:function(c,a,d,b){"object"!==typeof a&&
"function"!==typeof a?(b=d,d=a,a=this):void 0===a&&(a=this);void 0===d&&(d=!0);if(d)if(b)for(var e in this)this.hasOwnProperty(e)&&c.call(a,this[e],e,this);else for(e in this)c.call(a,this[e],e,this);else for(var d=f.getKeys.call(this,d,b),b=0,g=d.length;b<g;b++)e=d[b],c.call(a,this[e],e,this)},every:function(c,a,d,b){a instanceof Object?void 0===a&&(a=this):(b=d,d=a,a=this);void 0===d&&(d=!0);if(d)if(b)for(var e in this){if(this.hasOwnProperty(e)&&!c.call(a,this[e],e,this))return!1}else for(e in this){if(!c.call(a,
this[e],e,this))return!1}else for(var d=f.getKeys.call(this,d,b),b=0,g=d.length;b<g;b++)if(e=d[b],!c.call(a,this[e],e,this))return!1;return!0},some:function(c,a,d,b){a instanceof Object?void 0===a&&(a=this):(b=d,d=a,a=this);void 0===d&&(d=!0);if(d)if(b)for(var e in this){if(this.hasOwnProperty(e)&&c.call(a,this[e],e,this))return!0}else for(e in this){if(c.call(a,this[e],e,this))return!0}else for(var d=f.getKeys.call(this,d,b),b=0,g=d.length;b<g;b++)if(e=d[b],c.call(a,this[e],e,this))return!0;return!1},
map:function(c,a,d,b,e){var g=f.apply(e||f,"clone");f.forEach.call(this,function(a,b,d){a=c.call(this,a,b,d);"undefined"===typeof a?Object.defineProperty(g,b,{value:void 0}):g[b]=a},a||g,d,b);return g},filter:function(c,a,d,b,e){var g=f.apply(e||f,"clone");f.forEach.call(this,function(a,b,d){c.call(this,a,b,d)||Object.defineProperty(g,b,{value:void 0})},a||g,d,b);return g},getValues:function(c,a){return f.getKeys.apply(this,arguments).map(function(a){return this[a]},this)},setValues:function(c,a,
d){f.getKeys.call(this,a,d).forEach(function(a,d){d in c&&(this[a]=c[d])},this);return this},getKeys:function(c,a){var c=void 0===c||Boolean(c),a=void 0===a||Boolean(a),d=c&&a&&"keys"||!c&&a&&"getOwnPropertyNames";if(d)return Object[d](this);var b=[];!a&&c?f.forEach.call(this,function(a,c){b.push(c)},null,c,a):(b=Object.getOwnPropertyNames(this),f.getPrototypes.call(this).forEach(function(a){b=b.concat(Object.getOwnPropertyNames(a))}));return b},getPrototype:function(){return Object.getPrototypeOf(this)},
getOwnPropertyNames:function(){return Object.getOwnPropertyNames(this)},preventExtensions:function(){return Object.preventExtensions(this)},isExtensible:function(){return Object.isExtensible(this)},seal:function(){"__super__"in this||this.getSuper(!0);return Object.seal(this)},isSealed:function(){return Object.isSealed(this)},freeze:function(){return Object.freeze(this)},isFrozen:function(){return Object.isFrozen(this)},getOwnPropertyDescriptor:function(c){return Object.getOwnPropertyDescriptor(this,
c)},defineProperties:function(c,a){return Object.defineProperties(this,f.describe.apply(this,arguments))},defineProperty:function(c,a){return Object.defineProperty(this,c,a)}},l={prototype:f,constructor:function(c){c&&(this.prototype=c)},extend:function(c,a,d){var b=this.prototype;if(!b.isPrototypeOf(a)){var e=c[0].toUpperCase()+c.substr(1);a.hasOwnProperty("constructor")?a.constructor.typeName=e:a.constructor=e;a=b.clone(a,d)}d=l.create(a);this["$"+c]=a;return this[c]=d},put:function(c,a){function d(a,
b,c){if(!(c in a)||a[c]!==b)return a.extend(c,b)}"string"!=typeof c&&(a=c,c=void 0);if(c){var b=this,e=c.split("."),f=e.pop(),i=a;e.forEach(function(a){if(!(a in b)){i=Object.getPrototypeOf(i);var c=i.constructor.typeName||i.constructor.name;a!==c[0].toLowerCase()+c.substr(1)&&(i={});b.extend(a,i)}b=b[a]});return d(b,a,f)}e=a.getPrototypes();e.push(a);var j=this;e.forEach(function(a){var b=a.constructor.typeName||a.constructor.name;f=b[0].toLowerCase()+b.substr(1);d(j,a,f);j=j[f]});return j}},p={get $object(){f.defineProperties(f);
Object.defineProperty(this,"$object",{value:f});return f},get $namespace(){f=this.$object;l=f.clone(l);Object.defineProperty(this,"$namespace",{value:l});return l},inject:t,get prototype(){return this.$object},extend:l.extend,put:l.put};if("undefined"!=typeof module&&module.exports)module.exports=p;else if(n.requirejs&&"function"==typeof define)define(function(){return p});else{if("clonejs"in n){var s=n.clonejs;s.inject&&t()}if(!s||!1!==s.$object)n.$object=p.$object;n.clonejs=p}})(this);
//@ sourceMappingURL=clone.min.js.map