kyouka 1.3.10 → 1.3.11
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/build/kyouka.umd.js +1 -1
- package/dist/formatNumber.d.ts +7 -0
- package/dist/formatNumber.js +23 -0
- package/dist/isCJKChar.d.ts +7 -0
- package/dist/isCJKChar.js +15 -0
- package/dist/kyouka.d.ts +3 -0
- package/dist/kyouka.js +6 -0
- package/dist/timeStringToSeconds.d.ts +7 -0
- package/dist/timeStringToSeconds.js +20 -0
- package/package.json +2 -2
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,r=t.length,...n)=>r<=n.length?t(...n):e.bind(null,t,r,...n),t=e=>{if(null===e)return null;let r=Object.assign({},e);return Object.keys(r).forEach((n=>r[n]="object"==typeof e[n]?t(e[n]):e[n])),Array.isArray(e)&&e.length?(r.length=e.length)&&Array.from(r):Array.isArray(e)?Array.from(e):r},r=e=>180*e/Math.PI,n=()=>/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 r=Object.keys(e);return r.length===Object.keys(t).length&&r.every((r=>i(e[r],t[r])))},a=e=>e<0?(()=>{throw new TypeError("Negative numbers are not allowed!")})():e<=1?1:e*a(e-1);const l=e=>e/window.innerWidth*100,s=(e=null,t="px")=>{const r={x:void 0!==(e=e||window).pageXOffset?e.pageXOffset:e.scrollLeft,y:void 0!==e.pageYOffset?e.pageYOffset:e.scrollTop};return"vw"===t&&(r.x=l(r.x),r.y=l(r.y)),r},c=e=>"function"==typeof e?e:t=>{if(null==t)return;const r=e.split(".");let n=t;for(const e of r){if(null==n)return;n=n[e]}return n},u=(e,t)=>{const r=new FileReader;r.readAsDataURL(e),r.addEventListener("load",(()=>{const e=r.result;t(e)}))},d=e=>"function"==typeof e?e:"number"==typeof e?t=>t[e]:t=>{if(null==t)return;const r=e.split(".");let n=t;for(const e of r){if(null==n)return;n=n[e]}return n},m=(e,t)=>{if(typeof e==typeof t)switch(typeof e){case"string":return e.localeCompare(t);case"number":case"boolean":return e<t?-1:e>t?1:0;default:return String(e).localeCompare(String(t))}return String(e).localeCompare(String(t))},f={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,r=1)=>Array.from({length:r},(()=>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 r=(new Date).getTime(),n={value:0},o=()=>{n.value=requestAnimationFrame(o),(new Date).getTime()-r>=t&&(e(),r=(new Date).getTime())};return n.value=requestAnimationFrame(o),n},sample:e=>e[Math.floor(Math.random()*e.length)],shuffle:([...e])=>{let t=e.length;for(;t;){const r=Math.floor(Math.random()*t--);[e[t],e[r]]=[e[r],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 r=e instanceof Date?e.getTime():e,n=(t instanceof Date?t.getTime():t)-r;return Math.floor(n)},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,r)=>{e.addEventListener("change",(e=>{const n=e.target.files,o=n?n[0]:null;u(o,(e=>{e&&(t.src=e,r(e))}))}))},getScrollPosition:s,getScrollPositionAsVw:(e=null)=>s(e,"vw"),px2vw:l,initialize2DArray:(e,t,r=null)=>Array.from({length:t}).map((()=>Array.from({length:e}).fill(r))),deepClone:t,initializeArrayWithValues:(e,t=0)=>Array(e).fill(t),CSVToArray:(e,t=",",r=!1)=>e.slice(r?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,r=",")=>[t.join(r),...e.map((e=>t.reduce(((t,n)=>`${t}${t.length?r:""}"${e[n]?e[n]:""}"`),"")))].join("\n"),CSVToJSON:(e,t=",")=>{const r=e.slice(0,e.indexOf("\n")).split(t);return e.slice(e.indexOf("\n")+1).split("\n").map((e=>{const n=e.split(t);return r.reduce(((e,t,r)=>(e[t]=n[r],e)),{})}))},uniq:e=>[...new Set(e)],omit:(e,t)=>Object.keys(e).filter((e=>!t.includes(e))).reduce(((t,r)=>(t[r]=e[r],t)),{}),pick:(e,t)=>t.reduce(((t,r)=>(r in e&&(t[r]=e[r]),t)),{}),iosInputScrollFix:()=>{"Mobile"===n()&&document.querySelectorAll("input, select, textarea").forEach((e=>{e.addEventListener("blur",(()=>{window.scrollBy(0,-1)}))}))},mapObject:(e,t)=>e.reduce(((r,n,o)=>(r[n]=t(n,o,e),r)),{}),mapKeys:(e,t)=>Object.keys(e).reduce(((r,n)=>(r[t(e[n],n,e)]=e[n],r)),{}),mapValues:(e,t)=>Object.keys(e).reduce(((r,n)=>(r[n]=t(e[n],n,e),r)),{}),isEmpty:e=>null==e||!(Object.keys(e)||e).length,debounce:(e,t=0)=>{let r;return function(...n){clearTimeout(r),r=setTimeout((()=>e.apply(this,n)),t)}},throttle:(e,t)=>{let r,n,o;return function(){const i=this,a=arguments;r?(clearTimeout(n),n=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(),r=!0)}},partial:(e,...t)=>(...r)=>e(...t,...r),compose:(...e)=>e.reduce(((e,t)=>(...r)=>e(t(...r)))),curry:e,memorize:e=>{const t=new Map,r=function(r){return(t.has(r)||t.set(r,e.call(this,r)))&&t.get(r)};return r.cache=t,r},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(((r,n)=>e(...t,((e,t)=>e?n(e):r(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,r)=>Array.from({length:e.length},((t,n)=>e[n][r]))))},range:function*(e,t,r=1){let n=e;for(;n<t;)yield n,n+=r},unzip:e=>e.reduce(((e,t)=>(t.forEach(((t,r)=>e[r].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,r="*")=>`${e}`.slice(-t).padStart(`${e}`.length,r),intersection:(e,t)=>{const r=new Set(t);return[...new Set(e)].filter((e=>r.has(e)))},animateNumber:(e,t,r,n)=>{let o=null,i=a=>{o=o||a;let l=a-o,s=Math.min(l/n,1);e(t+s*(r-t)),s<1&&window.requestAnimationFrame(i)};window.requestAnimationFrame(i)},detectDeviceType:n,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:r,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,r=1)=>Array(e+1-r).fill(0).map(((e,n)=>(n+r)**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:u,sampleSize:([...e],t=1)=>{let r=e.length;for(;r;){const t=Math.floor(Math.random()*r--);[e[r],e[t]]=[e[t],e[r]]}return e.slice(0,t)},fromTimestamp:e=>new Date(1e3*e),getTimestamp:(e=new Date,t=!1)=>{const r=e.getTime()/1e3;return t?Math.floor(r):r},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 r=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),r&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(r))},yesNo:(e,t=!1)=>!!/^(y|yes)$/i.test(e)||!/^(n|no)$/i.test(e)&&t,loadVideoAsBlob:(e,t,r="mp4")=>{const n=new FileReader;n.readAsArrayBuffer(e),n.addEventListener("load",(()=>{const e=n.result,o=new Blob([new Uint8Array(e)],{type:`video/${r}`});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)},((r,n)=>e.slice(n*t,n*t+t))),isUrl:e=>/^http(s)?/.test(e),objectMap:(e,t)=>Object.fromEntries(Object.entries(e).map((([e,r],n)=>[e,t(r,e,n)]))),orderBy:(e,t,r)=>[...e].sort(((e,n)=>t.reduce(((t,o,i)=>{if(0===t){const[a,l]=r&&"desc"===r[i]?[n[o],e[o]]:[e[o],n[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,r])=>{const n=0===e.length?"?":"&";return e+="string"==typeof r?`${n}${t}=${r}`:""}),""):"",clamp:(e,t,r)=>Math.max(Math.min(Number(e),Math.max(t,r)),Math.min(t,r)),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,r)=>e+(t-e)*r,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)=>r(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,r,n)=>(t[r]=(t[r]||[]).concat(e[n]),t)),{}),chunkMultiSize:(e,t)=>{const r=[];let n=0,o=0;for(;o<e.length;){const i=t[n];r.push(e.slice(o,o+i)),n=(n+1)%t.length,o+=i}return r},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 r=e.split(",")[0].split(":")[1].split(";")[0],n=atob(e.split(",")[1]),o=new ArrayBuffer(n.length),i=new Uint8Array(o);for(let e=0;e<n.length;e++)i[e]=n.charCodeAt(e);return new File([i],t,{type:r})},dateRange:function*(e,t,r=1){let n=e;for(;n<t;)yield new Date(n),n.setDate(n.getDate()+r)},frequencies:e=>e.reduce(((e,t)=>(e[t]=e[t]?e[t]+1:1,e)),{}),countOccurrences:(e,t)=>e.reduce(((e,r)=>r===t?e+1:e),0),loopSlice:(e,t,r)=>{const[n,o]=[t,r];return o>=n?e.slice(n,o):[...e.slice(n,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,r)=>t>e.length-1?e:e.substring(0,t)+r+e.substring(t+1),remove:(e,t)=>Array.isArray(e)?e.filter(t).reduce(((t,r)=>(e.splice(e.indexOf(r),1),t.concat(r))),[]):[],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 r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=r.length;for(let o=0;o<e;o++)t+=r.charAt(Math.floor(Math.random()*n));return t},preloadAudios:(e="audio")=>{document.querySelectorAll(e).forEach((e=>{document.addEventListener("touchstart",(()=>{e.play(),e.pause()}),{once:!0})}))},doOnce:(e,t,r="session")=>{const n=window[r+"Storage"];n.getItem(e)||(n.setItem(e,"1"),t())},scrollToBottom:()=>window.scrollTo(0,document.body.scrollHeight),fileToBinaryString:e=>new Promise(((t,r)=>{const n=new FileReader;n.readAsBinaryString(e),n.onload=e=>{const r=e.target.result;t(r)},n.onerror=e=>{r(e)}})),stringifyObject:e=>(Object.keys(e).forEach((t=>{e[t]=`${e[t]}`})),e),calculateDateDifference:(e,t="now")=>{const r="now"===t?new Date:new Date(t),n=new Date(e);if(isNaN(n.getTime())||isNaN(r.getTime()))throw new Error("Invalid date");return(r.getTime()-n.getTime())/864e5},getDateProgress:(e,t)=>{const r=new Date,n=t.getTime()-e.getTime(),o=r.getTime()-e.getTime();return Math.floor(o/n*100)},isInCurrentQuarter:e=>{const t=new Date,r=t.getFullYear(),n=t.getMonth(),o=e.getFullYear(),i=e.getMonth(),a=3*Math.floor(n/3);return o===r&&i>=a&&i<=a+2},doOncePerDay:(e,t,r="session")=>{const n=window[r+"Storage"],o=(new Date).toISOString().split("T")[0];n.getItem(e)!==o&&(t(),n.setItem(e,o))},doOnceOrAnother:(e,t,r,n="session")=>{const o=window[n+"Storage"];o.getItem(e)?r():(o.setItem(e,"1"),t())},findRecursive:function e(t,r,n){if(Array.isArray(t)){for(const o of t){const t=e(o,r,n);if(t)return t}return null}if(t&&"object"==typeof t){if(!n||n(t))return t;const o=t[r];if(o&&Array.isArray(o))return e(o,r,n);for(const o in t)if(o!==r&&Object.prototype.hasOwnProperty.call(t,o)&&t[o]&&"object"==typeof t[o]){const i=e(t[o],r,n);if(i)return i}}return null},findAllRecursive:function(e,t,r){const n=[];return function e(o){if(Array.isArray(o))o.forEach((t=>e(t)));else if(o&&"object"==typeof o){r&&!r(o)||n.push(o);const i=o[t];i&&Array.isArray(i)&&e(i);for(const r in o)r!==t&&Object.prototype.hasOwnProperty.call(o,r)&&o[r]&&"object"==typeof o[r]&&e(o[r])}}(e),n},partialRight:(e,...t)=>(...r)=>e(...r,...t),intersectionBy:(...e)=>{if(0===e.length)return[];let t=e=>e,r=[];for(let n=e.length-1;n>=0;n--){const o=e[n];if("function"==typeof o||"string"==typeof o){t=o,r=e.slice(0,n);break}0===n&&(r=e)}if(0===r.length)return[];const[n,...o]=r;if(!n||0===n.length)return[];const i=c(t),a=o.map((e=>new Set(e.map((e=>i(e))))));return n.filter((e=>{const t=i(e);return a.every((e=>e.has(t)))}))},sortBy:(e,...t)=>{if(!e||!Array.isArray(e))return[];const r=[...e];if(0===t.length)return r.sort();const n=t.map((e=>d(e)));return r.sort(((e,t)=>{for(const r of n){const n=r(e),o=r(t);if(null==n&&null==o)continue;if(null==n)return 1;if(null==o)return-1;const i=m(n,o);if(0!==i)return i}return 0}))}};return f}));
|
|
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,r=t.length,...n)=>r<=n.length?t(...n):e.bind(null,t,r,...n),t=e=>{if(null===e)return null;let r=Object.assign({},e);return Object.keys(r).forEach((n=>r[n]="object"==typeof e[n]?t(e[n]):e[n])),Array.isArray(e)&&e.length?(r.length=e.length)&&Array.from(r):Array.isArray(e)?Array.from(e):r},r=e=>180*e/Math.PI,n=()=>/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 r=Object.keys(e);return r.length===Object.keys(t).length&&r.every((r=>i(e[r],t[r])))},a=e=>e<0?(()=>{throw new TypeError("Negative numbers are not allowed!")})():e<=1?1:e*a(e-1);const l=e=>e/window.innerWidth*100,s=(e=null,t="px")=>{const r={x:void 0!==(e=e||window).pageXOffset?e.pageXOffset:e.scrollLeft,y:void 0!==e.pageYOffset?e.pageYOffset:e.scrollTop};return"vw"===t&&(r.x=l(r.x),r.y=l(r.y)),r},c=e=>"function"==typeof e?e:t=>{if(null==t)return;const r=e.split(".");let n=t;for(const e of r){if(null==n)return;n=n[e]}return n},u=(e,t)=>{const r=new FileReader;r.readAsDataURL(e),r.addEventListener("load",(()=>{const e=r.result;t(e)}))},d=e=>"function"==typeof e?e:"number"==typeof e?t=>t[e]:t=>{if(null==t)return;const r=e.split(".");let n=t;for(const e of r){if(null==n)return;n=n[e]}return n},m=(e,t)=>{if(typeof e==typeof t)switch(typeof e){case"string":return e.localeCompare(t);case"number":case"boolean":return e<t?-1:e>t?1:0;default:return String(e).localeCompare(String(t))}return String(e).localeCompare(String(t))},f={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,r=1)=>Array.from({length:r},(()=>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 r=(new Date).getTime(),n={value:0},o=()=>{n.value=requestAnimationFrame(o),(new Date).getTime()-r>=t&&(e(),r=(new Date).getTime())};return n.value=requestAnimationFrame(o),n},sample:e=>e[Math.floor(Math.random()*e.length)],shuffle:([...e])=>{let t=e.length;for(;t;){const r=Math.floor(Math.random()*t--);[e[t],e[r]]=[e[r],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 r=e instanceof Date?e.getTime():e,n=(t instanceof Date?t.getTime():t)-r;return Math.floor(n)},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,r)=>{e.addEventListener("change",(e=>{const n=e.target.files,o=n?n[0]:null;u(o,(e=>{e&&(t.src=e,r(e))}))}))},getScrollPosition:s,getScrollPositionAsVw:(e=null)=>s(e,"vw"),px2vw:l,initialize2DArray:(e,t,r=null)=>Array.from({length:t}).map((()=>Array.from({length:e}).fill(r))),deepClone:t,initializeArrayWithValues:(e,t=0)=>Array(e).fill(t),CSVToArray:(e,t=",",r=!1)=>e.slice(r?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,r=",")=>[t.join(r),...e.map((e=>t.reduce(((t,n)=>`${t}${t.length?r:""}"${e[n]?e[n]:""}"`),"")))].join("\n"),CSVToJSON:(e,t=",")=>{const r=e.slice(0,e.indexOf("\n")).split(t);return e.slice(e.indexOf("\n")+1).split("\n").map((e=>{const n=e.split(t);return r.reduce(((e,t,r)=>(e[t]=n[r],e)),{})}))},uniq:e=>[...new Set(e)],omit:(e,t)=>Object.keys(e).filter((e=>!t.includes(e))).reduce(((t,r)=>(t[r]=e[r],t)),{}),pick:(e,t)=>t.reduce(((t,r)=>(r in e&&(t[r]=e[r]),t)),{}),iosInputScrollFix:()=>{"Mobile"===n()&&document.querySelectorAll("input, select, textarea").forEach((e=>{e.addEventListener("blur",(()=>{window.scrollBy(0,-1)}))}))},mapObject:(e,t)=>e.reduce(((r,n,o)=>(r[n]=t(n,o,e),r)),{}),mapKeys:(e,t)=>Object.keys(e).reduce(((r,n)=>(r[t(e[n],n,e)]=e[n],r)),{}),mapValues:(e,t)=>Object.keys(e).reduce(((r,n)=>(r[n]=t(e[n],n,e),r)),{}),isEmpty:e=>null==e||!(Object.keys(e)||e).length,debounce:(e,t=0)=>{let r;return function(...n){clearTimeout(r),r=setTimeout((()=>e.apply(this,n)),t)}},throttle:(e,t)=>{let r,n,o;return function(){const i=this,a=arguments;r?(clearTimeout(n),n=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(),r=!0)}},partial:(e,...t)=>(...r)=>e(...t,...r),compose:(...e)=>e.reduce(((e,t)=>(...r)=>e(t(...r)))),curry:e,memorize:e=>{const t=new Map,r=function(r){return(t.has(r)||t.set(r,e.call(this,r)))&&t.get(r)};return r.cache=t,r},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(((r,n)=>e(...t,((e,t)=>e?n(e):r(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,r)=>Array.from({length:e.length},((t,n)=>e[n][r]))))},range:function*(e,t,r=1){let n=e;for(;n<t;)yield n,n+=r},unzip:e=>e.reduce(((e,t)=>(t.forEach(((t,r)=>e[r].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,r="*")=>`${e}`.slice(-t).padStart(`${e}`.length,r),intersection:(e,t)=>{const r=new Set(t);return[...new Set(e)].filter((e=>r.has(e)))},animateNumber:(e,t,r,n)=>{let o=null,i=a=>{o=o||a;let l=a-o,s=Math.min(l/n,1);e(t+s*(r-t)),s<1&&window.requestAnimationFrame(i)};window.requestAnimationFrame(i)},detectDeviceType:n,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:r,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,r=1)=>Array(e+1-r).fill(0).map(((e,n)=>(n+r)**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:u,sampleSize:([...e],t=1)=>{let r=e.length;for(;r;){const t=Math.floor(Math.random()*r--);[e[r],e[t]]=[e[t],e[r]]}return e.slice(0,t)},fromTimestamp:e=>new Date(1e3*e),getTimestamp:(e=new Date,t=!1)=>{const r=e.getTime()/1e3;return t?Math.floor(r):r},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 r=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),r&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(r))},yesNo:(e,t=!1)=>!!/^(y|yes)$/i.test(e)||!/^(n|no)$/i.test(e)&&t,loadVideoAsBlob:(e,t,r="mp4")=>{const n=new FileReader;n.readAsArrayBuffer(e),n.addEventListener("load",(()=>{const e=n.result,o=new Blob([new Uint8Array(e)],{type:`video/${r}`});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)},((r,n)=>e.slice(n*t,n*t+t))),isUrl:e=>/^http(s)?/.test(e),objectMap:(e,t)=>Object.fromEntries(Object.entries(e).map((([e,r],n)=>[e,t(r,e,n)]))),orderBy:(e,t,r)=>[...e].sort(((e,n)=>t.reduce(((t,o,i)=>{if(0===t){const[a,l]=r&&"desc"===r[i]?[n[o],e[o]]:[e[o],n[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,r])=>{const n=0===e.length?"?":"&";return e+="string"==typeof r?`${n}${t}=${r}`:""}),""):"",clamp:(e,t,r)=>Math.max(Math.min(Number(e),Math.max(t,r)),Math.min(t,r)),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,r)=>e+(t-e)*r,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)=>r(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,r,n)=>(t[r]=(t[r]||[]).concat(e[n]),t)),{}),chunkMultiSize:(e,t)=>{const r=[];let n=0,o=0;for(;o<e.length;){const i=t[n];r.push(e.slice(o,o+i)),n=(n+1)%t.length,o+=i}return r},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 r=e.split(",")[0].split(":")[1].split(";")[0],n=atob(e.split(",")[1]),o=new ArrayBuffer(n.length),i=new Uint8Array(o);for(let e=0;e<n.length;e++)i[e]=n.charCodeAt(e);return new File([i],t,{type:r})},dateRange:function*(e,t,r=1){let n=e;for(;n<t;)yield new Date(n),n.setDate(n.getDate()+r)},frequencies:e=>e.reduce(((e,t)=>(e[t]=e[t]?e[t]+1:1,e)),{}),countOccurrences:(e,t)=>e.reduce(((e,r)=>r===t?e+1:e),0),loopSlice:(e,t,r)=>{const[n,o]=[t,r];return o>=n?e.slice(n,o):[...e.slice(n,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,r)=>t>e.length-1?e:e.substring(0,t)+r+e.substring(t+1),remove:(e,t)=>Array.isArray(e)?e.filter(t).reduce(((t,r)=>(e.splice(e.indexOf(r),1),t.concat(r))),[]):[],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 r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=r.length;for(let o=0;o<e;o++)t+=r.charAt(Math.floor(Math.random()*n));return t},preloadAudios:(e="audio")=>{document.querySelectorAll(e).forEach((e=>{document.addEventListener("touchstart",(()=>{e.play(),e.pause()}),{once:!0})}))},doOnce:(e,t,r="session")=>{const n=window[r+"Storage"];n.getItem(e)||(n.setItem(e,"1"),t())},scrollToBottom:()=>window.scrollTo(0,document.body.scrollHeight),fileToBinaryString:e=>new Promise(((t,r)=>{const n=new FileReader;n.readAsBinaryString(e),n.onload=e=>{const r=e.target.result;t(r)},n.onerror=e=>{r(e)}})),stringifyObject:e=>(Object.keys(e).forEach((t=>{e[t]=`${e[t]}`})),e),calculateDateDifference:(e,t="now")=>{const r="now"===t?new Date:new Date(t),n=new Date(e);if(isNaN(n.getTime())||isNaN(r.getTime()))throw new Error("Invalid date");return(r.getTime()-n.getTime())/864e5},getDateProgress:(e,t)=>{const r=new Date,n=t.getTime()-e.getTime(),o=r.getTime()-e.getTime();return Math.floor(o/n*100)},isInCurrentQuarter:e=>{const t=new Date,r=t.getFullYear(),n=t.getMonth(),o=e.getFullYear(),i=e.getMonth(),a=3*Math.floor(n/3);return o===r&&i>=a&&i<=a+2},doOncePerDay:(e,t,r="session")=>{const n=window[r+"Storage"],o=(new Date).toISOString().split("T")[0];n.getItem(e)!==o&&(t(),n.setItem(e,o))},doOnceOrAnother:(e,t,r,n="session")=>{const o=window[n+"Storage"];o.getItem(e)?r():(o.setItem(e,"1"),t())},findRecursive:function e(t,r,n){if(Array.isArray(t)){for(const o of t){const t=e(o,r,n);if(t)return t}return null}if(t&&"object"==typeof t){if(!n||n(t))return t;const o=t[r];if(o&&Array.isArray(o))return e(o,r,n);for(const o in t)if(o!==r&&Object.prototype.hasOwnProperty.call(t,o)&&t[o]&&"object"==typeof t[o]){const i=e(t[o],r,n);if(i)return i}}return null},findAllRecursive:function(e,t,r){const n=[];return function e(o){if(Array.isArray(o))o.forEach((t=>e(t)));else if(o&&"object"==typeof o){r&&!r(o)||n.push(o);const i=o[t];i&&Array.isArray(i)&&e(i);for(const r in o)r!==t&&Object.prototype.hasOwnProperty.call(o,r)&&o[r]&&"object"==typeof o[r]&&e(o[r])}}(e),n},partialRight:(e,...t)=>(...r)=>e(...r,...t),intersectionBy:(...e)=>{if(0===e.length)return[];let t=e=>e,r=[];for(let n=e.length-1;n>=0;n--){const o=e[n];if("function"==typeof o||"string"==typeof o){t=o,r=e.slice(0,n);break}0===n&&(r=e)}if(0===r.length)return[];const[n,...o]=r;if(!n||0===n.length)return[];const i=c(t),a=o.map((e=>new Set(e.map((e=>i(e))))));return n.filter((e=>{const t=i(e);return a.every((e=>e.has(t)))}))},sortBy:(e,...t)=>{if(!e||!Array.isArray(e))return[];const r=[...e];if(0===t.length)return r.sort();const n=t.map((e=>d(e)));return r.sort(((e,t)=>{for(const r of n){const n=r(e),o=r(t);if(null==n&&null==o)continue;if(null==n)return 1;if(null==o)return-1;const i=m(n,o);if(0!==i)return i}return 0}))},formatNumber:e=>{const t=e<0,r=Math.abs(e),n=1e9,o=1e6;return r>=n?`${t?"-":""}${(r/n).toFixed(1)}B`:r>=o?`${t?"-":""}${(r/o).toFixed(1)}M`:r>=1e3?`${t?"-":""}${(r/1e3).toFixed(1)}K`:`${t?"-":""}${r}`},timeStringToSeconds:e=>{const t=e.split(":").map(Number);if(2===t.length){const[e,r]=t;return 60*e+r}if(3===t.length){const[e,r,n]=t;return 3600*e+60*r+n}return null},isCJKChar:e=>{const t=e.charCodeAt(0);return t>=19968&&t<=40959||t>=13312&&t<=19903||t>=63744&&t<=64255||t>=12352&&t<=12447||t>=12448&&t<=12543}};return f}));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a number into a more readable string with suffixes for thousands (K), millions (M), and billions (B).
|
|
3
|
+
* @param num
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
const formatNumber = (num) => {
|
|
7
|
+
const isNegative = num < 0;
|
|
8
|
+
const absNum = Math.abs(num);
|
|
9
|
+
const billion = 1_000_000_000;
|
|
10
|
+
const million = 1_000_000;
|
|
11
|
+
const thousand = 1_000;
|
|
12
|
+
if (absNum >= billion) {
|
|
13
|
+
return `${isNegative ? "-" : ""}${(absNum / billion).toFixed(1)}B`;
|
|
14
|
+
}
|
|
15
|
+
else if (absNum >= million) {
|
|
16
|
+
return `${isNegative ? "-" : ""}${(absNum / million).toFixed(1)}M`;
|
|
17
|
+
}
|
|
18
|
+
else if (absNum >= thousand) {
|
|
19
|
+
return `${isNegative ? "-" : ""}${(absNum / thousand).toFixed(1)}K`;
|
|
20
|
+
}
|
|
21
|
+
return `${isNegative ? "-" : ""}${absNum}`;
|
|
22
|
+
};
|
|
23
|
+
export default formatNumber;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a character is a CJK (Chinese, Japanese, Korean) character.
|
|
3
|
+
* @param char
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
const isCJKChar = (char) => {
|
|
7
|
+
const code = char.charCodeAt(0);
|
|
8
|
+
return ((code >= 0x4e00 && code <= 0x9fff) || // CJK Unified Ideographs
|
|
9
|
+
(code >= 0x3400 && code <= 0x4dbf) || // CJK Unified Ideographs Extension A
|
|
10
|
+
(code >= 0xf900 && code <= 0xfaff) || // CJK Compatibility Ideographs
|
|
11
|
+
(code >= 0x3040 && code <= 0x309f) || // Hiragana
|
|
12
|
+
(code >= 0x30a0 && code <= 0x30ff) // Katakana
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
export default isCJKChar;
|
package/dist/kyouka.d.ts
CHANGED
|
@@ -161,5 +161,8 @@ declare const kyoka: {
|
|
|
161
161
|
partialRight: (fn: Function, ...partials: any[]) => (...args: any[]) => any;
|
|
162
162
|
intersectionBy: <T>(...args: any[]) => T[];
|
|
163
163
|
sortBy: <T_1>(collection: T_1[], ...iteratees: (string | number | ((item: T_1) => any))[]) => T_1[];
|
|
164
|
+
formatNumber: (num: number) => string;
|
|
165
|
+
timeStringToSeconds: (time: string) => number | null;
|
|
166
|
+
isCJKChar: (char: string) => boolean;
|
|
164
167
|
};
|
|
165
168
|
export default kyoka;
|
package/dist/kyouka.js
CHANGED
|
@@ -41,6 +41,7 @@ import factorial from "./factorial";
|
|
|
41
41
|
import fileToBinaryString from "./fileToBinaryString";
|
|
42
42
|
import { findRecursive, findAllRecursive } from "./findRecursive";
|
|
43
43
|
import formatDuration from "./formatDuration";
|
|
44
|
+
import formatNumber from "./formatNumber";
|
|
44
45
|
import frequencies from "./frequencies";
|
|
45
46
|
import fromTimestamp from "./fromTimestamp";
|
|
46
47
|
import getCenterPointPos from "./getCenterPointPos";
|
|
@@ -65,6 +66,7 @@ import intersectionBy from "./intersectionBy";
|
|
|
65
66
|
import iosInputScrollFix from "./iosInputScrollFix";
|
|
66
67
|
import isBottomVisible from "./isBottomVisible";
|
|
67
68
|
import isElBottomVisible from "./isElBottomVisible";
|
|
69
|
+
import isCJKChar from "./isCJKChar";
|
|
68
70
|
import isEmpty from "./isEmpty";
|
|
69
71
|
import isEven from "./isEven";
|
|
70
72
|
import isIdcard from "./isIdcard";
|
|
@@ -130,6 +132,7 @@ import orderBy from "./orderBy";
|
|
|
130
132
|
import sum from "./sum";
|
|
131
133
|
import sumPower from "./sumPower";
|
|
132
134
|
import throttle from "./throttle";
|
|
135
|
+
import timeStringToSeconds from "./timeStringToSeconds";
|
|
133
136
|
import timeTaken from "./timeTaken";
|
|
134
137
|
import toFixed0 from "./toFixed0";
|
|
135
138
|
import toFixed1 from "./toFixed1";
|
|
@@ -291,5 +294,8 @@ const kyoka = {
|
|
|
291
294
|
partialRight,
|
|
292
295
|
intersectionBy,
|
|
293
296
|
sortBy,
|
|
297
|
+
formatNumber,
|
|
298
|
+
timeStringToSeconds,
|
|
299
|
+
isCJKChar,
|
|
294
300
|
};
|
|
295
301
|
export default kyoka;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a time string in the format "MM:SS" or "HH:MM:SS" to total seconds.
|
|
3
|
+
* @param time
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
const timeStringToSeconds = (time) => {
|
|
7
|
+
const timeParts = time.split(":").map(Number);
|
|
8
|
+
if (timeParts.length === 2) {
|
|
9
|
+
const [minutes, seconds] = timeParts;
|
|
10
|
+
return minutes * 60 + seconds;
|
|
11
|
+
}
|
|
12
|
+
else if (timeParts.length === 3) {
|
|
13
|
+
const [hours, minutes, seconds] = timeParts;
|
|
14
|
+
return hours * 3600 + minutes * 60 + seconds;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export default timeStringToSeconds;
|
package/package.json
CHANGED