kyouka 1.3.7 → 1.3.9
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 +10 -1
- package/build/kyouka.umd.js +1 -1
- package/dist/calculateDateDifference.d.ts +8 -0
- package/dist/calculateDateDifference.js +21 -0
- package/dist/doOnce.d.ts +8 -0
- package/dist/doOnce.js +15 -0
- package/dist/doOncePerDay.d.ts +8 -0
- package/dist/doOncePerDay.js +17 -0
- package/dist/fileToBinaryString.d.ts +7 -0
- package/dist/fileToBinaryString.js +19 -0
- package/dist/getDateProgress.d.ts +8 -0
- package/dist/getDateProgress.js +14 -0
- package/dist/getRandString.d.ts +9 -0
- package/dist/getRandString.js +17 -0
- package/dist/hexToRgb.d.ts +13 -0
- package/dist/hexToRgb.js +18 -0
- package/dist/isInCurrentQuarter.d.ts +7 -0
- package/dist/isInCurrentQuarter.js +22 -0
- package/dist/isPositiveInteger.d.ts +8 -0
- package/dist/isPositiveInteger.js +10 -0
- package/dist/kyouka.d.ts +20 -0
- package/dist/kyouka.js +32 -0
- package/dist/preloadAudios.d.ts +6 -0
- package/dist/preloadAudios.js +14 -0
- package/dist/remove.d.ts +9 -0
- package/dist/remove.js +14 -0
- package/dist/scrollToBottom.d.ts +6 -0
- package/dist/scrollToBottom.js +6 -0
- package/dist/setChatAt.d.ts +10 -0
- package/dist/setChatAt.js +15 -0
- package/dist/setInnerHTML.d.ts +9 -0
- package/dist/setInnerHTML.js +17 -0
- package/dist/stringifyObject.d.ts +7 -0
- package/dist/stringifyObject.js +12 -0
- package/dist/toFixed3.d.ts +8 -0
- package/dist/toFixed3.js +8 -0
- package/package.json +1 -1
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/
|
|
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**
|
package/build/kyouka.umd.js
CHANGED
|
@@ -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},preloadAudios:(e="audio")=>{document.querySelectorAll(e).forEach((e=>{document.addEventListener("touchstart",(()=>{e.play(),e.pause()}),{once:!0})}))},doOnce:(e,t,n="session")=>{const r=window[n+"Storage"];r.getItem(e)||(r.setItem(e,"1"),t())},scrollToBottom:()=>window.scrollTo(0,document.body.scrollHeight),fileToBinaryString:e=>new Promise(((t,n)=>{const r=new FileReader;r.readAsBinaryString(e),r.onload=e=>{const n=e.target.result;t(n)},r.onerror=e=>{n(e)}})),stringifyObject:e=>(Object.keys(e).forEach((t=>{e[t]=`${e[t]}`})),e),calculateDateDifference:(e,t="now")=>{const n="now"===t?new Date:new Date(t),r=new Date(e);if(isNaN(r.getTime())||isNaN(n.getTime()))throw new Error("Invalid date");return(n.getTime()-r.getTime())/864e5},getDateProgress:(e,t)=>{const n=new Date,r=t.getTime()-e.getTime(),o=n.getTime()-e.getTime();return Math.floor(o/r*100)},isInCurrentQuarter:e=>{const t=new Date,n=t.getFullYear(),r=t.getMonth(),o=e.getFullYear(),a=e.getMonth(),i=3*Math.floor(r/3);return o===n&&a>=i&&a<=i+2},doOncePerDay:(e,t,n="session")=>{const r=window[n+"Storage"],o=(new Date).toISOString().split("T")[0];r.getItem(e)!==o&&(t(),r.setItem(e,o))}};return d}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the difference in days between two dates.
|
|
3
|
+
* @param {string | Date} startDate - The start date
|
|
4
|
+
* @param {string | Date | 'now'} endDate - The end date, can be current date ('now') or a specified target date
|
|
5
|
+
* @returns {number} - The date difference (in days)
|
|
6
|
+
*/
|
|
7
|
+
declare const calculateDateDifference: (startDate: string | Date, endDate?: string | Date | "now") => number;
|
|
8
|
+
export default calculateDateDifference;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the difference in days between two dates.
|
|
3
|
+
* @param {string | Date} startDate - The start date
|
|
4
|
+
* @param {string | Date | 'now'} endDate - The end date, can be current date ('now') or a specified target date
|
|
5
|
+
* @returns {number} - The date difference (in days)
|
|
6
|
+
*/
|
|
7
|
+
const calculateDateDifference = (startDate, endDate = "now") => {
|
|
8
|
+
// If the end date is 'now', use the current date
|
|
9
|
+
const currentDate = endDate === "now" ? new Date() : new Date(endDate);
|
|
10
|
+
// Convert the start date to a Date object
|
|
11
|
+
const start = new Date(startDate);
|
|
12
|
+
// Ensure the dates are valid
|
|
13
|
+
if (isNaN(start.getTime()) || isNaN(currentDate.getTime())) {
|
|
14
|
+
throw new Error("Invalid date");
|
|
15
|
+
}
|
|
16
|
+
// Calculate the date difference (in milliseconds)
|
|
17
|
+
const timeDifference = currentDate.getTime() - start.getTime();
|
|
18
|
+
// Convert to days
|
|
19
|
+
return timeDifference / (1000 * 60 * 60 * 24);
|
|
20
|
+
};
|
|
21
|
+
export default calculateDateDifference;
|
package/dist/doOnce.d.ts
ADDED
package/dist/doOnce.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Do something just once.
|
|
3
|
+
* @param cacheName
|
|
4
|
+
* @param cb
|
|
5
|
+
* @param storage
|
|
6
|
+
*/
|
|
7
|
+
const doOnce = (cacheName, cb, storage = "session") => {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const cache = window[storage + "Storage"];
|
|
10
|
+
if (!cache.getItem(cacheName)) {
|
|
11
|
+
cache.setItem(cacheName, "1");
|
|
12
|
+
cb();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export default doOnce;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Do something once per day.
|
|
3
|
+
* @param cacheName
|
|
4
|
+
* @param cb
|
|
5
|
+
* @param storage
|
|
6
|
+
*/
|
|
7
|
+
const do0ncePerDay = (cacheName, cb, storage = "session") => {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const cache = window[storage + "Storage"];
|
|
10
|
+
const today = new Date().toISOString().split("T")[0];
|
|
11
|
+
const lastExecuted = cache.getItem(cacheName);
|
|
12
|
+
if (lastExecuted !== today) {
|
|
13
|
+
cb();
|
|
14
|
+
cache.setItem(cacheName, today);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export default do0ncePerDay;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert file to binary string.
|
|
3
|
+
* @param file
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
const fileToBinaryString = (file) => {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const reader = new FileReader();
|
|
9
|
+
reader.readAsBinaryString(file);
|
|
10
|
+
reader.onload = (event) => {
|
|
11
|
+
const binaryString = event.target.result;
|
|
12
|
+
resolve(binaryString);
|
|
13
|
+
};
|
|
14
|
+
reader.onerror = (error) => {
|
|
15
|
+
reject(error);
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export default fileToBinaryString;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the progress of a date between two dates.
|
|
3
|
+
* @param begin The begin date
|
|
4
|
+
* @param end The end date
|
|
5
|
+
* @returns The progress of the date between the two dates
|
|
6
|
+
*/
|
|
7
|
+
declare const getDateProgress: (begin: Date, end: Date) => number;
|
|
8
|
+
export default getDateProgress;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the progress of a date between two dates.
|
|
3
|
+
* @param begin The begin date
|
|
4
|
+
* @param end The end date
|
|
5
|
+
* @returns The progress of the date between the two dates
|
|
6
|
+
*/
|
|
7
|
+
const getDateProgress = (begin, end) => {
|
|
8
|
+
const now = new Date();
|
|
9
|
+
const totalDuration = end.getTime() - begin.getTime();
|
|
10
|
+
const elapsedDuration = now.getTime() - begin.getTime();
|
|
11
|
+
const progress = Math.floor((elapsedDuration / totalDuration) * 100);
|
|
12
|
+
return progress;
|
|
13
|
+
};
|
|
14
|
+
export default getDateProgress;
|
|
@@ -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;
|
package/dist/hexToRgb.js
ADDED
|
@@ -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,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a date is in the current quarter.
|
|
3
|
+
* @param date The date to check
|
|
4
|
+
* @returns True if the date is in the current quarter, false otherwise
|
|
5
|
+
*/
|
|
6
|
+
const isInCurrentQuarter = (date) => {
|
|
7
|
+
const currentDate = new Date();
|
|
8
|
+
// Get the current year and current month
|
|
9
|
+
const currentYear = currentDate.getFullYear();
|
|
10
|
+
const currentMonth = currentDate.getMonth();
|
|
11
|
+
// Get the year and month of the date
|
|
12
|
+
const dateYear = date.getFullYear();
|
|
13
|
+
const dateMonth = date.getMonth();
|
|
14
|
+
// Calculate the start and end months of the quarter
|
|
15
|
+
const quarterStartMonth = Math.floor(currentMonth / 3) * 3;
|
|
16
|
+
const quarterEndMonth = quarterStartMonth + 2;
|
|
17
|
+
// Check if it's in the current quarter
|
|
18
|
+
return (dateYear === currentYear &&
|
|
19
|
+
dateMonth >= quarterStartMonth &&
|
|
20
|
+
dateMonth <= quarterEndMonth);
|
|
21
|
+
};
|
|
22
|
+
export default isInCurrentQuarter;
|
package/dist/kyouka.d.ts
CHANGED
|
@@ -134,5 +134,25 @@ 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;
|
|
148
|
+
preloadAudios: (sel?: string) => void;
|
|
149
|
+
doOnce: (cacheName: string, cb: () => void, storage?: string) => void;
|
|
150
|
+
scrollToBottom: () => void;
|
|
151
|
+
fileToBinaryString: (file: File) => Promise<string | ArrayBuffer | null>;
|
|
152
|
+
stringifyObject: (obj: Record<string, any>) => Record<string, any>;
|
|
153
|
+
calculateDateDifference: (startDate: string | Date, endDate?: string | Date) => number;
|
|
154
|
+
getDateProgress: (begin: Date, end: Date) => number;
|
|
155
|
+
isInCurrentQuarter: (date: Date) => boolean;
|
|
156
|
+
doOncePerDay: (cacheName: string, cb: () => void, storage?: string) => void;
|
|
137
157
|
};
|
|
138
158
|
export default kyoka;
|
package/dist/kyouka.js
CHANGED
|
@@ -7,6 +7,7 @@ import animateNumber from "./animateNumber";
|
|
|
7
7
|
import arrayToCSV from "./arrayToCSV";
|
|
8
8
|
import attempt from "./attempt";
|
|
9
9
|
import average from "./average";
|
|
10
|
+
import calculateDateDifference from "./calculateDateDifference";
|
|
10
11
|
import castArray from "./castArray";
|
|
11
12
|
import chunk from "./chunk";
|
|
12
13
|
import chunkMultiSize from "./chunkMultiSize";
|
|
@@ -31,15 +32,20 @@ import degreesAngle from "./degreesAngle";
|
|
|
31
32
|
import detectDeviceType from "./detectDeviceType";
|
|
32
33
|
import disableTouchMove from "./disableTouchMove";
|
|
33
34
|
import distance from "./distance";
|
|
35
|
+
import doOnce from "./doOnce";
|
|
36
|
+
import doOncePerDay from "./doOncePerDay";
|
|
34
37
|
import enableTouchMove from "./enableTouchMove";
|
|
35
38
|
import equals from "./equals";
|
|
36
39
|
import factorial from "./factorial";
|
|
40
|
+
import fileToBinaryString from "./fileToBinaryString";
|
|
37
41
|
import formatDuration from "./formatDuration";
|
|
38
42
|
import frequencies from "./frequencies";
|
|
39
43
|
import fromTimestamp from "./fromTimestamp";
|
|
40
44
|
import getCenterPointPos from "./getCenterPointPos";
|
|
45
|
+
import getDateProgress from "./getDateProgress";
|
|
41
46
|
import getMousePos from "./getMousePos";
|
|
42
47
|
import getNormalizedMousePos from "./getNormalizedMousePos";
|
|
48
|
+
import getRandString from "./getRandString";
|
|
43
49
|
import { getScrollPosition, getScrollPositionAsVw } from "./getScrollPosition";
|
|
44
50
|
import getTimeDeltaAsSeconds from "./getTimeDeltaAsSeconds";
|
|
45
51
|
import getTimeFromDate from "./getTimeFromDate";
|
|
@@ -47,6 +53,7 @@ import getTimestamp from "./getTimestamp";
|
|
|
47
53
|
import getURLParameters from "./getURLParameters";
|
|
48
54
|
import groupBy from "./groupBy";
|
|
49
55
|
import head from "./head";
|
|
56
|
+
import hexToRgb from "./hexToRgb";
|
|
50
57
|
import includesAll from "./includesAll";
|
|
51
58
|
import includesAny from "./includesAny";
|
|
52
59
|
import initialize2DArray from "./initialize2DArray";
|
|
@@ -58,11 +65,13 @@ import isElBottomVisible from "./isElBottomVisible";
|
|
|
58
65
|
import isEmpty from "./isEmpty";
|
|
59
66
|
import isEven from "./isEven";
|
|
60
67
|
import isIdcard from "./isIdcard";
|
|
68
|
+
import isInCurrentQuarter from "./isInCurrentQuarter";
|
|
61
69
|
import isNumber from "./isNumber";
|
|
62
70
|
import isNumeric from "./isNumeric";
|
|
63
71
|
import isObject from "./isObject";
|
|
64
72
|
import isOdd from "./isOdd";
|
|
65
73
|
import isPhoneNumber from "./isPhoneNumber";
|
|
74
|
+
import isPositiveInteger from "./isPositiveInteger";
|
|
66
75
|
import isToday from "./isToday";
|
|
67
76
|
import isUrl from "./isUrl";
|
|
68
77
|
import JSONToCSV from "./JSONToCSV";
|
|
@@ -87,6 +96,7 @@ import padNumber from "./padNumber";
|
|
|
87
96
|
import partial from "./partial";
|
|
88
97
|
import pick from "./pick";
|
|
89
98
|
import pluck from "./pluck";
|
|
99
|
+
import preloadAudios from "./preloadAudios";
|
|
90
100
|
import previewImage from "./previewImage";
|
|
91
101
|
import promisify from "./promisify";
|
|
92
102
|
import px2vh from "./px2vh";
|
|
@@ -99,13 +109,18 @@ import randomIntegerInRange from "./randomIntegerInRange";
|
|
|
99
109
|
import randomNumberInRange from "./randomNumberInRange";
|
|
100
110
|
import range from "./range";
|
|
101
111
|
import reload from "./reload";
|
|
112
|
+
import remove from "./remove";
|
|
102
113
|
import repeatArray from "./repeatArray";
|
|
103
114
|
import requestInterval from "./requestInterval";
|
|
104
115
|
import reverseString from "./reverseString";
|
|
105
116
|
import sample from "./sample";
|
|
106
117
|
import sampleSize from "./sampleSize";
|
|
118
|
+
import scrollToBottom from "./scrollToBottom";
|
|
119
|
+
import setCharAt from "./setChatAt";
|
|
120
|
+
import setInnerHTML from "./setInnerHTML";
|
|
107
121
|
import shuffle from "./shuffle";
|
|
108
122
|
import sleep from "./sleep";
|
|
123
|
+
import stringifyObject from "./stringifyObject";
|
|
109
124
|
import orderBy from "./orderBy";
|
|
110
125
|
import sum from "./sum";
|
|
111
126
|
import sumPower from "./sumPower";
|
|
@@ -114,6 +129,7 @@ import timeTaken from "./timeTaken";
|
|
|
114
129
|
import toFixed0 from "./toFixed0";
|
|
115
130
|
import toFixed1 from "./toFixed1";
|
|
116
131
|
import toFixed2 from "./toFixed2";
|
|
132
|
+
import toFixed3 from "./toFixed3";
|
|
117
133
|
import toHttps from "./toHttps";
|
|
118
134
|
import union from "./union";
|
|
119
135
|
import uniq from "./uniq";
|
|
@@ -248,5 +264,21 @@ const kyoka = {
|
|
|
248
264
|
toFixed0,
|
|
249
265
|
toFixed1,
|
|
250
266
|
toFixed2,
|
|
267
|
+
toFixed3,
|
|
268
|
+
setCharAt,
|
|
269
|
+
remove,
|
|
270
|
+
isPositiveInteger,
|
|
271
|
+
setInnerHTML,
|
|
272
|
+
hexToRgb,
|
|
273
|
+
getRandString,
|
|
274
|
+
preloadAudios,
|
|
275
|
+
doOnce,
|
|
276
|
+
scrollToBottom,
|
|
277
|
+
fileToBinaryString,
|
|
278
|
+
stringifyObject,
|
|
279
|
+
calculateDateDifference,
|
|
280
|
+
getDateProgress,
|
|
281
|
+
isInCurrentQuarter,
|
|
282
|
+
doOncePerDay,
|
|
251
283
|
};
|
|
252
284
|
export default kyoka;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preload all the audios in the page.
|
|
3
|
+
* @param sel
|
|
4
|
+
*/
|
|
5
|
+
const preloadAudios = (sel = "audio") => {
|
|
6
|
+
const audios = document.querySelectorAll(sel);
|
|
7
|
+
audios.forEach((audio) => {
|
|
8
|
+
document.addEventListener("touchstart", () => {
|
|
9
|
+
audio.play();
|
|
10
|
+
audio.pause();
|
|
11
|
+
}, { once: true });
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export default preloadAudios;
|
package/dist/remove.d.ts
ADDED
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,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,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;
|
package/dist/toFixed3.js
ADDED