qsu 1.0.4 → 1.0.7

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) jooy2.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE
1
+ MIT License
2
+
3
+ Copyright (c) jooy2.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  <div align="center">
2
2
 
3
3
  ![logo](qsu-logo.png)
4
+
4
5
  ### Node.js Quick & Simple Utility for JavaScript
5
6
 
6
7
  [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jooy2/qsu/blob/master/LICENSE)
@@ -10,19 +11,22 @@
10
11
  ![github repo size](https://img.shields.io/github/repo-size/jooy2/qsu)
11
12
  [![npm downloads](https://img.shields.io/npm/dm/qsu.svg)](https://www.npmjs.com/package/qsu)
12
13
  [![Followers](https://img.shields.io/github/followers/jooy2?style=social)](https://github.com/jooy2)
14
+ ![Stars](https://img.shields.io/github/stars/jooy2/qsu?style=social)
15
+ ![Commit Count](https://img.shields.io/github/commit-activity/y/jooy2/qsu)
16
+ ![Line Count](https://img.shields.io/tokei/lines/github/jooy2/qsu)
13
17
  </div>
14
18
 
15
- 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.
19
+ 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.
16
20
 
17
- 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.
21
+ **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.
18
22
 
19
23
  Some solutions partially referenced external documentation (e.g. [Stack Overflow](https://stackoverflow.com)).
20
24
 
21
25
  # Installation
22
- Qsu requires Node.js 14.x or higher, and the repository is serviced through NPM.
26
+ Qsu requires **Node.js 14.x** or higher, and the repository is serviced through **[NPM](https://npmjs.com)**.
23
27
  After configuring the node environment, you can simply run the following command.
24
28
  ```bash
25
- $ npm i --save qsu
29
+ $ npm i qsu
26
30
  ```
27
31
 
28
32
  # Usage
@@ -264,7 +268,7 @@ _.truncate('hello', 3); // Returns 'hel'
264
268
  _.truncate('hello', 2, '...'); // Returns 'he...'
265
269
  ```
266
270
 
267
- ### `_.split (string)`
271
+ ### `_.split (string[])`
268
272
 
269
273
  Splits a string based on the specified character and returns it as an Array. Unlike the existing split, it splits the values provided as multiple parameters (array or multiple arguments) at once.
270
274
  - `str::string`
@@ -354,6 +358,41 @@ Remove duplicate characters from a given string and output only one.
354
358
  _.strUnique('aaabbbcc'); // Returns 'abc'
355
359
  ```
356
360
 
361
+ ### `_.isEqual (boolean)`
362
+
363
+ It compares the first argument value as the left operand and the argument values given thereafter as the right operand, and returns `true` if the values are all the same.
364
+
365
+ `isEqual` returns `true` even if the data types do not match, but `isEqualStrict` returns `true` only when the data types of all argument values match.
366
+ - `leftOperand::any`
367
+ - `rightOperand::any||any[]||...any`
368
+
369
+ ```javascript
370
+ const val1 = 'Left';
371
+ const val2 = 1;
372
+
373
+ _.isEqual('Left', 'Left', val1); // Returns true
374
+ _.isEqual(1, [1, '1', 1, val2]); // Returns true
375
+ _.isEqual(val1, ['Right', 'Left', 1]); // Returns false
376
+ _.isEqual(1, 1, 1, 1); // Returns true
377
+ ```
378
+
379
+ ### `_.isEqualStrict (boolean)`
380
+
381
+ It compares the first argument value as the left operand and the argument values given thereafter as the right operand, and returns `true` if the values are all the same.
382
+
383
+ `isEqual` returns `true` even if the data types do not match, but `isEqualStrict` returns `true` only when the data types of all argument values match.
384
+ - `leftOperand::any`
385
+ - `rightOperand::any||any[]||...any`
386
+
387
+ ```javascript
388
+ const val1 = 'Left';
389
+ const val2 = 1;
390
+
391
+ _.isEqualStrict('Left', 'Left', val1); // Returns true
392
+ _.isEqualStrict(1, [1, '1', 1, val2]); // Returns false
393
+ _.isEqualStrict(1, 1, '1', 1); // Returns false
394
+ ```
395
+
357
396
  ### `_.isEmpty (boolean)`
358
397
 
359
398
  Returns true if the passed data is empty or has a length of 0.
@@ -520,7 +559,7 @@ _.license({
520
559
  ```
521
560
 
522
561
  # Contribute
523
- You can report issues on GitHub Issue. You can also request a pull to fix bugs and add frequently used features.
562
+ You can report issues on [GitHub Issue Tracker](https://github.com/jooy2/qsu/issues). You can also request a pull to fix bugs and add frequently used features.
524
563
 
525
564
  # License
526
- Copyright © 2021 Jooy2 Released under the MIT license.
565
+ Copyright © 2021-2022 Jooy2 Released under the MIT license.
package/dist/index.d.ts CHANGED
@@ -30,7 +30,7 @@ export default class Qsu {
30
30
  static strRandom<N extends number>(length: PositiveNumber<N>, additionalCharacters?: string): string;
31
31
  static strBlindRandom<N extends number>(str: string, blindLength: PositiveNumber<N>, blindStr?: string): string;
32
32
  static truncate<N extends number>(str: string, length: PositiveNumber<N>, ellipsis?: string): string;
33
- static split(str: string, ...splitter: Array<string>): string | string[];
33
+ static split(str: string, ...splitter: Array<string>): string[];
34
34
  static encrypt(str: string, secret: string, algorithm?: string, ivSize?: number): string;
35
35
  static decrypt(str: string, secret: string, algorithm?: string): string;
36
36
  static md5(str: string): string;
@@ -39,6 +39,8 @@ export default class Qsu {
39
39
  static encodeBase64(str: string): string;
40
40
  static decodeBase64(encodedStr: string): string;
41
41
  static strUnique(str: string): string;
42
+ static isEqual(leftOperand: any, ...rightOperand: Array<any>): boolean;
43
+ static isEqualStrict(leftOperand: any, ...rightOperand: Array<any>): boolean;
42
44
  static isEmpty(data?: any): boolean;
43
45
  static isUrl(url: string, withProtocol?: boolean, strict?: boolean): boolean;
44
46
  static contains(str: any[] | string, search: any[] | string, exact?: boolean): boolean;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import path from 'path';
2
- import crypto from 'crypto';
1
+ import { basename, extname } from 'path';
2
+ import { randomBytes, createCipheriv, createDecipheriv, createHash, } from 'crypto';
3
3
  export default class Qsu {
4
4
  /*
5
5
  * Misc
@@ -208,7 +208,7 @@ export default class Qsu {
208
208
  }
209
209
  }
210
210
  if (charPattern.length < 1 && strPattern.length < 1) {
211
- return str;
211
+ return [str];
212
212
  }
213
213
  if (charPattern.length > 0) {
214
214
  charPattern = `[${charPattern}]`;
@@ -222,8 +222,8 @@ export default class Qsu {
222
222
  if (!str || str.length < 1) {
223
223
  return '';
224
224
  }
225
- const iv = crypto.randomBytes(ivSize);
226
- const cipher = crypto.createCipheriv(algorithm, secret, iv);
225
+ const iv = randomBytes(ivSize);
226
+ const cipher = createCipheriv(algorithm, secret, iv);
227
227
  let enc = cipher.update(str);
228
228
  enc = Buffer.concat([enc, cipher.final()]);
229
229
  return `${iv.toString('hex')}:${enc.toString('hex')}`;
@@ -233,19 +233,19 @@ export default class Qsu {
233
233
  return '';
234
234
  }
235
235
  const arrStr = str.split(':');
236
- const decipher = crypto.createDecipheriv(algorithm, secret, Buffer.from(arrStr.shift(), 'hex'));
236
+ const decipher = createDecipheriv(algorithm, secret, Buffer.from(arrStr.shift(), 'hex'));
237
237
  let decrypted = decipher.update(Buffer.from(arrStr.join(':'), 'hex'));
238
238
  decrypted = Buffer.concat([decrypted, decipher.final()]);
239
239
  return decrypted.toString();
240
240
  }
241
241
  static md5(str) {
242
- return crypto.createHash('md5').update(str).digest('hex');
242
+ return createHash('md5').update(str).digest('hex');
243
243
  }
244
244
  static sha1(str) {
245
- return crypto.createHash('sha1').update(str).digest('hex');
245
+ return createHash('sha1').update(str).digest('hex');
246
246
  }
247
247
  static sha256(str) {
248
- return crypto.createHash('sha256').update(str).digest('hex');
248
+ return createHash('sha256').update(str).digest('hex');
249
249
  }
250
250
  static encodeBase64(str) {
251
251
  return Buffer.from(str, 'utf8').toString('base64');
@@ -259,6 +259,27 @@ export default class Qsu {
259
259
  /*
260
260
  * Verify
261
261
  * */
262
+ static isEqual(leftOperand, ...rightOperand) {
263
+ const rightOperands = rightOperand.length > 0 && typeof rightOperand[0] === 'object' ? rightOperand[0] : rightOperand;
264
+ const rightOperandLength = rightOperands.length;
265
+ for (let i = 0; i < rightOperandLength; i += 1) {
266
+ // eslint-disable-next-line eqeqeq
267
+ if (rightOperands[i] != leftOperand) {
268
+ return false;
269
+ }
270
+ }
271
+ return true;
272
+ }
273
+ static isEqualStrict(leftOperand, ...rightOperand) {
274
+ const rightOperands = rightOperand.length > 0 && typeof rightOperand[0] === 'object' ? rightOperand[0] : rightOperand;
275
+ const rightOperandLength = rightOperands.length;
276
+ for (let i = 0; i < rightOperandLength; i += 1) {
277
+ if (rightOperands[i] !== leftOperand) {
278
+ return false;
279
+ }
280
+ }
281
+ return true;
282
+ }
262
283
  static isEmpty(data) {
263
284
  if (!data) {
264
285
  return true;
@@ -289,7 +310,7 @@ export default class Qsu {
289
310
  }
290
311
  static contains(str, search, exact = false) {
291
312
  if (typeof search === 'string') {
292
- return str.indexOf(search) !== -1;
313
+ return str.length < 1 ? false : str.indexOf(search) !== -1;
293
314
  }
294
315
  for (let i = 0, iLen = search.length; i < iLen; i += 1) {
295
316
  if (exact) {
@@ -331,7 +352,7 @@ export default class Qsu {
331
352
  }
332
353
  }
333
354
  static isBotAgent(userAgent) {
334
- return /bot|naverbot|google|Googlebot|Googlebot-Mobile|Googlebot-Image|Google favicon|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|dotbot|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|Twitterbot|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(userAgent);
355
+ 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|dotbot|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|Twitterbot|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(userAgent);
335
356
  }
336
357
  /*
337
358
  * Format
@@ -341,9 +362,9 @@ export default class Qsu {
341
362
  }
342
363
  static fileName(filePath, withExtension = false) {
343
364
  if (withExtension) {
344
- return path.basename(filePath);
365
+ return basename(filePath);
345
366
  }
346
- return path.basename(filePath, path.extname(filePath));
367
+ return basename(filePath, extname(filePath));
347
368
  }
348
369
  static fileSize(bytes, decimals = 2) {
349
370
  if (bytes === 0 || bytes < 0) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qsu",
3
- "version": "1.0.4",
4
- "description": "Quick and Simple Utility for javascript",
3
+ "version": "1.0.7",
4
+ "description": "Quick and Simple Utility for JavaScript",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
@@ -43,15 +43,15 @@
43
43
  "math"
44
44
  ],
45
45
  "devDependencies": {
46
- "@types/node": "^18.0.0",
47
- "@typescript-eslint/eslint-plugin": "^5.28.0",
48
- "@typescript-eslint/parser": "^5.28.0",
49
- "date-fns": "^2.28.0",
50
- "eslint": "^8.17.0",
46
+ "@types/node": "^18.0.6",
47
+ "@typescript-eslint/eslint-plugin": "^5.30.7",
48
+ "@typescript-eslint/parser": "^5.30.7",
49
+ "date-fns": "^2.29.1",
50
+ "eslint": "^8.20.0",
51
51
  "eslint-config-airbnb": "^19.0.4",
52
52
  "eslint-plugin-import": "^2.26.0",
53
53
  "mocha": "^10.0.0",
54
- "ts-node": "^10.8.1",
55
- "typescript": "^4.7.3"
54
+ "ts-node": "^10.9.1",
55
+ "typescript": "^4.7.4"
56
56
  }
57
57
  }
package/CHANGELOG.md DELETED
@@ -1,32 +0,0 @@
1
- # Change Log
2
-
3
- ## 1.0.4 (2022-06-16)
4
- **NOTICE**: `convertDate` is no longer supported due to the removal of `moment` as a dependent module.
5
-
6
- The `today` method has changed its usage. We no longer support custom date formats.
7
-
8
- - `split`: Add new split method
9
- - `today`: Remove dependent modules, change parameters to use pure code
10
- - `convertDate`: Remove method
11
- - `encrypt`, `decrypt`: Add basic validation check (more fix)
12
-
13
- ## 1.0.3 (2022-05-24)
14
-
15
- - `encrypt`, `decrypt`: Add basic validation check
16
-
17
- ## 1.0.2 (2022-05-23)
18
-
19
- - `encrypt` `decrypt`: Add basic validation check
20
- - `strBlindRandom`: Override the deprecated substr method
21
-
22
- ## 1.0.1 (2022-05-12)
23
-
24
- - Minimize bundle size and clean up code
25
-
26
- ## 1.0.0 (2022-05-09)
27
-
28
- - First version release
29
-
30
- ## 0.0.1 ~ 0.5.5 (2021-03-16 ~ 2022-04-09)
31
-
32
- - This is for the Alpha release and is not recommended for use.