kyouka 1.3.7 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  <p>My Typescript helper function library.</p>
5
5
  </div>
6
6
  <p>
7
- <img alt="Version" src="https://img.shields.io/badge/version-1.3.6-blue.svg?cacheSeconds=2592000" />
7
+ <img alt="Version" src="https://img.shields.io/npm/v/kyouka" />
8
8
  <a href="https://github.com/alphardex/kyouka/blob/master/LICENSE" target="_blank">
9
9
  <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
10
10
  </a>
@@ -21,6 +21,15 @@
21
21
  npm i kyouka
22
22
  ```
23
23
 
24
+ ## Usage
25
+
26
+ ```js
27
+ import ky from "kyouka";
28
+
29
+ console.log(ky.isEmpty({}));
30
+ // true
31
+ ```
32
+
24
33
  ## Author
25
34
 
26
35
  👤 **alphardex**
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).kyouka=t()}(this,(function(){"use strict";const e=(t,n=t.length,...r)=>n<=r.length?t(...r):e.bind(null,t,n,...r),t=e=>{if(null===e)return null;let n=Object.assign({},e);return Object.keys(n).forEach((r=>n[r]="object"==typeof e[r]?t(e[r]):e[r])),Array.isArray(e)&&e.length?(n.length=e.length)&&Array.from(n):Array.isArray(e)?Array.from(e):n},n=e=>180*e/Math.PI,r=()=>/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?"Mobile":"Desktop",o=e=>{e.preventDefault()},i=(e,t)=>{if(e===t)return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(!e||!t||"object"!=typeof e&&"object"!=typeof t)return e===t;if(e.prototype!==t.prototype)return!1;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every((n=>i(e[n],t[n])))},a=e=>e<0?(()=>{throw new TypeError("Negative numbers are not allowed!")})():e<=1?1:e*a(e-1),l=e=>e/window.innerWidth*100,s=(e=null,t="px")=>{const n={x:void 0!==(e=e||window).pageXOffset?e.pageXOffset:e.scrollLeft,y:void 0!==e.pageYOffset?e.pageYOffset:e.scrollTop};return"vw"===t&&(n.x=l(n.x),n.y=l(n.y)),n},c=(e,t)=>{const n=new FileReader;n.readAsDataURL(e),n.addEventListener("load",(()=>{const e=n.result;t(e)}))},d={getCenterPointPos:e=>{const t=e.getBoundingClientRect();return{x:t.left+t.width/2,y:t.top+t.height/2}},getMousePos:e=>({x:e.clientX,y:e.clientY}),getTimeFromDate:e=>e.toTimeString().slice(0,8).split(":").join(""),randomIntArrayInRange:(e,t,n=1)=>Array.from({length:n},(()=>Math.floor(Math.random()*(t-e+1))+e)),randomNumberInRange:(e,t)=>Math.random()*(t-e)+e,randomIntegerInRange:(e,t)=>Math.floor(Math.random()*(t-e+1))+e,requestInterval:(e,t)=>{let n=(new Date).getTime(),r={value:0},o=()=>{r.value=requestAnimationFrame(o),(new Date).getTime()-n>=t&&(e(),n=(new Date).getTime())};return r.value=requestAnimationFrame(o),r},sample:e=>e[Math.floor(Math.random()*e.length)],shuffle:([...e])=>{let t=e.length;for(;t;){const n=Math.floor(Math.random()*t--);[e[t],e[n]]=[e[n],e[t]]}return e},sleep:e=>new Promise((t=>setTimeout(t,e))),vw2px:e=>e*Math.min(window.innerWidth,document.documentElement.clientWidth)/100,sum:(...e)=>[...e].reduce(((e,t)=>e+t),0),formatDuration:e=>{e<0&&(e=-e);return{day:Math.floor(e/864e5),hour:Math.floor(e/36e5)%24,minute:Math.floor(e/6e4)%60,second:Math.floor(e/1e3)%60,millisecond:Math.floor(e)%1e3}},getTimeDeltaAsSeconds:(e,t)=>{const n=e instanceof Date?e.getTime():e,r=(t instanceof Date?t.getTime():t)-n;return Math.floor(r)},isPhoneNumber:e=>/^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(e),isBottomVisible:(e=0)=>window.innerHeight+window.scrollY>=document.body.offsetHeight-e,getURLParameters:e=>(e.match(/([^?=&]+)(=([^&]*))/g)||[]).reduce(((e,t)=>(e[t.slice(0,t.indexOf("="))]=t.slice(t.indexOf("=")+1),e)),{}),average:(...e)=>e.reduce(((e,t)=>e+t),0)/e.length,previewImage:(e,t,n)=>{e.addEventListener("change",(e=>{const r=e.target.files,o=r?r[0]:null;c(o,(e=>{e&&(t.src=e,n(e))}))}))},getScrollPosition:s,getScrollPositionAsVw:(e=null)=>s(e,"vw"),px2vw:l,initialize2DArray:(e,t,n=null)=>Array.from({length:t}).map((()=>Array.from({length:e}).fill(n))),deepClone:t,initializeArrayWithValues:(e,t=0)=>Array(e).fill(t),CSVToArray:(e,t=",",n=!1)=>e.slice(n?e.indexOf("\n")+1:0).split("\n").map((e=>e.split(t))),arrayToCSV:(e,t=",")=>e.map((e=>e.map((e=>isNaN(e)?`"${e.replace(/"/g,'""')}"`:e)).join(t))).join("\n"),JSONToCSV:(e,t,n=",")=>[t.join(n),...e.map((e=>t.reduce(((t,r)=>`${t}${t.length?n:""}"${e[r]?e[r]:""}"`),"")))].join("\n"),CSVToJSON:(e,t=",")=>{const n=e.slice(0,e.indexOf("\n")).split(t);return e.slice(e.indexOf("\n")+1).split("\n").map((e=>{const r=e.split(t);return n.reduce(((e,t,n)=>(e[t]=r[n],e)),{})}))},uniq:e=>[...new Set(e)],omit:(e,t)=>Object.keys(e).filter((e=>!t.includes(e))).reduce(((t,n)=>(t[n]=e[n],t)),{}),pick:(e,t)=>t.reduce(((t,n)=>(n in e&&(t[n]=e[n]),t)),{}),iosInputScrollFix:()=>{"Mobile"===r()&&document.querySelectorAll("input, select, textarea").forEach((e=>{e.addEventListener("blur",(()=>{window.scrollBy(0,-1)}))}))},mapObject:(e,t)=>e.reduce(((n,r,o)=>(n[r]=t(r,o,e),n)),{}),mapKeys:(e,t)=>Object.keys(e).reduce(((n,r)=>(n[t(e[r],r,e)]=e[r],n)),{}),mapValues:(e,t)=>Object.keys(e).reduce(((n,r)=>(n[r]=t(e[r],r,e),n)),{}),isEmpty:e=>null==e||!(Object.keys(e)||e).length,debounce:(e,t=0)=>{let n;return function(...r){clearTimeout(n),n=setTimeout((()=>e.apply(this,r)),t)}},throttle:(e,t)=>{let n,r,o;return function(){const i=this,a=arguments;n?(clearTimeout(r),r=setTimeout((function(){Date.now()-o>=t&&(e.apply(i,a),o=Date.now())}),Math.max(t-(Date.now()-o),0))):(e.apply(i,a),o=Date.now(),n=!0)}},partial:(e,...t)=>(...n)=>e(...t,...n),compose:(...e)=>e.reduce(((e,t)=>(...n)=>e(t(...n)))),curry:e,memorize:e=>{const t=new Map,n=function(n){return(t.has(n)||t.set(n,e.call(this,n)))&&t.get(n)};return n.cache=t,n},attempt:(e,...t)=>{try{return e(...t)}catch(e){return e instanceof Error?e:new Error(e)}},compact:e=>e.filter(Boolean),promisify:e=>(...t)=>new Promise(((n,r)=>e(...t,((e,t)=>e?r(e):n(t))))),distance:(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),zip:(...e)=>{const t=Math.max(...e.map((e=>e.length)));return Array.from({length:t}).map(((t,n)=>Array.from({length:e.length},((t,r)=>e[r][n]))))},range:function*(e,t,n=1){let r=e;for(;r<t;)yield r,r+=n},unzip:e=>e.reduce(((e,t)=>(t.forEach(((t,n)=>e[n].push(t))),e)),Array.from({length:Math.max(...e.map((e=>e.length)))}).map((e=>[]))),union:(e,t)=>Array.from(new Set([...e,...t])),pluck:(e,t)=>e.map((e=>e[t])),mask:(e,t=4,n="*")=>`${e}`.slice(-t).padStart(`${e}`.length,n),intersection:(e,t)=>{const n=new Set(t);return[...new Set(e)].filter((e=>n.has(e)))},animateNumber:(e,t,n,r)=>{let o=null,i=a=>{o=o||a;let l=a-o,s=Math.min(l/r,1);e(t+s*(n-t)),s<1&&window.requestAnimationFrame(i)};window.requestAnimationFrame(i)},detectDeviceType:r,deg2rad:e=>e*Math.PI/180,factorial:a,equals:i,includesAll:(e,t)=>t.every((t=>e.includes(t))),includesAny:(e,t)=>t.some((t=>e.includes(t))),rad2deg:n,randomHexColorCode:()=>"#"+(1048575*Math.random()*1e6).toString(16).slice(0,6),timeTaken:e=>{console.time("timeTaken");const t=e();return console.timeEnd("timeTaken"),t},sumPower:(e,t=2,n=1)=>Array(e+1-n).fill(0).map(((e,r)=>(r+n)**t)).reduce(((e,t)=>e+t),0),reverseString:e=>[...e].reverse().join(""),vh2px:e=>e*Math.min(window.innerHeight,document.documentElement.clientHeight)/100,px2vh:e=>e/window.innerHeight*100,loadImageAsBase64URL:c,sampleSize:([...e],t=1)=>{let n=e.length;for(;n;){const t=Math.floor(Math.random()*n--);[e[n],e[t]]=[e[t],e[n]]}return e.slice(0,t)},fromTimestamp:e=>new Date(1e3*e),getTimestamp:(e=new Date,t=!1)=>{const n=e.getTime()/1e3;return t?Math.floor(n):n},isOdd:e=>e%2==1,isEven:e=>e%2==0,copyToClipboard:e=>{const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t);const n=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),n&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(n))},yesNo:(e,t=!1)=>!!/^(y|yes)$/i.test(e)||!/^(n|no)$/i.test(e)&&t,loadVideoAsBlob:(e,t,n="mp4")=>{const r=new FileReader;r.readAsArrayBuffer(e),r.addEventListener("load",(()=>{const e=r.result,o=new Blob([new Uint8Array(e)],{type:`video/${n}`});t(o)}))},maxN:(e,t=1)=>[...e].sort(((e,t)=>t-e)).slice(0,t),minN:(e,t=1)=>[...e].sort(((e,t)=>e-t)).slice(0,t),padNumber:(e,t)=>`${e}`.padStart(t,"0"),addHoursToDate:(e,t)=>(e.setTime(e.getTime()+60*t*60*1e3),e),addMinutesToDate:(e,t)=>(e.setTime(e.getTime()+60*t*1e3),e),addSecondsToDate:(e,t)=>(e.setTime(e.getTime()+1e3*t),e),chunk:(e,t)=>Array.from({length:Math.ceil(e.length/t)},((n,r)=>e.slice(r*t,r*t+t))),isUrl:e=>/^http(s)?/.test(e),objectMap:(e,t)=>Object.fromEntries(Object.entries(e).map((([e,n],r)=>[e,t(n,e,r)]))),orderBy:(e,t,n)=>[...e].sort(((e,r)=>t.reduce(((t,o,i)=>{if(0===t){const[a,l]=n&&"desc"===n[i]?[r[o],e[o]]:[e[o],r[o]];t=a>l?1:a<l?-1:0}return t}),0))),head:e=>e&&e.length?e[0]:void 0,last:e=>e&&e.length?e[e.length-1]:void 0,objectToQueryString:e=>e?Object.entries(e).reduce(((e,[t,n])=>{const r=0===e.length?"?":"&";return e+="string"==typeof n?`${r}${t}=${n}`:""}),""):"",clamp:(e,t,n)=>Math.max(Math.min(Number(e),Math.max(t,n)),Math.min(t,n)),isElBottomVisible:(e,t=0)=>e.offsetHeight+e.scrollTop>=e.scrollHeight-t,isIdcard:e=>/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0[1-9]|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/.test(e),lerp:(e,t,n)=>e+(t-e)*n,maxBy:(e,t)=>Math.max(...e.map("function"==typeof t?t:e=>e[t])),minBy:(e,t)=>Math.min(...e.map("function"==typeof t?t:e=>e[t])),reload:()=>location.reload(),repeatArray:(e,t)=>[].concat(...Array(t).fill(e)),degreesAngle:(e,t)=>n(Math.atan2(t.y-e.y,t.x-e.x)),radiansAngle:(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),addDaysToDate:(e,t)=>(e.setTime(e.getTime()+60*t*60*1e3*24),e),addWeeksToDate:(e,t)=>(e.setTime(e.getTime()+60*t*60*1e3*24*7),e),groupBy:(e,t)=>e.map("function"==typeof t?t:e=>e[t]).reduce(((t,n,r)=>(t[n]=(t[n]||[]).concat(e[r]),t)),{}),chunkMultiSize:(e,t)=>{const n=[];let r=0,o=0;for(;o<e.length;){const i=t[r];n.push(e.slice(o,o+i)),r=(r+1)%t.length,o+=i}return n},disableTouchMove:()=>{document.body.addEventListener("touchmove",o,{passive:!1})},enableTouchMove:()=>{document.body.removeEventListener("touchmove",o)},getNormalizedMousePos:e=>({x:e.clientX/window.innerWidth*2-1,y:-e.clientY/window.innerHeight*2+1}),dataURItoFile:(e,t="1.jpg")=>{let n=e.split(",")[0].split(":")[1].split(";")[0],r=atob(e.split(",")[1]),o=new ArrayBuffer(r.length),i=new Uint8Array(o);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return new File([i],t,{type:n})},dateRange:function*(e,t,n=1){let r=e;for(;r<t;)yield new Date(r),r.setDate(r.getDate()+n)},frequencies:e=>e.reduce(((e,t)=>(e[t]=e[t]?e[t]+1:1,e)),{}),countOccurrences:(e,t)=>e.reduce(((e,n)=>n===t?e+1:e),0),loopSlice:(e,t,n)=>{const[r,o]=[t,n];return o>=r?e.slice(r,o):[...e.slice(r,e.length),...e.slice(0,o)]},castArray:e=>Array.isArray(e)?e:[e],compatibleDate:e=>e.replace(/\.|\-/g,"/"),toHttps:e=>e.replace(/^http:/,"https:"),cleanObject:e=>(Object.keys(e).forEach((t=>{e[t]||delete e[t]})),e),isToday:e=>{const t=new Date;return e.getDate()==t.getDate()&&e.getMonth()==t.getMonth()&&e.getFullYear()==t.getFullYear()},isNumber:e=>"number"==typeof e&&e==e,isNumeric:e=>!isNaN(e),isObject:e=>e===Object(e),convertLetterToNumber:e=>{e=e.toUpperCase();const t="A".charCodeAt(0);return e.charCodeAt(0)-t},convertNumberToLetter:e=>{const t=e+"A".charCodeAt(0);return String.fromCharCode(t)},toFixed0:e=>Number(e).toFixed(0),toFixed1:e=>Number(e).toFixed(1),toFixed2:e=>Number(e).toFixed(2)};return d}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).kyouka=t()}(this,(function(){"use strict";const e=(t,n=t.length,...r)=>n<=r.length?t(...r):e.bind(null,t,n,...r),t=e=>{if(null===e)return null;let n=Object.assign({},e);return Object.keys(n).forEach((r=>n[r]="object"==typeof e[r]?t(e[r]):e[r])),Array.isArray(e)&&e.length?(n.length=e.length)&&Array.from(n):Array.isArray(e)?Array.from(e):n},n=e=>180*e/Math.PI,r=()=>/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?"Mobile":"Desktop",o=e=>{e.preventDefault()},a=(e,t)=>{if(e===t)return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(!e||!t||"object"!=typeof e&&"object"!=typeof t)return e===t;if(e.prototype!==t.prototype)return!1;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every((n=>a(e[n],t[n])))},i=e=>e<0?(()=>{throw new TypeError("Negative numbers are not allowed!")})():e<=1?1:e*i(e-1),l=e=>e/window.innerWidth*100,s=(e=null,t="px")=>{const n={x:void 0!==(e=e||window).pageXOffset?e.pageXOffset:e.scrollLeft,y:void 0!==e.pageYOffset?e.pageYOffset:e.scrollTop};return"vw"===t&&(n.x=l(n.x),n.y=l(n.y)),n},c=(e,t)=>{const n=new FileReader;n.readAsDataURL(e),n.addEventListener("load",(()=>{const e=n.result;t(e)}))},d={getCenterPointPos:e=>{const t=e.getBoundingClientRect();return{x:t.left+t.width/2,y:t.top+t.height/2}},getMousePos:e=>({x:e.clientX,y:e.clientY}),getTimeFromDate:e=>e.toTimeString().slice(0,8).split(":").join(""),randomIntArrayInRange:(e,t,n=1)=>Array.from({length:n},(()=>Math.floor(Math.random()*(t-e+1))+e)),randomNumberInRange:(e,t)=>Math.random()*(t-e)+e,randomIntegerInRange:(e,t)=>Math.floor(Math.random()*(t-e+1))+e,requestInterval:(e,t)=>{let n=(new Date).getTime(),r={value:0},o=()=>{r.value=requestAnimationFrame(o),(new Date).getTime()-n>=t&&(e(),n=(new Date).getTime())};return r.value=requestAnimationFrame(o),r},sample:e=>e[Math.floor(Math.random()*e.length)],shuffle:([...e])=>{let t=e.length;for(;t;){const n=Math.floor(Math.random()*t--);[e[t],e[n]]=[e[n],e[t]]}return e},sleep:e=>new Promise((t=>setTimeout(t,e))),vw2px:e=>e*Math.min(window.innerWidth,document.documentElement.clientWidth)/100,sum:(...e)=>[...e].reduce(((e,t)=>e+t),0),formatDuration:e=>{e<0&&(e=-e);return{day:Math.floor(e/864e5),hour:Math.floor(e/36e5)%24,minute:Math.floor(e/6e4)%60,second:Math.floor(e/1e3)%60,millisecond:Math.floor(e)%1e3}},getTimeDeltaAsSeconds:(e,t)=>{const n=e instanceof Date?e.getTime():e,r=(t instanceof Date?t.getTime():t)-n;return Math.floor(r)},isPhoneNumber:e=>/^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(e),isBottomVisible:(e=0)=>window.innerHeight+window.scrollY>=document.body.offsetHeight-e,getURLParameters:e=>(e.match(/([^?=&]+)(=([^&]*))/g)||[]).reduce(((e,t)=>(e[t.slice(0,t.indexOf("="))]=t.slice(t.indexOf("=")+1),e)),{}),average:(...e)=>e.reduce(((e,t)=>e+t),0)/e.length,previewImage:(e,t,n)=>{e.addEventListener("change",(e=>{const r=e.target.files,o=r?r[0]:null;c(o,(e=>{e&&(t.src=e,n(e))}))}))},getScrollPosition:s,getScrollPositionAsVw:(e=null)=>s(e,"vw"),px2vw:l,initialize2DArray:(e,t,n=null)=>Array.from({length:t}).map((()=>Array.from({length:e}).fill(n))),deepClone:t,initializeArrayWithValues:(e,t=0)=>Array(e).fill(t),CSVToArray:(e,t=",",n=!1)=>e.slice(n?e.indexOf("\n")+1:0).split("\n").map((e=>e.split(t))),arrayToCSV:(e,t=",")=>e.map((e=>e.map((e=>isNaN(e)?`"${e.replace(/"/g,'""')}"`:e)).join(t))).join("\n"),JSONToCSV:(e,t,n=",")=>[t.join(n),...e.map((e=>t.reduce(((t,r)=>`${t}${t.length?n:""}"${e[r]?e[r]:""}"`),"")))].join("\n"),CSVToJSON:(e,t=",")=>{const n=e.slice(0,e.indexOf("\n")).split(t);return e.slice(e.indexOf("\n")+1).split("\n").map((e=>{const r=e.split(t);return n.reduce(((e,t,n)=>(e[t]=r[n],e)),{})}))},uniq:e=>[...new Set(e)],omit:(e,t)=>Object.keys(e).filter((e=>!t.includes(e))).reduce(((t,n)=>(t[n]=e[n],t)),{}),pick:(e,t)=>t.reduce(((t,n)=>(n in e&&(t[n]=e[n]),t)),{}),iosInputScrollFix:()=>{"Mobile"===r()&&document.querySelectorAll("input, select, textarea").forEach((e=>{e.addEventListener("blur",(()=>{window.scrollBy(0,-1)}))}))},mapObject:(e,t)=>e.reduce(((n,r,o)=>(n[r]=t(r,o,e),n)),{}),mapKeys:(e,t)=>Object.keys(e).reduce(((n,r)=>(n[t(e[r],r,e)]=e[r],n)),{}),mapValues:(e,t)=>Object.keys(e).reduce(((n,r)=>(n[r]=t(e[r],r,e),n)),{}),isEmpty:e=>null==e||!(Object.keys(e)||e).length,debounce:(e,t=0)=>{let n;return function(...r){clearTimeout(n),n=setTimeout((()=>e.apply(this,r)),t)}},throttle:(e,t)=>{let n,r,o;return function(){const a=this,i=arguments;n?(clearTimeout(r),r=setTimeout((function(){Date.now()-o>=t&&(e.apply(a,i),o=Date.now())}),Math.max(t-(Date.now()-o),0))):(e.apply(a,i),o=Date.now(),n=!0)}},partial:(e,...t)=>(...n)=>e(...t,...n),compose:(...e)=>e.reduce(((e,t)=>(...n)=>e(t(...n)))),curry:e,memorize:e=>{const t=new Map,n=function(n){return(t.has(n)||t.set(n,e.call(this,n)))&&t.get(n)};return n.cache=t,n},attempt:(e,...t)=>{try{return e(...t)}catch(e){return e instanceof Error?e:new Error(e)}},compact:e=>e.filter(Boolean),promisify:e=>(...t)=>new Promise(((n,r)=>e(...t,((e,t)=>e?r(e):n(t))))),distance:(e,t)=>Math.hypot(t.x-e.x,t.y-e.y),zip:(...e)=>{const t=Math.max(...e.map((e=>e.length)));return Array.from({length:t}).map(((t,n)=>Array.from({length:e.length},((t,r)=>e[r][n]))))},range:function*(e,t,n=1){let r=e;for(;r<t;)yield r,r+=n},unzip:e=>e.reduce(((e,t)=>(t.forEach(((t,n)=>e[n].push(t))),e)),Array.from({length:Math.max(...e.map((e=>e.length)))}).map((e=>[]))),union:(e,t)=>Array.from(new Set([...e,...t])),pluck:(e,t)=>e.map((e=>e[t])),mask:(e,t=4,n="*")=>`${e}`.slice(-t).padStart(`${e}`.length,n),intersection:(e,t)=>{const n=new Set(t);return[...new Set(e)].filter((e=>n.has(e)))},animateNumber:(e,t,n,r)=>{let o=null,a=i=>{o=o||i;let l=i-o,s=Math.min(l/r,1);e(t+s*(n-t)),s<1&&window.requestAnimationFrame(a)};window.requestAnimationFrame(a)},detectDeviceType:r,deg2rad:e=>e*Math.PI/180,factorial:i,equals:a,includesAll:(e,t)=>t.every((t=>e.includes(t))),includesAny:(e,t)=>t.some((t=>e.includes(t))),rad2deg:n,randomHexColorCode:()=>"#"+(1048575*Math.random()*1e6).toString(16).slice(0,6),timeTaken:e=>{console.time("timeTaken");const t=e();return console.timeEnd("timeTaken"),t},sumPower:(e,t=2,n=1)=>Array(e+1-n).fill(0).map(((e,r)=>(r+n)**t)).reduce(((e,t)=>e+t),0),reverseString:e=>[...e].reverse().join(""),vh2px:e=>e*Math.min(window.innerHeight,document.documentElement.clientHeight)/100,px2vh:e=>e/window.innerHeight*100,loadImageAsBase64URL:c,sampleSize:([...e],t=1)=>{let n=e.length;for(;n;){const t=Math.floor(Math.random()*n--);[e[n],e[t]]=[e[t],e[n]]}return e.slice(0,t)},fromTimestamp:e=>new Date(1e3*e),getTimestamp:(e=new Date,t=!1)=>{const n=e.getTime()/1e3;return t?Math.floor(n):n},isOdd:e=>e%2==1,isEven:e=>e%2==0,copyToClipboard:e=>{const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t);const n=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),n&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(n))},yesNo:(e,t=!1)=>!!/^(y|yes)$/i.test(e)||!/^(n|no)$/i.test(e)&&t,loadVideoAsBlob:(e,t,n="mp4")=>{const r=new FileReader;r.readAsArrayBuffer(e),r.addEventListener("load",(()=>{const e=r.result,o=new Blob([new Uint8Array(e)],{type:`video/${n}`});t(o)}))},maxN:(e,t=1)=>[...e].sort(((e,t)=>t-e)).slice(0,t),minN:(e,t=1)=>[...e].sort(((e,t)=>e-t)).slice(0,t),padNumber:(e,t)=>`${e}`.padStart(t,"0"),addHoursToDate:(e,t)=>(e.setTime(e.getTime()+60*t*60*1e3),e),addMinutesToDate:(e,t)=>(e.setTime(e.getTime()+60*t*1e3),e),addSecondsToDate:(e,t)=>(e.setTime(e.getTime()+1e3*t),e),chunk:(e,t)=>Array.from({length:Math.ceil(e.length/t)},((n,r)=>e.slice(r*t,r*t+t))),isUrl:e=>/^http(s)?/.test(e),objectMap:(e,t)=>Object.fromEntries(Object.entries(e).map((([e,n],r)=>[e,t(n,e,r)]))),orderBy:(e,t,n)=>[...e].sort(((e,r)=>t.reduce(((t,o,a)=>{if(0===t){const[i,l]=n&&"desc"===n[a]?[r[o],e[o]]:[e[o],r[o]];t=i>l?1:i<l?-1:0}return t}),0))),head:e=>e&&e.length?e[0]:void 0,last:e=>e&&e.length?e[e.length-1]:void 0,objectToQueryString:e=>e?Object.entries(e).reduce(((e,[t,n])=>{const r=0===e.length?"?":"&";return e+="string"==typeof n?`${r}${t}=${n}`:""}),""):"",clamp:(e,t,n)=>Math.max(Math.min(Number(e),Math.max(t,n)),Math.min(t,n)),isElBottomVisible:(e,t=0)=>e.offsetHeight+e.scrollTop>=e.scrollHeight-t,isIdcard:e=>/(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0[1-9]|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/.test(e),lerp:(e,t,n)=>e+(t-e)*n,maxBy:(e,t)=>Math.max(...e.map("function"==typeof t?t:e=>e[t])),minBy:(e,t)=>Math.min(...e.map("function"==typeof t?t:e=>e[t])),reload:()=>location.reload(),repeatArray:(e,t)=>[].concat(...Array(t).fill(e)),degreesAngle:(e,t)=>n(Math.atan2(t.y-e.y,t.x-e.x)),radiansAngle:(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),addDaysToDate:(e,t)=>(e.setTime(e.getTime()+60*t*60*1e3*24),e),addWeeksToDate:(e,t)=>(e.setTime(e.getTime()+60*t*60*1e3*24*7),e),groupBy:(e,t)=>e.map("function"==typeof t?t:e=>e[t]).reduce(((t,n,r)=>(t[n]=(t[n]||[]).concat(e[r]),t)),{}),chunkMultiSize:(e,t)=>{const n=[];let r=0,o=0;for(;o<e.length;){const a=t[r];n.push(e.slice(o,o+a)),r=(r+1)%t.length,o+=a}return n},disableTouchMove:()=>{document.body.addEventListener("touchmove",o,{passive:!1})},enableTouchMove:()=>{document.body.removeEventListener("touchmove",o)},getNormalizedMousePos:e=>({x:e.clientX/window.innerWidth*2-1,y:-e.clientY/window.innerHeight*2+1}),dataURItoFile:(e,t="1.jpg")=>{let n=e.split(",")[0].split(":")[1].split(";")[0],r=atob(e.split(",")[1]),o=new ArrayBuffer(r.length),a=new Uint8Array(o);for(let e=0;e<r.length;e++)a[e]=r.charCodeAt(e);return new File([a],t,{type:n})},dateRange:function*(e,t,n=1){let r=e;for(;r<t;)yield new Date(r),r.setDate(r.getDate()+n)},frequencies:e=>e.reduce(((e,t)=>(e[t]=e[t]?e[t]+1:1,e)),{}),countOccurrences:(e,t)=>e.reduce(((e,n)=>n===t?e+1:e),0),loopSlice:(e,t,n)=>{const[r,o]=[t,n];return o>=r?e.slice(r,o):[...e.slice(r,e.length),...e.slice(0,o)]},castArray:e=>Array.isArray(e)?e:[e],compatibleDate:e=>e.replace(/\.|\-/g,"/"),toHttps:e=>e.replace(/^http:/,"https:"),cleanObject:e=>(Object.keys(e).forEach((t=>{e[t]||delete e[t]})),e),isToday:e=>{const t=new Date;return e.getDate()==t.getDate()&&e.getMonth()==t.getMonth()&&e.getFullYear()==t.getFullYear()},isNumber:e=>"number"==typeof e&&e==e,isNumeric:e=>!isNaN(e),isObject:e=>e===Object(e),convertLetterToNumber:e=>{e=e.toUpperCase();const t="A".charCodeAt(0);return e.charCodeAt(0)-t},convertNumberToLetter:e=>{const t=e+"A".charCodeAt(0);return String.fromCharCode(t)},toFixed0:e=>Number(e).toFixed(0),toFixed1:e=>Number(e).toFixed(1),toFixed2:e=>Number(e).toFixed(2),toFixed3:e=>Number(e).toFixed(3),setCharAt:(e,t,n)=>t>e.length-1?e:e.substring(0,t)+n+e.substring(t+1),remove:(e,t)=>Array.isArray(e)?e.filter(t).reduce(((t,n)=>(e.splice(e.indexOf(n),1),t.concat(n))),[]):[],isPositiveInteger:e=>/^[1-9]\d*$/.test(e),setInnerHTML:(e,t)=>{e.innerHTML=t,Array.from(e.querySelectorAll("script")).forEach((e=>{const t=document.createElement("script");Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.appendChild(document.createTextNode(e.innerHTML)),e.parentNode.replaceChild(t,e)}))},hexToRgb:e=>{const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null},getRandString:(e=10)=>{let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=n.length;for(let o=0;o<e;o++)t+=n.charAt(Math.floor(Math.random()*r));return t}};return d}));
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Get a random string of a specific length.
3
+ * ref: https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
4
+ *
5
+ * @param length
6
+ * @returns
7
+ */
8
+ declare const getRandString: (length?: number) => string;
9
+ export default getRandString;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Get a random string of a specific length.
3
+ * ref: https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
4
+ *
5
+ * @param length
6
+ * @returns
7
+ */
8
+ const getRandString = (length = 10) => {
9
+ let result = "";
10
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
11
+ const charactersLength = characters.length;
12
+ for (let i = 0; i < length; i++) {
13
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
14
+ }
15
+ return result;
16
+ };
17
+ export default getRandString;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Convert a hex color to a rgb object.
3
+ * ref: https://stackoverflow.com/a/5624139
4
+ *
5
+ * @param hex
6
+ * @returns
7
+ */
8
+ declare const hexToRgb: (hex: string) => {
9
+ r: number;
10
+ g: number;
11
+ b: number;
12
+ } | null;
13
+ export default hexToRgb;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Convert a hex color to a rgb object.
3
+ * ref: https://stackoverflow.com/a/5624139
4
+ *
5
+ * @param hex
6
+ * @returns
7
+ */
8
+ const hexToRgb = (hex) => {
9
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
10
+ return result
11
+ ? {
12
+ r: parseInt(result[1], 16),
13
+ g: parseInt(result[2], 16),
14
+ b: parseInt(result[3], 16),
15
+ }
16
+ : null;
17
+ };
18
+ export default hexToRgb;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Check whether a number is a positive integer.
3
+ *
4
+ * @param num
5
+ * @returns
6
+ */
7
+ declare const isPositiveInteger: (num: any) => boolean;
8
+ export default isPositiveInteger;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Check whether a number is a positive integer.
3
+ *
4
+ * @param num
5
+ * @returns
6
+ */
7
+ const isPositiveInteger = (num) => {
8
+ return /^[1-9]\d*$/.test(num);
9
+ };
10
+ export default isPositiveInteger;
package/dist/kyouka.d.ts CHANGED
@@ -134,5 +134,16 @@ declare const kyoka: {
134
134
  toFixed0: (num: string | number) => string;
135
135
  toFixed1: (num: string | number) => string;
136
136
  toFixed2: (num: string | number) => string;
137
+ toFixed3: (num: string | number) => string;
138
+ setCharAt: (str: string, index: number, chr: string) => string;
139
+ remove: (arr: any[], func: any) => any;
140
+ isPositiveInteger: (num: any) => boolean;
141
+ setInnerHTML: (elm: any, html: any) => void;
142
+ hexToRgb: (hex: string) => {
143
+ r: number;
144
+ g: number;
145
+ b: number;
146
+ } | null;
147
+ getRandString: (length?: number) => string;
137
148
  };
