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