qsu 1.0.5 → 1.0.8

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/.eslintrc.cjs CHANGED
@@ -16,7 +16,7 @@ module.exports = {
16
16
  'plugin:@typescript-eslint/recommended',
17
17
  ],
18
18
  rules: {
19
- 'linebreak-style': ['error', 'windows'],
19
+ 'linebreak-style': 0,
20
20
  'arrow-parens': 0,
21
21
  'max-len': 0,
22
22
  '@typescript-eslint/no-explicit-any': 0
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, win32 } from 'path';
2
+ import { randomBytes, createCipheriv, createDecipheriv, createHash, } from 'crypto';
3
3
  export default class Qsu {
4
4
  /*
5
5
  * Misc
@@ -177,6 +177,9 @@ export default class Qsu {
177
177
  }
178
178
  static truncate(str, length, ellipsis = '') {
179
179
  let convStr = str;
180
+ if (!str) {
181
+ return '';
182
+ }
180
183
  if (str.length > length) {
181
184
  convStr = str.substring(0, length) + ellipsis;
182
185
  }
@@ -208,7 +211,7 @@ export default class Qsu {
208
211
  }
209
212
  }
210
213
  if (charPattern.length < 1 && strPattern.length < 1) {
211
- return str;
214
+ return [str];
212
215
  }
213
216
  if (charPattern.length > 0) {
214
217
  charPattern = `[${charPattern}]`;
@@ -222,8 +225,8 @@ export default class Qsu {
222
225
  if (!str || str.length < 1) {
223
226
  return '';
224
227
  }
225
- const iv = crypto.randomBytes(ivSize);
226
- const cipher = crypto.createCipheriv(algorithm, secret, iv);
228
+ const iv = randomBytes(ivSize);
229
+ const cipher = createCipheriv(algorithm, secret, iv);
227
230
  let enc = cipher.update(str);
228
231
  enc = Buffer.concat([enc, cipher.final()]);
229
232
  return `${iv.toString('hex')}:${enc.toString('hex')}`;
@@ -233,19 +236,19 @@ export default class Qsu {
233
236
  return '';
234
237
  }
235
238
  const arrStr = str.split(':');
236
- const decipher = crypto.createDecipheriv(algorithm, secret, Buffer.from(arrStr.shift(), 'hex'));
239
+ const decipher = createDecipheriv(algorithm, secret, Buffer.from(arrStr.shift(), 'hex'));
237
240
  let decrypted = decipher.update(Buffer.from(arrStr.join(':'), 'hex'));
238
241
  decrypted = Buffer.concat([decrypted, decipher.final()]);
239
242
  return decrypted.toString();
240
243
  }
241
244
  static md5(str) {
242
- return crypto.createHash('md5').update(str).digest('hex');
245
+ return createHash('md5').update(str).digest('hex');
243
246
  }
244
247
  static sha1(str) {
245
- return crypto.createHash('sha1').update(str).digest('hex');
248
+ return createHash('sha1').update(str).digest('hex');
246
249
  }
247
250
  static sha256(str) {
248
- return crypto.createHash('sha256').update(str).digest('hex');
251
+ return createHash('sha256').update(str).digest('hex');
249
252
  }
250
253
  static encodeBase64(str) {
251
254
  return Buffer.from(str, 'utf8').toString('base64');
@@ -259,6 +262,27 @@ export default class Qsu {
259
262
  /*
260
263
  * Verify
261
264
  * */
265
+ static isEqual(leftOperand, ...rightOperand) {
266
+ const rightOperands = rightOperand.length > 0 && typeof rightOperand[0] === 'object' ? rightOperand[0] : rightOperand;
267
+ const rightOperandLength = rightOperands.length;
268
+ for (let i = 0; i < rightOperandLength; i += 1) {
269
+ // eslint-disable-next-line eqeqeq
270
+ if (rightOperands[i] != leftOperand) {
271
+ return false;
272
+ }
273
+ }
274
+ return true;
275
+ }
276
+ static isEqualStrict(leftOperand, ...rightOperand) {
277
+ const rightOperands = rightOperand.length > 0 && typeof rightOperand[0] === 'object' ? rightOperand[0] : rightOperand;
278
+ const rightOperandLength = rightOperands.length;
279
+ for (let i = 0; i < rightOperandLength; i += 1) {
280
+ if (rightOperands[i] !== leftOperand) {
281
+ return false;
282
+ }
283
+ }
284
+ return true;
285
+ }
262
286
  static isEmpty(data) {
263
287
  if (!data) {
264
288
  return true;
@@ -331,7 +355,7 @@ export default class Qsu {
331
355
  }
332
356
  }
333
357
  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);
358
+ 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
359
  }
336
360
  /*
337
361
  * Format
@@ -340,10 +364,20 @@ export default class Qsu {
340
364
  return new Intl.NumberFormat().format(number);
341
365
  }
342
366
  static fileName(filePath, withExtension = false) {
367
+ if (!filePath) {
368
+ return '';
369
+ }
370
+ if (filePath.indexOf('/') === -1) {
371
+ // Windows path
372
+ if (withExtension) {
373
+ return win32.basename(filePath);
374
+ }
375
+ return win32.basename(filePath, extname(filePath));
376
+ }
343
377
  if (withExtension) {
344
- return path.basename(filePath);
378
+ return basename(filePath);
345
379
  }
346
- return path.basename(filePath, path.extname(filePath));
380
+ return basename(filePath, extname(filePath));
347
381
  }
348
382
  static fileSize(bytes, decimals = 2) {
349
383
  if (bytes === 0 || bytes < 0) {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "qsu",
3
- "version": "1.0.5",
4
- "description": "Quick and Simple Utility for javascript",
3
+ "version": "1.0.8",
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": "tsc",
9
- "test": "npm run lint && npm run build && mocha --parallel test/*.spec.js",
9
+ "test": "npm run build && mocha --parallel test/*.spec.js",
10
10
  "lint": "eslint .",
11
11
  "lint:fix": "eslint --fix ."
12
12
  },
@@ -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.7.3",
47
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
48
+ "@typescript-eslint/parser": "^5.33.0",
49
+ "date-fns": "^2.29.1",
50
+ "eslint": "^8.22.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,36 +0,0 @@
1
- # Change Log
2
-
3
- ## 1.0.5 (2022-06-23)
4
-
5
- - `contains`: When the length of the str parameter value of string type is 0, no error is thrown and false is returned.
6
-
7
- ## 1.0.4 (2022-06-16)
8
- **NOTICE**: `convertDate` is no longer supported due to the removal of `moment` as a dependent module.
9
-
10
- The `today` method has changed its usage. We no longer support custom date formats.
11
-
12
- - `split`: Add new split method
13
- - `today`: Remove dependent modules, change parameters to use pure code
14
- - `convertDate`: Remove method
15
- - `encrypt`, `decrypt`: Add basic validation check (more fix)
16
-
17
- ## 1.0.3 (2022-05-24)
18
-
19
- - `encrypt`, `decrypt`: Add basic validation check
20
-
21
- ## 1.0.2 (2022-05-23)
22
-
23
- - `encrypt` `decrypt`: Add basic validation check
24
- - `strBlindRandom`: Override the deprecated substr method
25
-
26
- ## 1.0.1 (2022-05-12)
27
-
28
- - Minimize bundle size and clean up code
29
-
30
- ## 1.0.0 (2022-05-09)
31
-
32
- - First version release
33
-
34
- ## 0.0.1 ~ 0.5.5 (2021-03-16 ~ 2022-04-09)
35
-
36
- - This is for the Alpha release and is not recommended for use.