qsu 1.3.0 → 1.3.1
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
- 100% optimized for the latest NodeJS and ESM environments.
|
|
12
12
|
- Useful features for websites and web applications
|
|
13
13
|
|
|
14
|
-
## [Documentation (Getting Started & Method Reference)](https://qsu.jooy2.com/getting-started)
|
|
14
|
+
## [Documentation (Getting Started & Method Reference)](https://qsu.jooy2.com/getting-started/installation)
|
|
15
15
|
|
|
16
|
-
Installing and using the package and defining all the utility methods can be found on the documentation page below: https://qsu.jooy2.com/getting-started
|
|
16
|
+
Installing and using the package and defining all the utility methods can be found on the documentation page below: https://qsu.jooy2.com/getting-started/installation
|
|
17
17
|
|
|
18
18
|
## Contribute
|
|
19
19
|
|
package/dist/index.d.ts
CHANGED
|
@@ -48,8 +48,8 @@ export default class Qsu {
|
|
|
48
48
|
static truncateExpect<N extends number>(str: string, expectLength: PositiveNumber<N>, endStringChar?: string): string;
|
|
49
49
|
static split(str: string, ...splitter: any[]): string[];
|
|
50
50
|
static split(str: string, ...splitter: Array<string>): string[];
|
|
51
|
-
static encrypt(str: string, secret: string, algorithm?: string, ivSize?: number): string;
|
|
52
|
-
static decrypt(str: string, secret: string, algorithm?: string): string;
|
|
51
|
+
static encrypt(str: string, secret: string, algorithm?: string, ivSize?: number, toBase64?: boolean): string;
|
|
52
|
+
static decrypt(str: string, secret: string, algorithm?: string, toBase64?: boolean): string;
|
|
53
53
|
static md5(str: string): string;
|
|
54
54
|
static sha1(str: string): string;
|
|
55
55
|
static sha256(str: string): string;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{basename as t,extname as e,win32 as r}from"path";import{randomBytes as a,createCipheriv as n,createDecipheriv as i,createHash as s}from"crypto";export default class o{static sleep(t){return new Promise((e=>{setTimeout(e,t)}))}static funcTimes(t,e){const r=[];for(let a=0;a<t;a+=1)r[a]="function"==typeof e?e.call():e;return r}static debounce(t,e){let r;return(...a)=>{clearTimeout(r),r=setTimeout((()=>{t.apply(this,a)}),e)}}static getPlatform(){switch(process.platform){case"win32":return"Windows";case"darwin":return"macOS";case"linux":case"aix":case"sunos":case"netbsd":case"openbsd":case"freebsd":case"cygwin":case"android":return"Linux";default:return"Unknown"}}static objectId(){return Math.floor(Date.now()/1e3).toString(16)+"x".repeat(16).replace(/x/g,(()=>Math.floor(16*Math.random()).toString(16)))}static numRandom(t,e){if(!t&&!e)return Math.random()>.5?1:0;const r=e||t,a=!e||t>=e?null:t;return Math.floor(Math.random()*(a?r-a+1:r+1))+(a||0)}static sum(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=0;for(let t=0,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r+=e[t]);return r}static mul(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r*=e[t]);return r}static sub(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r-=e[t]);return r}static div(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r/=e[t]);return r}static dayDiff(t,e){const r=e||new Date;return Math.ceil(Math.abs(r.getTime()-t.getTime())/864e5)}static today(t="-",e=!0){const r=new Date,a=r.getMonth()+1,n=r.getDate(),i=[`${a<10?"0":""}${a}`,`${n<10?"0":""}${n}`];return e?i.unshift(r.getFullYear().toString()):i.push(r.getFullYear().toString()),i.join(t)}static isValidDate(t){if(!/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(t))throw new Error("The date format must be 'YYYY-MM-DD'");const e=t.split("-");return/^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/.test(`${parseInt(e[2],10)}-${parseInt(e[1],10)}-${parseInt(e[0],10)}`)}static dateToYYYYMMDD(t,e="-"){const r=t.getMonth()+1,a=t.getDate();return`${t.getFullYear()}${e}${r<10?`0${r}`:r}${e}${a<10?`0${a}`:a}`}static createDateListFromRange(t,e){if(!o.isValidDate(o.dateToYYYYMMDD(t))||!o.isValidDate(o.dateToYYYYMMDD(e)))throw new Error("Either the start date or end date is an invalid date.");if(Math.floor((Date.parse(e.toString())-Date.parse(t.toString()))/864e5)<0)throw new Error("The start date is more recent than the end date.");const r=o.dateToYYYYMMDD(e),a=[];let n=t.getFullYear(),i=t.getMonth()+1,s=t.getDate(),c="";const l=(t,e,r)=>`${t}-${e<10?"0":""}${e}-${r<10?"0":""}${r}`;for(;r!==c;){-1!==c.indexOf("-12-31")&&(n+=1,i=1,s=1);const t=l(n,i,s);o.isValidDate(t)?(s+=1,a.push(t),c=t):(i+=1,s=1,c=l(n,i,s))}return a}static arrShuffle(t){if(1===t.length)return t[0];const e=t;for(let r=t.length-1;r>0;r-=1){const a=Math.floor(Math.random()*(r+1));[e[r],e[a]]=[t[a],t[r]]}return e}static arrWithDefault(t,e=0){return e<1?[]:Array(e).fill(t)}static arrUnique(t){return o.is2dArray(t)?Array.from(new Set(t.map((t=>JSON.stringify(t)))),(t=>JSON.parse(t))):[...new Set(t)]}static arrWithNumber(t,e){if(t>e)throw new Error("`end` is greater than `start`.");return Array.from({length:e-t+1},((e,r)=>r+t))}static average(t){return t.reduce(((t,e)=>t+e),0)/t.length}static arrMove(t,e,r){const a=t.length;if(a<=e||a<=r)throw new Error("Invalid move params");return t.splice(r,0,t.splice(e,1)[0]),t}static arrTo1dArray(t){const e=t=>{const r=[],a=t.length;for(let n=0;n<a;n+=1)"object"!=typeof t[n]?r.push(t[n]):o.is2dArray(t[n])?r.push(...e(t[n])):r.push(...t[n]);return r};return e(t)}static arrRepeat(t,e){if(!t||e<1||"object"!=typeof t)return[];const r=o.isObject(t),a=[];for(let n=0,i=e;n<i;n+=1)r?a.push(t):a.push(...t);return a}static arrCount(t){const e={};for(let r=0;r<t.length;r+=1){const a=t[r];e[a]=(e[a]||0)+1}return e}static sortByObjectKey(t,e,r=!1,a=!1){if(a){const a=new Intl.Collator([],{numeric:!0}),n=t.sort(((t,r)=>a.compare(t[e],r[e])));return r?n.reverse():n}return t.sort(((t,a)=>r?t[e]>a[e]?-1:t[e]<a[e]?1:0:t[e]<a[e]?-1:t[e]>a[e]?1:0))}static sortNumeric(t,e=!1){const r=new Intl.Collator([],{numeric:!0}),a=t.sort(((t,e)=>r.compare(t,e)));return e?a.reverse():a}static trim(t,e=!1){return t.trim().replace(e?/\s+/g:/\s{2,}/g,"")}static removeSpecialChar(t,e){return t?t.replace(new RegExp(`[^a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ0-9-ヿ㐀-䶿一-鿿豈-ヲ-゚${e??""}]`,"gi"),""):""}static replaceBetween(t,e,r,a=""){if(!t)return"";const n=/[.*+?^${}()|[\]\\]/g,i=n.test(e)?`\\${e}`:e,s=n.test(r)?`\\${r}`:r;return t.replace(new RegExp(`${i}.*?${s}`,"g"),a)}static removeNewLine(t,e=""){return t?t.replace(/(\r\n|\n|\r)/gm,e).trim():""}static capitalizeFirst(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""}static capitalizeEverySentence(t,e){if(!t)return"";const r=e||".",a=t.split(r);let n,i="";for(let t=0,e=a.length;t<e;t+=1){n=[...a[t]];for(let e=0,r=n.length;e<r;e+=1)if(/[a-zA-Z]/.test(a[t][e])){n[e]=a[t][e].toUpperCase();break}i+=`${n.join("")}${t<e-1?r:""}`}return i}static capitalizeEachWords(t,e){if(!t)return"";const r=t.trim().toLowerCase().split(" ");for(let t=0,a=r.length;t<a;t+=1)e&&o.contains(r[t],["in","on","the","at","and","or","of","for","to","that","a","by","it","is","as","are","were","was","nor","an"],!0)||(r[t]=o.capitalizeFirst(r[t]));return o.capitalizeFirst(r.join(" "))}static strCount(t,e){if(!t||!e)return 0;let r=0,a=t.indexOf(e);for(;a>-1;)r+=1,a=t.indexOf(e,a+=e.length);return r}static strShuffle(t){return t?[...t].sort((()=>Math.random()-.5)).join(""):""}static strRandom(t,e){const r=`abcdefghijklmnopqrstuvwxyz0123456789${e}`,a=r.length;let n,i="";for(let e=0;e<t;e+=1)n=r.charAt(Math.floor(Math.random()*a)),n=Math.random()<.5?n.toUpperCase():n,i+=n;return i}static strBlindRandom(t,e,r="*"){if(!t)return"";let a=t,n=0,i=0,s=0;const c=a.length;for(;n<e&&s<c;)i=o.numRandom(0,c),/[a-zA-Z가-힣]/.test(a.substring(i,i+1))&&(a=`${a.substring(0,i+1)}${r}${a.substring(i+2)}`,n+=1),s+=1;return a}static truncate(t,e,r=""){if(!t)return"";let a=t;return t.length>e&&(a=t.substring(0,e)+r),a}static truncateExpect(t,e,r="."){if(!t)return"";const a=t.slice(-1)===r,n=t.split(r),i=n.length;let s="",o=0;for(let t=0;t<i&&o<e;t+=1)s+=`${n[t]}${t!==i-1||a?r:""}`,o+=n[t].length+r.length;return s}static split(t,...e){if(!t)return[];const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;let n="",i="";for(let t=0;t<a;t+=1){const e=r[t];e.length>1?i+=`${i.length<1?"":"|"}${e.replace(/\\/g,"\\\\").replace(/\[/g,"\\[").replace(/]/g,"\\]").replace(/\?/g,"\\?").replace(/\./g,"\\.").replace(/\{/g,"\\{").replace(/}/g,"\\}").replace(/\+/g,"\\+")}`:n+="-"===e||"["===e||"]"===e?`\\${e}`:e}return n.length<1&&i.length<1?[t]:(n.length>0&&(n=`[${n}]`,i.length>0&&(i=`|${i}`)),t.split(new RegExp(`${n}${i}+`,"gi")))}static encrypt(t,e,r="aes-256-cbc",i=16){if(!t||t.length<1)return"";const s=a(i),o=n(r,e,s);let c=o.update(t);return c=Buffer.concat([c,o.final()]),`${s.toString("hex")}:${c.toString("hex")}`}static decrypt(t,e,r="aes-256-cbc"){if(!t||t.length<1)return"";const a=t.split(":"),n=i(r,e,Buffer.from(a.shift(),"hex"));let s=n.update(Buffer.from(a.join(":"),"hex"));return s=Buffer.concat([s,n.final()]),s.toString()}static md5(t){return s("md5").update(t).digest("hex")}static sha1(t){return s("sha1").update(t).digest("hex")}static sha256(t){return s("sha256").update(t).digest("hex")}static encodeBase64(t){return Buffer.from(t,"utf8").toString("base64")}static decodeBase64(t){return Buffer.from(t,"base64").toString("utf8")}static strToAscii(t){const e=[];for(let r=0;r<t.length;r+=1)e.push(t.charCodeAt(r));return e}static strUnique(t){return t?[...new Set(t)].join(""):""}static isObject(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}static isEqual(t,...e){const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;for(let e=0;e<a;e+=1)if(r[e]!=t)return!1;return!0}static isEqualStrict(t,...e){const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;for(let e=0;e<a;e+=1)if(r[e]!==t)return!1;return!0}static isEmpty(t){if(!t)return!0;switch(typeof t){case"string":return t.length<1;case"object":return Array.isArray(t)?t.length<1:Object.keys(t).length<1;default:return!1}}static isUrl(t,e=!1,r=!1){if(r&&-1===t.indexOf("."))return!1;try{new URL(`${e&&-1===t.indexOf("://")?"https://":""}${t}`).toString()}catch(t){return!1}return!0}static contains(t,e,r=!1){if("string"==typeof e)return!(t.length<1)&&-1!==t.indexOf(e);for(let a=0,n=e.length;a<n;a+=1)if(r){if(t===e[a])return!0}else if(-1!==t.indexOf(e[a]))return!0;return!1}static is2dArray(t){return t.filter(Array.isArray).length>0}static between(t,e,r=!1){const a=Math.min.apply(Math,[t[0],t[1]]),n=Math.max.apply(Math,[t[0],t[1]]);return r?e>=a&&e<=n:e>a&&e<n}static len(t){if(!t)return 0;switch(typeof t){case"object":return Array.isArray(t)?t.length:Object.keys(t).length;case"number":case"bigint":return t.toString().length;case"boolean":return t?4:5;case"function":return t().length;default:return t.length}}static isEmail(t){return/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(t)}static numberFormat(t){return(new Intl.NumberFormat).format(t)}static fileName(a,n=!1){return a?-1===a.indexOf("/")?n?r.basename(a):r.basename(a,e(a)):n?t(a):t(a,e(a)):""}static fileSize(t,e=2){if(!t||0===t||t<0)return"0 Bytes";const r=Math.floor(Math.log(t)/Math.log(1024));return`${parseFloat((t/1024**r).toFixed(e<0?0:e))} ${["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][r]}`}static fileExt(t){if(-1===t.indexOf("."))return"Unknown";const e=t.trim().toLowerCase().split(".");return e.length>0?e[e.length-1]:"Unknown"}static msToTime(t=0,e=!1,r=":"){const a=Math.floor(t%1e3/100);let n=Math.floor(t/1e3%60),i=Math.floor(t/6e4%60),s=Math.floor(t/36e5);return s=s<10?`0${s}`:s,i=i<10?`0${i}`:i,n=n<10?`0${n}`:n,`${s}${r}${i}${r}${n}${e?`.${a}`:""}`}static secToTime(t=0,e=!1,r=":"){let a=Math.floor(t%60),n=Math.floor(t/60%60),i=Math.floor(t/3600);return i=i<10?`0${i}`:i,n=n<10?`0${n}`:n,a=a<10?`0${a}`:a,e?i.toString():`${i}${r}${n}${r}${a}`}}export{o as Qsu};export const{sleep:sleep,funcTimes:funcTimes,debounce:debounce,getPlatform:getPlatform,objectId:objectId,numRandom:numRandom,sum:sum,mul:mul,sub:sub,div:div,dayDiff:dayDiff,today:today,isValidDate:isValidDate,dateToYYYYMMDD:dateToYYYYMMDD,createDateListFromRange:createDateListFromRange,arrShuffle:arrShuffle,arrWithDefault:arrWithDefault,arrUnique:arrUnique,arrWithNumber:arrWithNumber,arrRepeat:arrRepeat,arrCount:arrCount,average:average,arrMove:arrMove,arrTo1dArray:arrTo1dArray,sortByObjectKey:sortByObjectKey,sortNumeric:sortNumeric,trim:trim,replaceBetween:replaceBetween,removeSpecialChar:removeSpecialChar,removeNewLine:removeNewLine,capitalizeFirst:capitalizeFirst,capitalizeEverySentence:capitalizeEverySentence,capitalizeEachWords:capitalizeEachWords,strCount:strCount,strShuffle:strShuffle,strRandom:strRandom,strBlindRandom:strBlindRandom,truncate:truncate,truncateExpect:truncateExpect,split:split,encrypt:encrypt,decrypt:decrypt,md5:md5,sha1:sha1,sha256:sha256,encodeBase64:encodeBase64,decodeBase64:decodeBase64,strUnique:strUnique,strToAscii:strToAscii,isObject:isObject,isEqual:isEqual,isEqualStrict:isEqualStrict,isEmpty:isEmpty,isUrl:isUrl,contains:contains,is2dArray:is2dArray,between:between,len:len,isEmail:isEmail,numberFormat:numberFormat,fileName:fileName,fileSize:fileSize,fileExt:fileExt,msToTime:msToTime,secToTime:secToTime}=o;
|
|
1
|
+
import{basename as t,extname as e,win32 as r}from"path";import{randomBytes as a,createCipheriv as n,createDecipheriv as i,createHash as s}from"crypto";export default class o{static sleep(t){return new Promise((e=>{setTimeout(e,t)}))}static funcTimes(t,e){const r=[];for(let a=0;a<t;a+=1)r[a]="function"==typeof e?e.call():e;return r}static debounce(t,e){let r;return(...a)=>{clearTimeout(r),r=setTimeout((()=>{t.apply(this,a)}),e)}}static getPlatform(){switch(process.platform){case"win32":return"Windows";case"darwin":return"macOS";case"linux":case"aix":case"sunos":case"netbsd":case"openbsd":case"freebsd":case"cygwin":return"Linux";case"android":return"Android";default:return"Unknown"}}static objectId(){return Math.floor(Date.now()/1e3).toString(16)+"x".repeat(16).replace(/x/g,(()=>Math.floor(16*Math.random()).toString(16)))}static numRandom(t,e){if(!t&&!e)return Math.random()>.5?1:0;const r=e||t,a=!e||t>=e?null:t;return Math.floor(Math.random()*(a?r-a+1:r+1))+(a||0)}static sum(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=0;for(let t=0,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r+=e[t]);return r}static mul(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r*=e[t]);return r}static sub(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r-=e[t]);return r}static div(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=e[0];for(let t=1,a=e.length;t<a;t+=1)"number"==typeof e[t]&&(r/=e[t]);return r}static dayDiff(t,e){const r=e||new Date;return Math.ceil(Math.abs(r.getTime()-t.getTime())/864e5)}static today(t="-",e=!0){const r=new Date,a=r.getMonth()+1,n=r.getDate(),i=[`${a<10?"0":""}${a}`,`${n<10?"0":""}${n}`];return e?i.unshift(r.getFullYear().toString()):i.push(r.getFullYear().toString()),i.join(t)}static isValidDate(t){if(!/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(t))throw new Error("The date format must be 'YYYY-MM-DD'");const e=t.split("-");return/^(?=\d)(?:(?:31(?!.(?:0?[2469]|11))|(?:30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(?:\x20|$))|(?:2[0-8]|1\d|0?[1-9]))([-./])(?:1[012]|0?[1-9])\1(?:1[6-9]|[2-9]\d)?\d\d(?:(?=\x20\d)\x20|$))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/.test(`${parseInt(e[2],10)}-${parseInt(e[1],10)}-${parseInt(e[0],10)}`)}static dateToYYYYMMDD(t,e="-"){const r=t.getMonth()+1,a=t.getDate();return`${t.getFullYear()}${e}${r<10?`0${r}`:r}${e}${a<10?`0${a}`:a}`}static createDateListFromRange(t,e){if(!o.isValidDate(o.dateToYYYYMMDD(t))||!o.isValidDate(o.dateToYYYYMMDD(e)))throw new Error("Either the start date or end date is an invalid date.");if(Math.floor((Date.parse(e.toString())-Date.parse(t.toString()))/864e5)<0)throw new Error("The start date is more recent than the end date.");const r=o.dateToYYYYMMDD(e),a=[];let n=t.getFullYear(),i=t.getMonth()+1,s=t.getDate(),c="";const l=(t,e,r)=>`${t}-${e<10?"0":""}${e}-${r<10?"0":""}${r}`;for(;r!==c;){/[0-9]{4}-12-31/g.test(c)&&(n+=1,i=1,s=1);const t=l(n,i,s);o.isValidDate(t)?(s+=1,a.push(t),c=t):(i+=1,s=1,c=l(n,i,s))}return a}static arrShuffle(t){if(1===t.length)return t[0];const e=t;for(let r=t.length-1;r>0;r-=1){const a=Math.floor(Math.random()*(r+1));[e[r],e[a]]=[t[a],t[r]]}return e}static arrWithDefault(t,e=0){return e<1?[]:Array(e).fill(t)}static arrUnique(t){return o.is2dArray(t)?Array.from(new Set(t.map((t=>JSON.stringify(t)))),(t=>JSON.parse(t))):[...new Set(t)]}static arrWithNumber(t,e){if(t>e)throw new Error("`end` is greater than `start`.");return Array.from({length:e-t+1},((e,r)=>r+t))}static average(t){return t.reduce(((t,e)=>t+e),0)/t.length}static arrMove(t,e,r){const a=t.length;if(a<=e||a<=r)throw new Error("Invalid move params");return t.splice(r,0,t.splice(e,1)[0]),t}static arrTo1dArray(t){const e=t=>{const r=[],a=t.length;for(let n=0;n<a;n+=1)"object"!=typeof t[n]?r.push(t[n]):o.is2dArray(t[n])?r.push(...e(t[n])):r.push(...t[n]);return r};return e(t)}static arrRepeat(t,e){if(!t||e<1||"object"!=typeof t)return[];const r=o.isObject(t),a=[];for(let n=0,i=e;n<i;n+=1)r?a.push(t):a.push(...t);return a}static arrCount(t){const e={};for(let r=0;r<t.length;r+=1){const a=t[r];e[a]=(e[a]||0)+1}return e}static sortByObjectKey(t,e,r=!1,a=!1){if(a){const a=new Intl.Collator([],{numeric:!0}),n=t.sort(((t,r)=>a.compare(t[e],r[e])));return r?n.reverse():n}return t.sort(((t,a)=>r?t[e]>a[e]?-1:t[e]<a[e]?1:0:t[e]<a[e]?-1:t[e]>a[e]?1:0))}static sortNumeric(t,e=!1){const r=new Intl.Collator([],{numeric:!0}),a=t.sort(((t,e)=>r.compare(t,e)));return e?a.reverse():a}static trim(t,e=!1){return t.trim().replace(e?/\s+/g:/\s{2,}/g,"")}static removeSpecialChar(t,e){return t?t.replace(new RegExp(`[^a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ0-9-ヿ㐀-䶿一-鿿豈-ヲ-゚${e??""}]`,"gi"),""):""}static replaceBetween(t,e,r,a=""){if(!t)return"";const n=/[.*+?^${}()|[\]\\]/g,i=n.test(e)?`\\${e}`:e,s=n.test(r)?`\\${r}`:r;return t.replace(new RegExp(`${i}.*?${s}`,"g"),a)}static removeNewLine(t,e=""){return t?t.replace(/(\r\n|\n|\r)/gm,e).trim():""}static capitalizeFirst(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""}static capitalizeEverySentence(t,e){if(!t)return"";const r=e||".",a=t.split(r);let n,i="";for(let t=0,e=a.length;t<e;t+=1){n=[...a[t]];for(let e=0,r=n.length;e<r;e+=1)if(/[a-zA-Z]/.test(a[t][e])){n[e]=a[t][e].toUpperCase();break}i+=`${n.join("")}${t<e-1?r:""}`}return i}static capitalizeEachWords(t,e){if(!t)return"";const r=t.trim().toLowerCase().split(" ");for(let t=0,a=r.length;t<a;t+=1)e&&o.contains(r[t],["in","on","the","at","and","or","of","for","to","that","a","by","it","is","as","are","were","was","nor","an"],!0)||(r[t]=o.capitalizeFirst(r[t]));return o.capitalizeFirst(r.join(" "))}static strCount(t,e){if(!t||!e)return 0;let r=0,a=t.indexOf(e);for(;a>-1;)r+=1,a=t.indexOf(e,a+=e.length);return r}static strShuffle(t){return t?[...t].sort((()=>Math.random()-.5)).join(""):""}static strRandom(t,e){const r=`abcdefghijklmnopqrstuvwxyz0123456789${e}`,a=r.length;let n,i="";for(let e=0;e<t;e+=1)n=r.charAt(Math.floor(Math.random()*a)),n=Math.random()<.5?n.toUpperCase():n,i+=n;return i}static strBlindRandom(t,e,r="*"){if(!t)return"";let a=t,n=0,i=0,s=0;const c=a.length;for(;n<e&&s<c;)i=o.numRandom(0,c),/[a-zA-Z가-힣]/.test(a.substring(i,i+1))&&(a=`${a.substring(0,i+1)}${r}${a.substring(i+2)}`,n+=1),s+=1;return a}static truncate(t,e,r=""){if(!t)return"";let a=t;return t.length>e&&(a=t.substring(0,e)+r),a}static truncateExpect(t,e,r="."){if(!t)return"";const a=t.slice(-1)===r,n=t.split(r),i=n.length;let s="",o=0;for(let t=0;t<i&&o<e;t+=1)s+=`${n[t]}${t!==i-1||a?r:""}`,o+=n[t].length+r.length;return s}static split(t,...e){if(!t)return[];const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;let n="",i="";for(let t=0;t<a;t+=1){const e=r[t];e.length>1?i+=`${i.length<1?"":"|"}${e.replace(/\\/g,"\\\\").replace(/\[/g,"\\[").replace(/]/g,"\\]").replace(/\?/g,"\\?").replace(/\./g,"\\.").replace(/\{/g,"\\{").replace(/}/g,"\\}").replace(/\+/g,"\\+")}`:n+="-"===e||"["===e||"]"===e?`\\${e}`:e}return n.length<1&&i.length<1?[t]:(n.length>0&&(n=`[${n}]`,i.length>0&&(i=`|${i}`)),t.split(new RegExp(`${n}${i}+`,"gi")))}static encrypt(t,e,r="aes-256-cbc",i=16,s=!1){if(!t||t.length<1)return"";const o=a(i),c=n(r,e,o);let l=c.update(t);l=Buffer.concat([l,c.final()]);const u=s?"base64":"hex";return`${o.toString(u)}:${l.toString(u)}`}static decrypt(t,e,r="aes-256-cbc",a=!1){if(!t||t.length<1)return"";const n=a?"base64":"hex",s=t.split(":"),o=i(r,e,Buffer.from(s.shift(),n));let c=o.update(Buffer.from(s.join(":"),n));return c=Buffer.concat([c,o.final()]),c.toString()}static md5(t){return s("md5").update(t).digest("hex")}static sha1(t){return s("sha1").update(t).digest("hex")}static sha256(t){return s("sha256").update(t).digest("hex")}static encodeBase64(t){return Buffer.from(t,"utf8").toString("base64")}static decodeBase64(t){return Buffer.from(t,"base64").toString("utf8")}static strToAscii(t){const e=[];for(let r=0;r<t.length;r+=1)e.push(t.charCodeAt(r));return e}static strUnique(t){return t?[...new Set(t)].join(""):""}static isObject(t){return"object"==typeof t&&!Array.isArray(t)&&null!==t}static isEqual(t,...e){const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;for(let e=0;e<a;e+=1)if(r[e]!=t)return!1;return!0}static isEqualStrict(t,...e){const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;for(let e=0;e<a;e+=1)if(r[e]!==t)return!1;return!0}static isEmpty(t){if(!t)return!0;switch(typeof t){case"string":return t.length<1;case"object":return Array.isArray(t)?t.length<1:Object.keys(t).length<1;default:return!1}}static isUrl(t,e=!1,r=!1){if(r&&-1===t.indexOf("."))return!1;try{new URL(`${e&&-1===t.indexOf("://")?"https://":""}${t}`).toString()}catch(t){return!1}return!0}static contains(t,e,r=!1){if("string"==typeof e)return!(t.length<1)&&-1!==t.indexOf(e);for(let a=0,n=e.length;a<n;a+=1)if(r){if(t===e[a])return!0}else if(-1!==t.indexOf(e[a]))return!0;return!1}static is2dArray(t){return t.filter(Array.isArray).length>0}static between(t,e,r=!1){const a=Math.min.apply(Math,[t[0],t[1]]),n=Math.max.apply(Math,[t[0],t[1]]);return r?e>=a&&e<=n:e>a&&e<n}static len(t){if(!t)return 0;switch(typeof t){case"object":return Array.isArray(t)?t.length:Object.keys(t).length;case"number":case"bigint":return t.toString().length;case"boolean":return t?4:5;case"function":return t().length;default:return t.length}}static isEmail(t){return/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(t)}static numberFormat(t){return(new Intl.NumberFormat).format(t)}static fileName(a,n=!1){return a?-1===a.indexOf("/")?n?r.basename(a):r.basename(a,e(a)):n?t(a):t(a,e(a)):""}static fileSize(t,e=2){if(!t||0===t||t<0)return"0 Bytes";const r=Math.floor(Math.log(t)/Math.log(1024));return`${parseFloat((t/1024**r).toFixed(e<0?0:e))} ${["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][r]}`}static fileExt(t){if(-1===t.indexOf("."))return"Unknown";const e=t.trim().toLowerCase().split(".");return e.length>0?e[e.length-1]:"Unknown"}static msToTime(t=0,e=!1,r=":"){const a=Math.floor(t%1e3/100);let n=Math.floor(t/1e3%60),i=Math.floor(t/6e4%60),s=Math.floor(t/36e5);return s=s<10?`0${s}`:s,i=i<10?`0${i}`:i,n=n<10?`0${n}`:n,`${s}${r}${i}${r}${n}${e?`.${a}`:""}`}static secToTime(t=0,e=!1,r=":"){let a=Math.floor(t%60),n=Math.floor(t/60%60),i=Math.floor(t/3600);return i=i<10?`0${i}`:i,n=n<10?`0${n}`:n,a=a<10?`0${a}`:a,e?i.toString():`${i}${r}${n}${r}${a}`}}export{o as Qsu};export const{sleep:sleep,funcTimes:funcTimes,debounce:debounce,getPlatform:getPlatform,objectId:objectId,numRandom:numRandom,sum:sum,mul:mul,sub:sub,div:div,dayDiff:dayDiff,today:today,isValidDate:isValidDate,dateToYYYYMMDD:dateToYYYYMMDD,createDateListFromRange:createDateListFromRange,arrShuffle:arrShuffle,arrWithDefault:arrWithDefault,arrUnique:arrUnique,arrWithNumber:arrWithNumber,arrRepeat:arrRepeat,arrCount:arrCount,average:average,arrMove:arrMove,arrTo1dArray:arrTo1dArray,sortByObjectKey:sortByObjectKey,sortNumeric:sortNumeric,trim:trim,replaceBetween:replaceBetween,removeSpecialChar:removeSpecialChar,removeNewLine:removeNewLine,capitalizeFirst:capitalizeFirst,capitalizeEverySentence:capitalizeEverySentence,capitalizeEachWords:capitalizeEachWords,strCount:strCount,strShuffle:strShuffle,strRandom:strRandom,strBlindRandom:strBlindRandom,truncate:truncate,truncateExpect:truncateExpect,split:split,encrypt:encrypt,decrypt:decrypt,md5:md5,sha1:sha1,sha256:sha256,encodeBase64:encodeBase64,decodeBase64:decodeBase64,strUnique:strUnique,strToAscii:strToAscii,isObject:isObject,isEqual:isEqual,isEqualStrict:isEqualStrict,isEmpty:isEmpty,isUrl:isUrl,contains:contains,is2dArray:is2dArray,between:between,len:len,isEmail:isEmail,numberFormat:numberFormat,fileName:fileName,fileSize:fileSize,fileExt:fileExt,msToTime:msToTime,secToTime:secToTime}=o;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qsu",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "QSU is a lightweight and simple module with a variety of built-in utility functions that you can utilize in your NodeJS projects.",
|
|
5
5
|
"author": "Jooy2 <jooy2.contact@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,18 +56,18 @@
|
|
|
56
56
|
"file"
|
|
57
57
|
],
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@types/mocha": "^10.0.
|
|
60
|
-
"@types/node": "^20.
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
62
|
-
"@typescript-eslint/parser": "^6.
|
|
59
|
+
"@types/mocha": "^10.0.4",
|
|
60
|
+
"@types/node": "^20.9.0",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
62
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
63
63
|
"dayjs": "^1.11.10",
|
|
64
|
-
"eslint": "^8.
|
|
64
|
+
"eslint": "^8.53.0",
|
|
65
65
|
"eslint-config-airbnb": "^19.0.4",
|
|
66
66
|
"eslint-config-prettier": "^9.0.0",
|
|
67
|
-
"eslint-plugin-import": "^2.
|
|
67
|
+
"eslint-plugin-import": "^2.29.0",
|
|
68
68
|
"mocha": "^10.2.0",
|
|
69
69
|
"prettier": "^3.0.3",
|
|
70
|
-
"terser": "^5.
|
|
70
|
+
"terser": "^5.24.0",
|
|
71
71
|
"ts-node": "^10.9.1",
|
|
72
72
|
"typescript": "^5.2.2"
|
|
73
73
|
}
|