sk-polyfill
Version:
ShaneKing for Polyfill
3 lines (2 loc) • 4.54 kB
JavaScript
!function(){"use strict";Boolean.isBoolean||(Boolean.isBoolean=function(t){return t===!0||t===!1}),Function.isFunction||(Function.isFunction=function(t){return!!t&&!t.nodeName&&t.constructor!=String&&t.constructor!=RegExp&&t.constructor!=Array&&/function/i.test(t+"")}),Object.isObject||(Object.isObject=function(t){return"object"==typeof t&&t.constructor===Object}),Array.prototype.skArr||Object.defineProperty(Array.prototype,"skArr",{writable:!0,enumerable:!1,configurable:!0,value:function(t,r){var e=[];return this.forEach(function(n){e.push(t&&(Array.isArray(n)||Object.isObject(n))?n.skArr(t,r):n)}),e}}),Array.prototype.skFilter||Object.defineProperty(Array.prototype,"skFilter",{writable:!0,enumerable:!1,configurable:!0,value:function(t,r){var e=[];return this.forEach(function(n,i){Function.isFunction(r)&&r(i,n,this)&&e.push(t&&(Array.isArray(n)||Object.isObject(n))?n.skFilter(t,r):n)}.bind(this)),e}}),Array.prototype.skObj||Object.defineProperty(Array.prototype,"skObj",{writable:!0,enumerable:!1,configurable:!0,value:function(t,r){var e={};return this.forEach(function(n,i){e[Function.isFunction(r)?r(i,n,this):i]=t&&(Array.isArray(n)||Object.isObject(n))?n.skObj(t,r):n}.bind(this)),e}}),Array.prototype.skSomeIn||Object.defineProperty(Array.prototype,"skSomeIn",{writable:!0,enumerable:!1,configurable:!0,value:function(t,r){var e=[];return this.forEach(function(n){t.forEach(function(t){(Function.isFunction(r)?r(n,t):n===t)&&e.push(n)})}),e}}),Array.prototype.skUnique||Object.defineProperty(Array.prototype,"skUnique",{writable:!0,enumerable:!1,configurable:!0,value:function(){var t=[];return this.forEach(function(r){-1===t.indexOf(r)&&t.push(r)}),t}}),Number.prototype.skCurrencyFmt||(Number.prototype.skCurrencyFmt=function(t){return String(this).skCurrencyFmt(t)}),Number.prototype.skIn||(Number.prototype.skIn=function(t){return-1!==t.indexOf(this)}),Object.prototype.skArr||Object.defineProperty(Object.prototype,"skArr",{writable:!0,enumerable:!1,configurable:!0,value:function(t,r){var e=[],n={};return Object.keys(this).forEach(function(i){var o=this[i],c=t&&(Object.isObject(o)||Array.isArray(o))?o.skArr(t,r):o;n[i]=c,Function.isFunction(r)&&r(i,o,this)&&e.push(c)}.bind(this)),Object.keys(n).length===e.length?e:n}}),Object.prototype.skFilter||Object.defineProperty(Object.prototype,"skFilter",{writable:!0,enumerable:!1,configurable:!0,value:function(t,r){var e={};return Object.keys(this).forEach(function(n){var i=this[n];Function.isFunction(r)&&r(n,i,this)&&(e[n]=t&&(Array.isArray(i)||Object.isObject(i))?i.skFilter(t,r):i)}.bind(this)),e}}),Object.prototype.skObj||Object.defineProperty(Object.prototype,"skObj",{writable:!0,enumerable:!1,configurable:!0,value:function(t,r){var e={};return Object.keys(this).forEach(function(n){var i=this[n];e[n]=t&&(Array.isArray(i)||Object.isObject(i))?i.skObj(t,r):i}.bind(this)),e}}),Object.prototype.skVal||Object.defineProperty(Object.prototype,"skVal",{writable:!0,enumerable:!1,configurable:!0,value:function(t,r){var e=this,n=t.split("."),i=0;if(arguments.length>1){for(;i<n.length-1;i++)void 0===e[n[i]]&&(e[n[i]]={}),e=e[n[i]];return e&&(e[n[i]]=r),this}for(;i<n.length&&(e=e[n[i]],void 0!==e);i++);return e}}),Object.prototype.skVals||Object.defineProperty(Object.prototype,"skVals",{writable:!0,enumerable:!1,configurable:!0,value:function(){return Object.keys(this).map(function(t){return this[t]}.bind(this))}}),String.prototype.skBlank||(String.prototype.skBlank=function(){return 0===this.trim().length}),String.prototype.skCurrencyFmt||(String.prototype.skCurrencyFmt=function(t){t=t>0&&20>=t?t:2;var r=(parseFloat(this.replace(/[^\d\.-]/g,"")).toFixed(t)+"").split(".");return r[0].replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,")+"."+r[1]}),String.prototype.skEmpty||(String.prototype.skEmpty=function(){return 0===this.length}),String.prototype.skEndWith||(String.prototype.skEndWith=function(t,r){var e=this.toString();(void 0===r||r>e.length)&&(r=e.length),r-=t.length;var n=e.indexOf(t,r);return-1!==n&&n===r}),String.prototype.skFmt||(String.prototype.skFmt=function(t){return this.replace(/(\$\{\w+(\.\w+)*\})/g,function(r){return t.skVal(r.replace("${","").replace("}",""))})}),String.prototype.skFmtArr||(String.prototype.skFmtArr=function(t){return this.replace(/\$(\d+)/g,function(r,e){return t[--e]})}),String.prototype.skIn||(String.prototype.skIn=function(t){return-1!==t.indexOf(this)}),String.prototype.skStartWith||(String.prototype.skStartWith=function(t){return this.slice(0,t.length)===t})}();
//# sourceMappingURL=sk.polyfill.min.js.map