qsu 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,63 +2,50 @@
2
2
 
3
3
  ![logo](logo.webp)
4
4
 
5
- ### Node.js Quick & Simple Utility for JavaScript
6
-
7
- <table>
8
- <tr>
9
- <td>📑</td>
10
- <td>
11
-
12
- [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jooy2/qsu/blob/master/LICENSE)
13
- ![Programming Language Usage](https://img.shields.io/github/languages/top/jooy2/qsu)
14
- ![Commit Count](https://img.shields.io/github/commit-activity/y/jooy2/qsu)
15
- ![Line Count](https://img.shields.io/tokei/lines/github/jooy2/qsu)
16
-
17
- </td>
18
- </tr>
19
- <tr>
20
- <td>📊</td>
21
- <td>
22
-
23
- [![npm downloads](https://img.shields.io/npm/dm/qsu.svg)](https://www.npmjs.com/package/qsu)
24
- [![npm latest package](https://img.shields.io/npm/v/qsu/latest.svg)](https://www.npmjs.com/package/qsu)
25
- ![npm maintenance](https://img.shields.io/npms-io/maintenance-score/qsu)
26
- ![npm quality](https://img.shields.io/npms-io/quality-score/qsu)
27
- ![minified size](https://img.shields.io/bundlephobia/min/qsu)
28
- ![github repo size](https://img.shields.io/github/repo-size/jooy2/qsu)
29
-
30
- </td>
31
- </tr>
32
- <tr>
33
- <td>💕</td>
34
- <td>
35
-
36
- [![Followers](https://img.shields.io/github/followers/jooy2?style=social)](https://github.com/jooy2)
37
- ![Stars](https://img.shields.io/github/stars/jooy2/qsu?style=social)
38
-
39
- </td>
40
- </tr>
41
- </table>
5
+ ### Quick & Simple Utility for NodeJS
42
6
 
43
- </div>
7
+ > [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jooy2/qsu/blob/master/LICENSE) ![Programming Language Usage](https://img.shields.io/github/languages/top/jooy2/qsu) ![Commit Count](https://img.shields.io/github/commit-activity/y/jooy2/qsu) ![Line Count](https://img.shields.io/tokei/lines/github/jooy2/qsu) [![npm downloads](https://img.shields.io/npm/dm/qsu.svg)](https://www.npmjs.com/package/qsu) [![npm latest package](https://img.shields.io/npm/v/qsu/latest.svg)](https://www.npmjs.com/package/qsu) ![npm maintenance](https://img.shields.io/npms-io/maintenance-score/qsu) ![npm quality](https://img.shields.io/npms-io/quality-score/qsu) ![minified size](https://img.shields.io/bundlephobia/min/qsu) ![github repo size](https://img.shields.io/github/repo-size/jooy2/qsu) [![Followers](https://img.shields.io/github/followers/jooy2?style=social)](https://github.com/jooy2) ![Stars](https://img.shields.io/github/stars/jooy2/qsu?style=social)
44
8
 
45
- A collection of complex or useful features that are often used in **JavaScript**. It is implemented to be used in both a client or server environment.
9
+ </div>
46
10
 
47
- **qsu** is optimized for modern development environments, so older browsers such as Internet Explorer 11 and Legacy Edge (Not Chromium) may not support it unless you use a transcompiler. Some functions use ES6 or higher JS standard syntax.
11
+ **Qsu** is an underscore-based utility library optimized for the **[NodeJS](https://nodejs.org)** development environment. It is supported in one module without the need to separately write frequently used methods for each project.
48
12
 
49
- Some solutions partially referenced external documentation (e.g. [Stack Overflow](https://stackoverflow.com)).
13
+ - Lightweight and fast!
14
+ - Easy to install and use.
15
+ - 100% optimized for the latest NodeJS and ESM environments.
16
+ - Useful features for websites and web applications
50
17
 
51
18
  # Installation
52
19
 
53
- Qsu requires **Node.js 12.x** or higher, and the repository is serviced through **[NPM](https://npmjs.com)**.
20
+ Qsu requires `Node.js 12.x` or higher, and the repository is serviced through **[NPM](https://npmjs.com)**.
54
21
 
55
22
  After configuring the node environment, you can simply run the following command.
56
23
 
57
24
  ```bash
25
+ # via npm
58
26
  $ npm install qsu
27
+
28
+ # via yarn
29
+ $ yarn add qsu
30
+
31
+ # via pnpm
32
+ $ pnpm install qsu
59
33
  ```
60
34
 
61
- # Usage
35
+ # How to use
36
+
37
+ ### Using named import (Multiple utilities in a single require) - Recommend
38
+
39
+ ```javascript
40
+ import { today, strCount } from 'qsu';
41
+
42
+ function main() {
43
+ console.log(today()); // '20xx-xx-xx'
44
+ console.log(strCount('123412341234', '1')); // 3
45
+ }
46
+ ```
47
+
48
+ ### Using whole class (multiple utilities simultaneously with one object)
62
49
 
63
50
  ```javascript
64
51
  import _ from 'qsu';
@@ -84,6 +71,30 @@ _.sleep(5000).then(() => {
84
71
  });
85
72
  ```
86
73
 
74
+ ### `_.funcTimes (any[])`
75
+
76
+ Repeat iteratee n (times argument value) times. After the return result of each function is stored in the array in order, the final array is returned.
77
+
78
+ - `times::number`
79
+ - `iteratee::function`
80
+
81
+ ```javascript
82
+ function sayHi(str) {
83
+ return `Hi${str || ''}`;
84
+ }
85
+
86
+ _.funcTimes(3, sayHi); // Returns ['Hi', 'Hi', 'Hi']
87
+ _.funcTimes(4, () => sayHi('!')); // Returns ['Hi!', 'Hi!', 'Hi!', 'Hi!']
88
+ ```
89
+
90
+ ### `_.getPlatform (string)`
91
+
92
+ Returns the operating system of the currently running process as a human-friendly string.
93
+
94
+ ```javascript
95
+ _.getPlatform(); // Returns 'Windows'
96
+ ```
97
+
87
98
  ### `_.numRandom (number)`
88
99
 
89
100
  Returns a random number (Between min and max).
package/dist/index.d.ts CHANGED
@@ -9,9 +9,13 @@ declare interface LicenseOption {
9
9
  declare type PositiveNumber<N extends number> = number extends N ? N : `${N}` extends `-${string}` ? never : N;
10
10
  export default class Qsu {
11
11
  static sleep<N extends number>(delay: PositiveNumber<N>): Promise<void>;
12
+ static funcTimes<N extends number>(times: PositiveNumber<N>, iteratee: any): Array<any>;
13
+ static getPlatform(): string;
12
14
  static numRandom(min: number, max: number): number;
13
- static sum(...args: number[]): number;
14
- static mul(...args: number[]): number;
15
+ static sum(...args: any[]): number;
16
+ static sum(...args: Array<number>): number;
17
+ static mul(...args: any[]): number;
18
+ static mul(...args: Array<number>): number;
15
19
  static dayDiff(date1: Date, date2?: Date): number;
16
20
  static today(separator?: string, yearFirst?: boolean): string;
17
21
  static isRealDate(date: string | Date): boolean;
@@ -31,6 +35,7 @@ export default class Qsu {
31
35
  static strRandom<N extends number>(length: PositiveNumber<N>, additionalCharacters?: string): string;
32
36
  static strBlindRandom<N extends number>(str: string, blindLength: PositiveNumber<N>, blindStr?: string): string;
33
37
  static truncate<N extends number>(str: string, length: PositiveNumber<N>, ellipsis?: string): string;
38
+ static split(str: string, ...splitter: any[]): string[];
34
39
  static split(str: string, ...splitter: Array<string>): string[];
35
40
  static encrypt(str: string, secret: string, algorithm?: string, ivSize?: number): string;
36
41
  static decrypt(str: string, secret: string, algorithm?: string): string;
@@ -58,3 +63,4 @@ export default class Qsu {
58
63
  static license(options: LicenseOption): string;
59
64
  }
60
65
  export { Qsu };
66
+ export declare const sleep: typeof Qsu.sleep, funcTimes: typeof Qsu.funcTimes, getPlatform: typeof Qsu.getPlatform, numRandom: typeof Qsu.numRandom, sum: typeof Qsu.sum, mul: typeof Qsu.mul, dayDiff: typeof Qsu.dayDiff, today: typeof Qsu.today, isRealDate: typeof Qsu.isRealDate, arrShuffle: typeof Qsu.arrShuffle, arrWithDefault: typeof Qsu.arrWithDefault, arrUnique: typeof Qsu.arrUnique, arrWithNumber: typeof Qsu.arrWithNumber, average: typeof Qsu.average, arrMove: typeof Qsu.arrMove, trim: typeof Qsu.trim, removeSpecialChar: typeof Qsu.removeSpecialChar, removeNewLine: typeof Qsu.removeNewLine, capitalizeFirst: typeof Qsu.capitalizeFirst, capitalizeEachWords: typeof Qsu.capitalizeEachWords, strCount: typeof Qsu.strCount, strShuffle: typeof Qsu.strShuffle, strRandom: typeof Qsu.strRandom, strBlindRandom: typeof Qsu.strBlindRandom, truncate: typeof Qsu.truncate, split: typeof Qsu.split, encrypt: typeof Qsu.encrypt, decrypt: typeof Qsu.decrypt, md5: typeof Qsu.md5, sha1: typeof Qsu.sha1, sha256: typeof Qsu.sha256, encodeBase64: typeof Qsu.encodeBase64, decodeBase64: typeof Qsu.decodeBase64, strUnique: typeof Qsu.strUnique, isEqual: typeof Qsu.isEqual, isEqualStrict: typeof Qsu.isEqualStrict, isEmpty: typeof Qsu.isEmpty, isUrl: typeof Qsu.isUrl, contains: typeof Qsu.contains, is2dArray: typeof Qsu.is2dArray, between: typeof Qsu.between, len: typeof Qsu.len, isBotAgent: typeof Qsu.isBotAgent, numberFormat: typeof Qsu.numberFormat, fileName: typeof Qsu.fileName, fileSize: typeof Qsu.fileSize, fileExt: typeof Qsu.fileExt, msToTime: typeof Qsu.msToTime, secToTime: typeof Qsu.secToTime, license: typeof Qsu.license;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{basename as t,extname as e,win32 as r}from"path";import{randomBytes as o,createCipheriv as n,createDecipheriv as i,createHash as a}from"crypto";export default class s{static sleep(t){return new Promise((e=>{setTimeout(e,t)}))}static numRandom(t,e){if(!t&&!e)return Math.random()>.5?1:0;const r=e||t,o=!e||t>=e?null:t;return Math.floor(Math.random()*(o?r-o+1:r+1))+(o||0)}static sum(...t){const e=t.length>0&&"object"==typeof t[0]?t[0]:t;let r=0;for(let t=0,o=e.length;t<o;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,o=e.length;t<o;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,o=r.getMonth()+1,n=r.getDate(),i=[`${o<10?"0":""}${o}`,`${n<10?"0":""}${n}`];return e?i.unshift(r.getFullYear().toString()):i.push(r.getFullYear().toString()),i.join(t)}static isRealDate(t){const e="string"==typeof t?new Date(t):t;return!!e.getTime()&&e.toISOString().slice(0,10)===t}static arrShuffle(t){if(1===t.length)return t[0];const e=t;for(let r=t.length-1;r>0;r-=1){const o=Math.floor(Math.random()*(r+1));[e[r],e[o]]=[t[o],t[r]]}return e}static arrWithDefault(t,e=0){return e<1?[]:Array(e).fill(t)}static arrUnique(t){return this.is2dArray(t)?t.map((t=>JSON.stringify(t))).reverse().filter(((t,e,r)=>-1===r.indexOf(t,e+1))).reverse().map((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 o=t.length;if(o<=e||o<=r)throw new Error("Invalid move params");return t.splice(r,0,t.splice(e,1)[0]),t}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 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 capitalizeEachWords(t,e){if(!t)return"";const r=t.trim().toLowerCase().split(" ");for(let t=0,o=r.length;t<o;t+=1)e&&this.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]=this.capitalizeFirst(r[t]));return this.capitalizeFirst(r.join(" "))}static strCount(t,e){if(!t||!e)return 0;let r=0,o=t.indexOf(e);for(;o>-1;)r+=1,o=t.indexOf(e,o+=e.length);return r}static strShuffle(t){return t?[...t].sort((()=>Math.random()-.5)).join(""):""}static strRandom(t,e){const r=`abcdefghijklmnopqrstuvwxyz0123456789${e}`,o=r.length;let n,i="";for(let e=0;e<t;e+=1)n=r.charAt(Math.floor(Math.random()*o)),n=Math.random()<.5?n.toUpperCase():n,i+=n;return i}static strBlindRandom(t,e,r="*"){if(!t)return"";let o=t,n=0,i=0,a=0;const s=o.length;for(;n<e&&a<s;)i=this.numRandom(0,s),/[a-zA-Z가-힣]/.test(o.substring(i,i+1))&&(o=`${o.substring(0,i+1)}${r}${o.substring(i+2)}`,n+=1),a+=1;return o}static truncate(t,e,r=""){if(!t)return"";let o=t;return t.length>e&&(o=t.substring(0,e)+r),o}static split(t,...e){if(!t)return[];const r=e.length>0&&"object"==typeof e[0]?e[0]:e,o=r.length;let n="",i="";for(let t=0;t<o;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 a=o(i),s=n(r,e,a);let c=s.update(t);return c=Buffer.concat([c,s.final()]),`${a.toString("hex")}:${c.toString("hex")}`}static decrypt(t,e,r="aes-256-cbc"){if(!t||t.length<1)return"";const o=t.split(":"),n=i(r,e,Buffer.from(o.shift(),"hex"));let a=n.update(Buffer.from(o.join(":"),"hex"));return a=Buffer.concat([a,n.final()]),a.toString()}static md5(t){return a("md5").update(t).digest("hex")}static sha1(t){return a("sha1").update(t).digest("hex")}static sha256(t){return a("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 strUnique(t){return t?[...new Set(t)].join(""):""}static isEqual(t,...e){const r=e.length>0&&"object"==typeof e[0]?e[0]:e,o=r.length;for(let e=0;e<o;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,o=r.length;for(let e=0;e<o;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 o=0,n=e.length;o<n;o+=1)if(r){if(t===e[o])return!0}else if(-1!==t.indexOf(e[o]))return!0;return!1}static is2dArray(t){return t.filter(Array.isArray).length>0}static between(t,e,r=!1){const o=Math.min.apply(Math,[t[0],t[1]]),n=Math.max.apply(Math,[t[0],t[1]]);return r?e>=o&&e<=n:e>o&&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 isBotAgent(t){return/bot|naverbot|google|Googlebot|Googlebot-Mobile|Googlebot-Image|Google favicon|Chrome-Lighthouse|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis/i.test(t)}static numberFormat(t){return(new Intl.NumberFormat).format(t)}static fileName(o,n=!1){return o?-1===o.indexOf("/")?n?r.basename(o):r.basename(o,e(o)):n?t(o):t(o,e(o)):""}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 o=Math.floor(t%1e3/100);let n=Math.floor(t/1e3%60),i=Math.floor(t/6e4%60),a=Math.floor(t/36e5);return a=a<10?`0${a}`:a,i=i<10?`0${i}`:i,n=n<10?`0${n}`:n,`${a}${r}${i}${r}${n}${e?`.${o}`:""}`}static secToTime(t=0,e=!1,r=":"){let o=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,o=o<10?`0${o}`:o,e?i.toString():`${i}${r}${n}${r}${o}`}static license(t){const e=t.htmlBr?"<br/>":"\n",r=`${t.yearStart}${t.yearEnd?`-${t.yearEnd}`:""}`,o=`${t.author}${t.email?` <${t.email}>`:""}`;return"apache20"===t.type.replace(/\.-_,\s/g,"").toLowerCase()?`Copyright ${r} ${o}${e}${e}Licensed under the Apache License, Version 2.0 (the "License");${e}you may not use this file except in compliance with the License.${e}You may obtain a copy of the License at${e}${e} http://www.apache.org/licenses/LICENSE-2.0${e}${e}Unless required by applicable law or agreed to in writing, software${e}distributed under the License is distributed on an "AS IS" BASIS,${e}WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.${e}See the License for the specific language governing permissions and${e}limitations under the License.`:`Copyright (c) ${r} ${o}${e}${e}Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:${e}${e}The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.${e}${e}THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.`}}export{s as Qsu};
1
+ import{basename as t,extname as e,win32 as r}from"path";import{randomBytes as a,createCipheriv as i,createDecipheriv as n,createHash as o}from"crypto";export default class s{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 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 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 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,i=r.getDate(),n=[`${a<10?"0":""}${a}`,`${i<10?"0":""}${i}`];return e?n.unshift(r.getFullYear().toString()):n.push(r.getFullYear().toString()),n.join(t)}static isRealDate(t){const e="string"==typeof t?new Date(t):t;return!!e.getTime()&&e.toISOString().slice(0,10)===t}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 s.is2dArray(t)?t.map((t=>JSON.stringify(t))).reverse().filter(((t,e,r)=>-1===r.indexOf(t,e+1))).reverse().map((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 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 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 capitalizeEachWords(t,e){if(!t)return"";const r=t.trim().toLowerCase().split(" ");for(let t=0,a=r.length;t<a;t+=1)e&&s.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]=s.capitalizeFirst(r[t]));return s.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 i,n="";for(let e=0;e<t;e+=1)i=r.charAt(Math.floor(Math.random()*a)),i=Math.random()<.5?i.toUpperCase():i,n+=i;return n}static strBlindRandom(t,e,r="*"){if(!t)return"";let a=t,i=0,n=0,o=0;const c=a.length;for(;i<e&&o<c;)n=s.numRandom(0,c),/[a-zA-Z가-힣]/.test(a.substring(n,n+1))&&(a=`${a.substring(0,n+1)}${r}${a.substring(n+2)}`,i+=1),o+=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 split(t,...e){if(!t)return[];const r=e.length>0&&"object"==typeof e[0]?e[0]:e,a=r.length;let i="",n="";for(let t=0;t<a;t+=1){const e=r[t];e.length>1?n+=`${n.length<1?"":"|"}${e.replace(/\\/g,"\\\\").replace(/\[/g,"\\[").replace(/]/g,"\\]").replace(/\?/g,"\\?").replace(/\./g,"\\.").replace(/\{/g,"\\{").replace(/}/g,"\\}").replace(/\+/g,"\\+")}`:i+="-"===e||"["===e||"]"===e?`\\${e}`:e}return i.length<1&&n.length<1?[t]:(i.length>0&&(i=`[${i}]`,n.length>0&&(n=`|${n}`)),t.split(new RegExp(`${i}${n}+`,"gi")))}static encrypt(t,e,r="aes-256-cbc",n=16){if(!t||t.length<1)return"";const o=a(n),s=i(r,e,o);let c=s.update(t);return c=Buffer.concat([c,s.final()]),`${o.toString("hex")}:${c.toString("hex")}`}static decrypt(t,e,r="aes-256-cbc"){if(!t||t.length<1)return"";const a=t.split(":"),i=n(r,e,Buffer.from(a.shift(),"hex"));let o=i.update(Buffer.from(a.join(":"),"hex"));return o=Buffer.concat([o,i.final()]),o.toString()}static md5(t){return o("md5").update(t).digest("hex")}static sha1(t){return o("sha1").update(t).digest("hex")}static sha256(t){return o("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 strUnique(t){return t?[...new Set(t)].join(""):""}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,i=e.length;a<i;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]]),i=Math.max.apply(Math,[t[0],t[1]]);return r?e>=a&&e<=i:e>a&&e<i}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 isBotAgent(t){return/bot|naverbot|google|Googlebot|Googlebot-Mobile|Googlebot-Image|Google favicon|Chrome-Lighthouse|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis/i.test(t)}static numberFormat(t){return(new Intl.NumberFormat).format(t)}static fileName(a,i=!1){return a?-1===a.indexOf("/")?i?r.basename(a):r.basename(a,e(a)):i?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 i=Math.floor(t/1e3%60),n=Math.floor(t/6e4%60),o=Math.floor(t/36e5);return o=o<10?`0${o}`:o,n=n<10?`0${n}`:n,i=i<10?`0${i}`:i,`${o}${r}${n}${r}${i}${e?`.${a}`:""}`}static secToTime(t=0,e=!1,r=":"){let a=Math.floor(t%60),i=Math.floor(t/60%60),n=Math.floor(t/3600);return n=n<10?`0${n}`:n,i=i<10?`0${i}`:i,a=a<10?`0${a}`:a,e?n.toString():`${n}${r}${i}${r}${a}`}static license(t){const e=t.htmlBr?"<br/>":"\n",r=`${t.yearStart}${t.yearEnd?`-${t.yearEnd}`:""}`,a=`${t.author}${t.email?` <${t.email}>`:""}`;return"apache20"===t.type.replace(/\.-_,\s/g,"").toLowerCase()?`Copyright ${r} ${a}${e}${e}Licensed under the Apache License, Version 2.0 (the "License");${e}you may not use this file except in compliance with the License.${e}You may obtain a copy of the License at${e}${e} http://www.apache.org/licenses/LICENSE-2.0${e}${e}Unless required by applicable law or agreed to in writing, software${e}distributed under the License is distributed on an "AS IS" BASIS,${e}WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.${e}See the License for the specific language governing permissions and${e}limitations under the License.`:`Copyright (c) ${r} ${a}${e}${e}Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:${e}${e}The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.${e}${e}THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.`}}export{s as Qsu};export const{sleep:sleep,funcTimes:funcTimes,getPlatform:getPlatform,numRandom:numRandom,sum:sum,mul:mul,dayDiff:dayDiff,today:today,isRealDate:isRealDate,arrShuffle:arrShuffle,arrWithDefault:arrWithDefault,arrUnique:arrUnique,arrWithNumber:arrWithNumber,average:average,arrMove:arrMove,trim:trim,removeSpecialChar:removeSpecialChar,removeNewLine:removeNewLine,capitalizeFirst:capitalizeFirst,capitalizeEachWords:capitalizeEachWords,strCount:strCount,strShuffle:strShuffle,strRandom:strRandom,strBlindRandom:strBlindRandom,truncate:truncate,split:split,encrypt:encrypt,decrypt:decrypt,md5:md5,sha1:sha1,sha256:sha256,encodeBase64:encodeBase64,decodeBase64:decodeBase64,strUnique:strUnique,isEqual:isEqual,isEqualStrict:isEqualStrict,isEmpty:isEmpty,isUrl:isUrl,contains:contains,is2dArray:is2dArray,between:between,len:len,isBotAgent:isBotAgent,numberFormat:numberFormat,fileName:fileName,fileSize:fileSize,fileExt:fileExt,msToTime:msToTime,secToTime:secToTime,license:license}=s;
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "qsu",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Quick and Simple Utility for JavaScript",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "npm run format:fix && tsc && npm run minify",
9
- "test": "npm run build && mocha --parallel test/*.spec.js",
9
+ "test": "npm run build && mocha test/**/*.spec.ts -r ts-node/register --loader=ts-node/esm --timeout 10000",
10
10
  "lint": "eslint .",
11
11
  "lint:fix": "eslint --fix .",
12
- "minify": "terser dist/index.js --config-file terser.config.json -o dist/index.js",
12
+ "minify": "terser dist/index.js --config-file .terserrc -o dist/index.js",
13
13
  "prepare": "npm run build",
14
14
  "format": "prettier .",
15
15
  "format:fix": "prettier . --write"
@@ -52,17 +52,19 @@
52
52
  "file"
53
53
  ],
54
54
  "devDependencies": {
55
- "@types/node": "^18.11.2",
55
+ "@types/mocha": "^10.0.0",
56
+ "@types/node": "^18.11.3",
56
57
  "@typescript-eslint/eslint-plugin": "^5.40.1",
57
58
  "@typescript-eslint/parser": "^5.40.1",
58
59
  "date-fns": "^2.29.3",
59
- "eslint": "^8.25.0",
60
+ "eslint": "^8.26.0",
60
61
  "eslint-config-airbnb": "^19.0.4",
61
62
  "eslint-config-prettier": "^8.5.0",
62
63
  "eslint-plugin-import": "^2.26.0",
63
64
  "mocha": "^10.1.0",
64
65
  "prettier": "^2.7.1",
65
66
  "terser": "^5.15.1",
67
+ "ts-node": "^10.9.1",
66
68
  "typescript": "^4.8.4"
67
69
  }
68
70
  }
package/.prettierignore DELETED
@@ -1,4 +0,0 @@
1
- dist/
2
- .idea/
3
-
4
- package-lock.json
package/.prettierrc DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "printWidth": 100,
3
- "tabWidth": 2,
4
- "singleQuote": true,
5
- "quoteProps": "as-needed",
6
- "trailingComma": "none",
7
- "bracketSpacing": true,
8
- "bracketSameLine": false,
9
- "arrowParens": "always",
10
- "insertPragma": false,
11
- "requirePragma": false,
12
- "proseWrap": "never",
13
- "htmlWhitespaceSensitivity": "strict",
14
- "endOfLine": "lf"
15
- }