138
149
  export default kyoka;
package/dist/kyouka.js CHANGED
@@ -40,6 +40,7 @@ import fromTimestamp from "./fromTimestamp";
40
40
  import getCenterPointPos from "./getCenterPointPos";
41
41
  import getMousePos from "./getMousePos";
42
42
  import getNormalizedMousePos from "./getNormalizedMousePos";
43
+ import getRandString from "./getRandString";
43
44
  import { getScrollPosition, getScrollPositionAsVw } from "./getScrollPosition";
44
45
  import getTimeDeltaAsSeconds from "./getTimeDeltaAsSeconds";
45
46
  import getTimeFromDate from "./getTimeFromDate";
@@ -47,6 +48,7 @@ import getTimestamp from "./getTimestamp";
47
48
  import getURLParameters from "./getURLParameters";
48
49
  import groupBy from "./groupBy";
49
50
  import head from "./head";
51
+ import hexToRgb from "./hexToRgb";
50
52
  import includesAll from "./includesAll";
51
53
  import includesAny from "./includesAny";
52
54
  import initialize2DArray from "./initialize2DArray";
@@ -63,6 +65,7 @@ import isNumeric from "./isNumeric";
63
65
  import isObject from "./isObject";
64
66
  import isOdd from "./isOdd";
65
67
  import isPhoneNumber from "./isPhoneNumber";
