vue-methodly
Version:
A simple Vue plugin to augment your Vue instance methods with custom ones
50 lines (49 loc) • 12.9 kB
JavaScript
(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):(a=a||self,a.VueMethodly=b())})(this,function(){'use strict';var b=Math.min;function a(a,b){return b={exports:{}},a(b,b.exports),b.exports}var c=function(a){return"object"==typeof a?null!==a:"function"==typeof a},d=function(a){if(!c(a))throw TypeError(a+" is not an object!");return a},e=function(a){try{return!!a()}catch(a){return!0}},g=!e(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a}),h=a(function(a){// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
var b=a.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self// eslint-disable-next-line no-new-func
:Function("return this")();"number"==typeof __g&&(__g=b)}),j=h.document,k=c(j)&&c(j.createElement),l=function(a){return k?j.createElement(a):{}},m=!g&&!e(function(){return 7!=Object.defineProperty(l("div"),"a",{get:function(){return 7}}).a}),n=function(a,b){if(!c(a))return a;var d,e;if(b&&"function"==typeof(d=a.toString)&&!c(e=d.call(a)))return e;if("function"==typeof(d=a.valueOf)&&!c(e=d.call(a)))return e;if(!b&&"function"==typeof(d=a.toString)&&!c(e=d.call(a)))return e;throw TypeError("Can't convert object to primitive value")},o=Object.defineProperty,p=g?Object.defineProperty:function(a,b,c){if(d(a),b=n(b,!0),d(c),m)try{return o(a,b,c)}catch(a){/* empty */}if("get"in c||"set"in c)throw TypeError("Accessors not supported!");return"value"in c&&(a[b]=c.value),a},f={f:p},q=f.f,r=Function.prototype,s=/^\s*function ([^ (]*)/,t="name";t in r||g&&q(r,t,{configurable:!0,get:function(){try{return(""+this).match(s)[1]}catch(a){return""}}});var u=a(function(a){var b=a.exports={version:"2.6.9"};"number"==typeof __e&&(__e=b)}),v=u.version,w=function(a,b){return{enumerable:!(1&a),configurable:!(2&a),writable:!(4&a),value:b}},x=g?function(a,b,c){return f.f(a,b,w(1,c))}:function(a,b,c){return a[b]=c,a},y={}.hasOwnProperty,z=function(a,b){return y.call(a,b)},A=0,B=Math.random(),C=function(a){return"Symbol(".concat(a===void 0?"":a,")_",(++A+B).toString(36))},D=a(function(a){var b=h["__core-js_shared__"]||(h["__core-js_shared__"]={});(a.exports=function(a,c){return b[a]||(b[a]=c===void 0?{}:c)})("versions",[]).push({version:u.version,mode:"global",copyright:"\xA9 2019 Denis Pushkarev (zloirock.ru)"})}),E=D("native-function-to-string",Function.toString),F=a(function(a){var b=C("src"),c="toString",d=(""+E).split(c);u.inspectSource=function(a){return E.call(a)},(a.exports=function(a,c,e,f){var g="function"==typeof e;g&&(z(e,"name")||x(e,"name",c));a[c]===e||(g&&(z(e,b)||x(e,b,a[c]?""+a[c]:d.join(c+""))),a===h?a[c]=e:f?a[c]?a[c]=e:x(a,c,e):(delete a[c],x(a,c,e)))})(Function.prototype,c,function(){return"function"==typeof this&&this[b]||E.call(this)})}),G=function(a){if("function"!=typeof a)throw TypeError(a+" is not a function!");return a},H=function(d,e,f){return(G(d),void 0===e)?d:1===f?function(b){return d.call(e,b)}:2===f?function(c,a){return d.call(e,c,a)}:3===f?function(f,a,b){return d.call(e,f,a,b)}:function()/* ...args */{return d.apply(e,arguments)}},I="prototype",J=function(a,b,c){var d,e,f,g,i=a&J.F,j=a&J.G,k=a&J.S,l=a&J.P,m=a&J.B,n=j?h:k?h[b]||(h[b]={}):(h[b]||{})[I],o=j?u:u[b]||(u[b]={}),p=o[I]||(o[I]={});for(d in j&&(c=b),c)// contains in native
// export native or passed
// bind timers to global for call from export context
e=!i&&n&&void 0!==n[d],f=(e?n:c)[d],g=m&&e?H(f,h):l&&"function"==typeof f?H(Function.call,f):f,n&&F(n,d,f,a&J.U),o[d]!=f&&x(o,d,g),l&&p[d]!=f&&(p[d]=f)};h.core=u,J.F=1,J.G=2,J.S=4,J.P=8,J.B=16,J.W=32,J.U=64,J.R=128;// real proto method for `library`
var K=J,L=function(a){if(a==null)throw TypeError("Can't call method on "+a);return a},M=function(a){return Object(L(a))},N={}.toString,P=function(a){return N.call(a).slice(8,-1)},Q=Object("z").propertyIsEnumerable(0)?Object:function(a){return"String"==P(a)?a.split(""):Object(a)},R=Math.ceil,S=Math.floor,T=function(a){return isNaN(a=+a)?0:(0<a?S:R)(a)},U=function(a){return 0<a?b(T(a),9007199254740991):0;// pow(2, 53) - 1 == 9007199254740991
},V=function(a,b,c,d,e){G(b);var f=M(a),g=Q(f),h=U(f.length),j=e?h-1:0,k=e?-1:1;if(2>c)for(;;){if(j in g){d=g[j],j+=k;break}if(j+=k,e?0>j:h<=j)throw TypeError("Reduce of empty array with no initial value")}for(;e?0<=j:h>j;j+=k)j in g&&(d=b(d,g[j],j,f));return d},W=function(a,b){return!!a&&e(function(){// eslint-disable-next-line no-useless-call
b?a.call(null,function(){/* empty */},1):a.call(null)})};// 7.2.1 RequireObjectCoercible(argument)
K(K.P+K.F*!W([].reduce,!0),"Array",{// 22.1.3.18 / 15.4.4.21 Array.prototype.reduce(callbackfn [, initialValue])
reduce:function(a/* , initialValue */){return V(this,a,arguments.length,arguments[1],!1)}});// to indexed object, toObject with fallback for non-array-like ES3 strings
var X=function(a){return Q(L(a))},Y=Math.max,Z=function(a,c){return a=T(a),0>a?Y(a+c,0):b(a,c)},$=function(a){return function(b,c,d){var e,f=X(b),g=U(f.length),h=Z(d,g);// Array#includes uses SameValueZero equality algorithm
// eslint-disable-next-line no-self-compare
if(a&&c!=c){for(;g>h;)// eslint-disable-next-line no-self-compare
if(e=f[h++],e!=e)return!0;// Array#indexOf ignores holes, Array#includes - not
}else for(;g>h;h++)if((a||h in f)&&f[h]===c)return a||h||0;return!a&&-1}},_=a(function(a){var b=D("wks"),c=h.Symbol,d="function"==typeof c,e=a.exports=function(a){return b[a]||(b[a]=d&&c[a]||(d?c:C)("Symbol."+a))};e.store=b}),aa=_("unscopables"),ba=Array.prototype;ba[aa]==null&&x(ba,aa,{});var ca=function(a){ba[aa][a]=!0},da=$(!0);// https://github.com/tc39/Array.prototype.includes
K(K.P,"Array",{includes:function(a/* , fromIndex = 0 */){return da(this,a,1<arguments.length?arguments[1]:void 0)}}),ca("includes");// 7.2.8 IsRegExp(argument)
var ea=_("match"),fa=function(a){var b;return c(a)&&((b=a[ea])===void 0?"RegExp"==P(a):!!b)},ga=function(a,b,c){if(fa(b))throw TypeError("String#"+c+" doesn't accept regex!");return L(a)+""},ha=_("match"),ia="includes";K(K.P+K.F*function(a){var b=/./;try{"/./"[a](b)}catch(c){try{return b[ha]=!1,!"/./"[a](b)}catch(a){/* empty */}}return!0}(ia),"String",{includes:function(a/* , position = 0 */){return!!~ga(this,a,ia).indexOf(a,1<arguments.length?arguments[1]:void 0)}});// 7.2.2 IsArray(argument)
var ja=Array.isArray||function(a){return"Array"==P(a)},ka=_("species"),la=function(a){var b;return ja(a)&&(b=a.constructor,"function"==typeof b&&(b===Array||ja(b.prototype))&&(b=void 0),c(b)&&(b=b[ka],null===b&&(b=void 0))),void 0===b?Array:b},ma=function(a,b){return new(la(a))(b)},na=function(a,b){var c=1==a,d=4==a,e=6==a,g=b||ma;return function(b,h,i){for(var j,k,l=M(b),m=Q(l),n=H(h,i,3),f=U(m.length),o=0,p=c?g(b,f):2==a?g(b,0):void 0;f>o;o++)if((5==a||e||o in m)&&(j=m[o],k=n(j,o,l),a))if(c)p[o]=k;// map
else if(k)switch(a){case 3:return!0;// some
case 5:return j;// find
case 6:return o;// findIndex
case 2:p.push(j);// filter
}else if(d)return!1;// every
return e?-1:3==a||d?d:p}},oa=na(0),pa=W([].forEach,!0);K(K.P+K.F*!pa,"Array",{// 22.1.3.10 / 15.4.4.18 Array.prototype.forEach(callbackfn [, thisArg])
forEach:function(a/* , thisArg */){return oa(this,a,arguments[1])}});var qa=na(2);K(K.P+K.F*!W([].filter,!0),"Array",{// 22.1.3.7 / 15.4.4.20 Array.prototype.filter(callbackfn [, thisArg])
filter:function(a/* , thisArg */){return qa(this,a,arguments[1])}});var ra=function(a,b){return{value:b,done:!!a}},sa={},ta=D("keys"),ua=function(a){return ta[a]||(ta[a]=C(a))},va=$(!1),wa=ua("IE_PROTO"),xa=function(a,b){var c,d=X(a),e=0,f=[];for(c in d)c!=wa&&z(d,c)&&f.push(c);// Don't enum bug & hidden keys
for(;b.length>e;)z(d,c=b[e++])&&(~va(f,c)||f.push(c));return f},ya=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],za=Object.keys||function(a){return xa(a,ya)},Aa=g?Object.defineProperties:function(a,b){d(a);for(var c,e=za(b),g=e.length,h=0;g>h;)f.f(a,c=e[h++],b[c]);return a},Ba=h.document,Ca=Ba&&Ba.documentElement,Da=ua("IE_PROTO"),Ea=function(){/* empty */},Fa="prototype",Ga=function(){// Thrash, waste and sodomy: IE GC bug
var a,b=l("iframe"),c=ya.length,d="<",e=">";for(b.style.display="none",Ca.appendChild(b),b.src="javascript:",a=b.contentWindow.document,a.open(),a.write(d+"script"+e+"document.F=Object"+d+"/script"+e),a.close(),Ga=a.F;c--;)delete Ga[Fa][ya[c]];return Ga()},Ha=Object.create||function(a,b){var c;return null===a?c=Ga():(Ea[Fa]=d(a),c=new Ea,Ea[Fa]=null,c[Da]=a),void 0===b?c:Aa(c,b)},Ia=f.f,Ja=_("toStringTag"),Ka=function(a,b,c){a&&!z(a=c?a:a.prototype,Ja)&&Ia(a,Ja,{configurable:!0,value:b})},La={};x(La,_("iterator"),function(){return this});var Ma=function(a,b,c){a.prototype=Ha(La,{next:w(1,c)}),Ka(a,b+" Iterator")},Na=ua("IE_PROTO"),Oa=Object.prototype,Pa=Object.getPrototypeOf||function(a){return a=M(a),z(a,Na)?a[Na]:"function"==typeof a.constructor&&a instanceof a.constructor?a.constructor.prototype:a instanceof Object?Oa:null},Qa=_("iterator"),Ra=!([].keys&&"next"in[].keys()),Sa="keys",Ta="values",Ua=function(){return this},Va=function(a,b,c,d,e,f,g){Ma(c,b,d);var h,i,j,k=function(a){return!Ra&&a in o?o[a]:a===Sa?function(){return new c(this,a)}:a===Ta?function(){return new c(this,a)}:function(){return new c(this,a)}},l=b+" Iterator",m=e==Ta,n=!1,o=a.prototype,p=o[Qa]||o["@@iterator"]||e&&o[e],q=p||k(e),r=e?m?k("entries"):q:void 0,s="Array"==b?o.entries||p:p;if(s&&(j=Pa(s.call(new a)),j!==Object.prototype&&j.next&&(Ka(j,l,!0),"function"!=typeof j[Qa]&&x(j,Qa,Ua))),m&&p&&p.name!==Ta&&(n=!0,q=function(){return p.call(this)}),(Ra||n||!o[Qa])&&x(o,Qa,q),sa[b]=q,sa[l]=Ua,e)if(h={values:m?q:k(Ta),keys:f?q:k(Sa),entries:r},g)for(i in h)i in o||F(o,i,h[i]);else K(K.P+K.F*(Ra||n),b,h);return h},Wa=Va(Array,"Array",function(a,b){// target
// next index
this._t=X(a),this._i=0,this._k=b},function(){var a=this._t,b=this._k,c=this._i++;return!a||c>=a.length?(this._t=void 0,ra(1)):"keys"==b?ra(0,c):"values"==b?ra(0,a[c]):ra(0,[c,a[c]])},"values");// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
sa.Arguments=sa.Array,ca("keys"),ca("values"),ca("entries");for(var Xa=_("iterator"),Ya=_("toStringTag"),Za=sa.Array,$a={CSSRuleList:!0,// TODO: Not spec compliant, should be false.
CSSStyleDeclaration:!1,CSSValueList:!1,ClientRectList:!1,DOMRectList:!1,DOMStringList:!1,DOMTokenList:!0,DataTransferItemList:!1,FileList:!1,HTMLAllCollection:!1,HTMLCollection:!1,HTMLFormElement:!1,HTMLSelectElement:!1,MediaList:!0,// TODO: Not spec compliant, should be false.
MimeTypeArray:!1,NamedNodeMap:!1,NodeList:!0,PaintRequestList:!1,Plugin:!1,PluginArray:!1,SVGLengthList:!1,SVGNumberList:!1,SVGPathSegList:!1,SVGPointList:!1,SVGStringList:!1,SVGTransformList:!1,SourceBufferList:!1,StyleSheetList:!0,// TODO: Not spec compliant, should be false.
TextTrackCueList:!1,TextTrackList:!1,TouchList:!1},_a=za($a),ab=0;ab<_a.length;ab++){var O,bb=_a[ab],cb=$a[bb],db=h[bb],eb=db&&db.prototype;if(eb&&(eb[Xa]||x(eb,Xa,Za),eb[Ya]||x(eb,Ya,bb),sa[bb]=Za,cb))for(O in Wa)eb[O]||F(eb,O,Wa[O],!0)}// getting tag from 19.1.3.6 Object.prototype.toString()
var fb=_("toStringTag"),gb="Arguments"==P(function(){return arguments}()),hb=function(a,b){try{return a[b]}catch(a){/* empty */}},ib=function(a){var b,c,d;return a===void 0?"Undefined":null===a?"Null"// @@toStringTag case
:"string"==typeof(c=hb(b=Object(a),fb))?c// builtinTag case
:gb?P(b)// ES3 arguments fallback
:"Object"==(d=P(b))&&"function"==typeof b.callee?"Arguments":d},jb={};// ES3 wrong here
jb[_("toStringTag")]="z","[object z]"!=jb+""&&F(Object.prototype,"toString",function(){return"[object "+ib(this)+"]"},!0);(function(a,b){var c=(u.Object||{})[a]||Object[a],d={};d[a]=b(c),K(K.S+K.F*e(function(){c(1)}),"Object",d)})("keys",function(){return function(a){return za(M(a))}});var kb=na(1);K(K.P+K.F*!W([].map,!0),"Array",{// 22.1.3.15 / 15.4.4.19 Array.prototype.map(callbackfn [, thisArg])
map:function(a/* , thisArg */){return kb(this,a,arguments[1])}}),K(K.S,"Array",{isArray:ja});return{install:function(a,b){// initial hooks
var c={beforeCreate:[],created:[],beforeMount:[],mounted:[],update:[],activated:[],deactivated:[],beforeDestroy:[],destroyed:[]// boolean helper
},d=Array.isArray(b.methods);// bail if nothing to do
if(d){Object.keys(c).map(function(a){// grab methods for this hook
var d=b.methods.filter(function(b){return b.hook===a});// add each one, so long as name does not collide with any native hooks
d.forEach(function(b){Object.keys(c).includes(d)||c[a].push(b)})});// reduce into only hooks which have methods
var e=Object.keys(c).reduce(function(a,b){return c[b].length&&(!a[b]&&(a[b]=[]),a[b].push(c[b])),a},{}),f={};// base mixin
Object.keys(e).forEach(function(a){f[a]=function(){var b=this;e[a].forEach(function(a){a.forEach(function(a){var c=b.$options[a.name]||!1;c&&c.call(b)})})}}),a.mixin(f)}// add methods to hooks
}}});