-
Notifications
You must be signed in to change notification settings - Fork 8
/
helpful.min.js
2 lines (2 loc) · 4.46 KB
/
helpful.min.js
1
2
!function(r,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():r.helpful=t()}("undefined"!=typeof self?self:this,function(){const r={};function e(r,t){return r.repeat(t/r.length)+r.substring(0,t%r.length)}r.stringToArray=function(t){if(null==t)return"";let n=[];for(let r=0;r<t.length;r++)n.push(t[r]);return n},r.duplicateArray=function(t){if(null==t)return[];let n=[];for(let r=0;r<t.length;r++)n.push(t[r]);return n},r.differenceOfArrays=function(r,t){return null==r||null==t?[]:r.filter(r=>!t.includes(r))},r.sumOfArrays=function(t,n){if(null==t||null==n)return[];let e=[];for(let r=0;r<t.length;r++)e.push(t[r]);for(let r=0;r<n.length;r++)e.push(n[r]);return e},r.capitalize=function(r){if(null==r)return"";if("string"!=typeof r)return r;if(1<r.split(" ").length){const e=r.split(" ").reduce((r,t)=>{const[n,...e]=t;return r+=""+n.toUpperCase()+e.join("").toLowerCase()+" "},"");return e.trimEnd()}const[t,...n]=r;return""+t.toUpperCase()+n.join("").toLowerCase()},r.mergeArrays=function(r,t){if(null==r||null==t)return[];const n=r.slice();for(let r=0;r<t.length;r++)n.includes(t[r])||n.push(t[r]);return n},r.average=function(t){if(null==t)return[];let n=0;for(let r=0;r<t.length;r++)n+=t[r];return n/t.length},r.shuffleArray=function(r){if(null==r)return[];let t=[],n=r.slice();for(;n.length;)t.push(...n.splice(Math.floor(Math.random()*n.length),1));return t},r.reverseArray=function(r){if(null==r)return[];let t=[],n=r.slice();for(;n.length;)t.unshift(n.shift());return t},r.pad=function(r,t,n=" "){if(null==r)return"";if(null==t)return r;t-=r.length;return t<=0?r:""+e(n=null==n?" ":n,Math.floor(t/2))+r+e(n,Math.ceil(t/2))},r.padStart=function(r,t,n=" "){if(null==r)return"";if(null==t)return r;t-=r.length;return t<=0?r:""+e(n=null==n?" ":n,t)+r},r.padEnd=function(r,t,n=" "){if(null==r)return"";if(null==t)return r;t-=r.length;return t<=0?r:""+r+e(n=null==n?" ":n,t)},r.chunkArray=function(r,t){if(null==r)return[];if(null==t)return r;const n=[];var e=Math.ceil(r.length/t);let l=0;for(;n.length<e;){var u=l+t;n.push(r.slice(l,u)),l=u}return n},r.fillArray=function(t,n){if(null==t)return[];for(let r=0;r<t.length;r++)t[r]=n;return t},r.flattenArray=function(t){let n=[];for(let r=0;r<t.length;r++){var e=t[r];Array.isArray(e)?n.push(...e):n.push(e)}return n},r.deepFlattenArray=function(t){let n=[];for(let r=0;r<t.length;r++){var e=t[r];Array.isArray(e)?n.push(...this.deepFlattenArray(e)):n.push(e)}return n};function l(r,t){return[].concat.apply([],Array(t).fill(r)).slice(0,t)}r.padArray=function(r,t,n){if(null===r)return[];var e=t-r.length;if(e<=0)return r;t=l(n,Math.floor(e/2)),e=l(n,Math.ceil(e/2));return[...t,...r,...e]},r.padArrayStart=function(r,t,n){if(null===r)return[];t-=r.length;return t<=0?r:[...l(n,t),...r]},r.padArrayEnd=function(r,t,n){if(null===r)return[];t-=r.length;if(t<=0)return r;t=l(n,t);return[...r,...t]};const n=[{character:"&",replacement:"&"},{character:"<",replacement:"<"},{character:">",replacement:">"},{character:'"',replacement:"""},{character:"'",replacement:"'"}];return r.escape=function(r){if(null===r||"string"!=typeof r)return r;let t=r;for(let r=0;r<n.length;r++)t=t.replace(new RegExp(n[r].character,"g"),n[r].replacement);return t},r.unescape=function(r){if(null===r||"string"!=typeof r)return r;let t=r;for(let r=n.length-1;0<=r;r--)t=t.replace(new RegExp(n[r].replacement,"g"),n[r].character);return t},r.mergeObjects=function(t,n){if(null===t)return n;if(null===n)return t;var e=Object.keys(t),l=Object.keys(n);let u={};for(let r=0;r<l.length;r++)u[l[r]]=n[l[r]];for(let r=0;r<e.length;r++)u[e[r]]=t[e[r]];return u},r.partitionArray=function(r,t){return[r.filter(function(r){return t(r)}),r.filter(function(r){return!t(r)})]},r.hex={},r.hex.convertFromString=function(n){if(null==n)return"";let e="";for(let t=0;t<n.length;t++){let r=n.charCodeAt(t).toString(16);for(;r.length<2;)r="0"+r;e+=r}return e},r.hex.convertToString=function(t){if(null==t)return"";let n="";for(let r=0;r<t.length;r+=2)n+=String.fromCharCode(parseInt(t.substring(r,r+2),16));return n},r.hex.convertFromBytes=function(t){if(null==t||!(t instanceof Uint8Array))return"";let n="";for(let r=0;r<t.length;r++)0==t[r].toString(16).length?n+="00":1==t[r].toString(16).length?n+="0"+t[r].toString(16):n+=t[r].toString(16);return n},r.hex.convertToBytes=function(t){if(null==t)return new Uint8Array;let n=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)n[r/2]=parseInt(t.substring(r,r+2),16);return n},r});
//# sourceMappingURL=helpful.min.js.map