68
+ import isPositiveInteger from "./isPositiveInteger";
66
69
  import isToday from "./isToday";
67
70
  import isUrl from "./isUrl";
68
71
  import JSONToCSV from "./JSONToCSV";
@@ -99,11 +102,14 @@ import randomIntegerInRange from "./randomIntegerInRange";
99
102
  import randomNumberInRange from "./randomNumberInRange";
100
103
  import range from "./range";
101
104
  import reload from "./reload";
105
+ import remove from "./remove";
102
106
  import repeatArray from "./repeatArray";
103
107
  import requestInterval from "./requestInterval";
104
108
  import reverseString from "./reverseString";
105
109
  import sample from "./sample";
106
110
  import sampleSize from "./sampleSize";
111
+ import setCharAt from "./setChatAt";
112
+ import setInnerHTML from "./setInnerHTML";
107
113
  import shuffle from "./shuffle";
108
114
  import sleep from "./sleep";
109
115
  import orderBy from "./orderBy";
@@ -114,6 +120,7 @@ import timeTaken from "./timeTaken";
114
120
  import toFixed0 from "./toFixed0";
115
121
  import toFixed1 from "./toFixed1";
116
122
  import toFixed2 from "./toFixed2";
123
+ import toFixed3 from "./toFixed3";
117
124
  import toHttps from "./toHttps";
118
125
  import union from "./union";
119
126
  import uniq from "./uniq";
@@ -248,5 +255,12 @@ const kyoka = {
248
255
  toFixed0,
249
256
  toFixed1,
250
257
  toFixed2,
258
+ toFixed3,
259
+ setCharAt,
260
+ remove,
261
+ isPositiveInteger,
262
+ setInnerHTML,
263
+ hexToRgb,
264
+ getRandString,
251
265
  };
252
266
  export default kyoka;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Mutates an array by removing elements for which the given function returns `false`.
3
+ *
4
+ * @param arr
5
+ * @param func
6
+ * @returns
7
+ */
8
+ declare const remove: (arr: any[], func: any) => any;
9
+ export default remove;
package/dist/remove.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Mutates an array by removing elements for which the given function returns `false`.
3
+ *
4
+ * @param arr
5
+ * @param func
6
+ * @returns
7
+ */
8
+ const remove = (arr, func) => Array.isArray(arr)
9
+ ? arr.filter(func).reduce((acc, val) => {
10
+ arr.splice(arr.indexOf(val), 1);
11
+ return acc.concat(val);
12
+ }, [])
13
+ : [];
14
+ export default remove;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Replace a specific char at a specific index of a string.
3
+ *
4
+ * @param str
5
+ * @param index
6
+ * @param chr
7
+ * @returns
8
+ */
9
+ declare const setCharAt: (str: string, index: number, chr: string) => string;
10
+ export default setCharAt;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Replace a specific char at a specific index of a string.
3
+ *
4
+ * @param str
5
+ * @param index
6
+ * @param chr
7
+ * @returns
8
+ */
9
+ const setCharAt = (str, index, chr) => {
10
+ if (index > str.length - 1) {
11
+ return str;
12
+ }
13
+ return str.substring(0, index) + chr + str.substring(index + 1);
14
+ };
15
+ export default setCharAt;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Executing <script> elements inserted with .innerHTML.
3
+ * ref: https://stackoverflow.com/a/47614491
4
+ *
5
+ * @param elm
6
+ * @param html
7
+ */
8
+ declare const setInnerHTML: (elm: any, html: any) => void;
9
+ export default setInnerHTML;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Executing <script> elements inserted with .innerHTML.
3
+ * ref: https://stackoverflow.com/a/47614491
4
+ *
5
+ * @param elm
6
+ * @param html
7
+ */
8
+ const setInnerHTML = (elm, html) => {
9
+ elm.innerHTML = html;
10
+ Array.from(elm.querySelectorAll("script")).forEach((oldScript) => {
11
+ const newScript = document.createElement("script");
12
+ Array.from(oldScript.attributes).forEach((attr) => newScript.setAttribute(attr.name, attr.value));
13
+ newScript.appendChild(document.createTextNode(oldScript.innerHTML));
14
+ oldScript.parentNode.replaceChild(newScript, oldScript);
15
+ });
16
+ };
17
+ export default setInnerHTML;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A shortcut for Number.toFixed(3).
3
+ *
4
+ * @param num
5
+ * @returns
6
+ */
7
+ declare const toFixed3: (num: number | string) => string;
8
+ export default toFixed3;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A shortcut for Number.toFixed(3).
3
+ *
4
+ * @param num
5
+ * @returns
6
+ */
7
+ const toFixed3 = (num) => Number(num).toFixed(3);
8
+ export default toFixed3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kyouka",
3
- "version": "1.3.7",
3
+ "version": "1.3.8",
4
4
  "description": "",
5
5
  "main": "./dist/kyouka.js",
6
6
  "types": "./dist/kyouka.d.ts",