qsu 1.0.6 → 1.0.9
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 +1 -1
- package/dist/index.js +41 -1
- package/package.json +7 -7
- package/CHANGELOG.md +0 -44
package/.eslintrc.cjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { basename, extname } from 'path';
|
|
1
|
+
import { basename, extname, win32 } from 'path';
|
|
2
2
|
import { randomBytes, createCipheriv, createDecipheriv, createHash, } from 'crypto';
|
|
3
3
|
export default class Qsu {
|
|
4
4
|
/*
|
|
@@ -121,15 +121,27 @@ export default class Qsu {
|
|
|
121
121
|
* String
|
|
122
122
|
* */
|
|
123
123
|
static removeSpecialChar(str, withoutSpace) {
|
|
124
|
+
if (!str) {
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
124
127
|
return str.replace(new RegExp(`[^a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ0-9\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f${withoutSpace ? ' ' : ''}]`, 'gi'), '');
|
|
125
128
|
}
|
|
126
129
|
static removeNewLine(str, replaceTo = '') {
|
|
130
|
+
if (!str) {
|
|
131
|
+
return '';
|
|
132
|
+
}
|
|
127
133
|
return str.replace(/(\r\n|\n|\r)/gm, replaceTo).trim();
|
|
128
134
|
}
|
|
129
135
|
static capitalizeFirst(str) {
|
|
136
|
+
if (!str) {
|
|
137
|
+
return '';
|
|
138
|
+
}
|
|
130
139
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
131
140
|
}
|
|
132
141
|
static capitalizeEachWords(str, natural) {
|
|
142
|
+
if (!str) {
|
|
143
|
+
return '';
|
|
144
|
+
}
|
|
133
145
|
const splitStr = str.trim().toLowerCase().split(' ');
|
|
134
146
|
for (let i = 0, iLen = splitStr.length; i < iLen; i += 1) {
|
|
135
147
|
if (!natural || !this.contains(splitStr[i], [
|
|
@@ -142,9 +154,15 @@ export default class Qsu {
|
|
|
142
154
|
return this.capitalizeFirst(splitStr.join(' '));
|
|
143
155
|
}
|
|
144
156
|
static strNumberOf(str, search) {
|
|
157
|
+
if (!str) {
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
145
160
|
return (str.match(new RegExp(search, 'g')) || []).length;
|
|
146
161
|
}
|
|
147
162
|
static strShuffle(str) {
|
|
163
|
+
if (!str) {
|
|
164
|
+
return '';
|
|
165
|
+
}
|
|
148
166
|
return [...str].sort(() => Math.random() - 0.5).join('');
|
|
149
167
|
}
|
|
150
168
|
static strRandom(length, additionalCharacters) {
|
|
@@ -160,6 +178,9 @@ export default class Qsu {
|
|
|
160
178
|
return result;
|
|
161
179
|
}
|
|
162
180
|
static strBlindRandom(str, blindLength, blindStr = '*') {
|
|
181
|
+
if (!str) {
|
|
182
|
+
return '';
|
|
183
|
+
}
|
|
163
184
|
let currentStr = str;
|
|
164
185
|
let hideCount = 0;
|
|
165
186
|
let tempIdx = 0;
|
|
@@ -176,6 +197,9 @@ export default class Qsu {
|
|
|
176
197
|
return currentStr;
|
|
177
198
|
}
|
|
178
199
|
static truncate(str, length, ellipsis = '') {
|
|
200
|
+
if (!str) {
|
|
201
|
+
return '';
|
|
202
|
+
}
|
|
179
203
|
let convStr = str;
|
|
180
204
|
if (str.length > length) {
|
|
181
205
|
convStr = str.substring(0, length) + ellipsis;
|
|
@@ -183,6 +207,9 @@ export default class Qsu {
|
|
|
183
207
|
return convStr;
|
|
184
208
|
}
|
|
185
209
|
static split(str, ...splitter) {
|
|
210
|
+
if (!str) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
186
213
|
const splitters = splitter.length > 0 && typeof splitter[0] === 'object' ? splitter[0] : splitter;
|
|
187
214
|
const splitterLength = splitters.length;
|
|
188
215
|
let charPattern = '';
|
|
@@ -254,6 +281,9 @@ export default class Qsu {
|
|
|
254
281
|
return Buffer.from(encodedStr, 'base64').toString('utf8');
|
|
255
282
|
}
|
|
256
283
|
static strUnique(str) {
|
|
284
|
+
if (!str) {
|
|
285
|
+
return '';
|
|
286
|
+
}
|
|
257
287
|
return [...new Set(str)].join('');
|
|
258
288
|
}
|
|
259
289
|
/*
|
|
@@ -361,6 +391,16 @@ export default class Qsu {
|
|
|
361
391
|
return new Intl.NumberFormat().format(number);
|
|
362
392
|
}
|
|
363
393
|
static fileName(filePath, withExtension = false) {
|
|
394
|
+
if (!filePath) {
|
|
395
|
+
return '';
|
|
396
|
+
}
|
|
397
|
+
if (filePath.indexOf('/') === -1) {
|
|
398
|
+
// Windows path
|
|
399
|
+
if (withExtension) {
|
|
400
|
+
return win32.basename(filePath);
|
|
401
|
+
}
|
|
402
|
+
return win32.basename(filePath, extname(filePath));
|
|
403
|
+
}
|
|
364
404
|
if (withExtension) {
|
|
365
405
|
return basename(filePath);
|
|
366
406
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qsu",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Quick and Simple Utility for
|
|
3
|
+
"version": "1.0.9",
|
|
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
|
|
9
|
+
"test": "npm run build && mocha --parallel test/*.spec.js",
|
|
10
10
|
"lint": "eslint .",
|
|
11
11
|
"lint:fix": "eslint --fix ."
|
|
12
12
|
},
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"math"
|
|
44
44
|
],
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^18.
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
48
|
-
"@typescript-eslint/parser": "^5.
|
|
46
|
+
"@types/node": "^18.7.3",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
|
48
|
+
"@typescript-eslint/parser": "^5.33.0",
|
|
49
49
|
"date-fns": "^2.29.1",
|
|
50
|
-
"eslint": "^8.
|
|
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",
|
package/CHANGELOG.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
## 1.0.6 (2022-07-24)
|
|
4
|
-
|
|
5
|
-
- `isBotAgent`: Add `chrome-lighthouse` in bot lists
|
|
6
|
-
- `split`: Fix incorrect return type
|
|
7
|
-
- `isEqual`: Add new isEqual method
|
|
8
|
-
- `isEqualStrict`: Add new isEqualStrict method
|
|
9
|
-
- Import only the methods needed in the path and crypto module
|
|
10
|
-
|
|
11
|
-
## 1.0.5 (2022-06-23)
|
|
12
|
-
|
|
13
|
-
- `contains`: When the length of the str parameter value of string type is 0, no error is thrown and false is returned
|
|
14
|
-
|
|
15
|
-
## 1.0.4 (2022-06-16)
|
|
16
|
-
**NOTICE**: `convertDate` is no longer supported due to the removal of `moment` as a dependent module.
|
|
17
|
-
|
|
18
|
-
The `today` method has changed its usage. We no longer support custom date formats.
|
|
19
|
-
|
|
20
|
-
- `split`: Add new split method
|
|
21
|
-
- `today`: Remove dependent modules, change parameters to use pure code
|
|
22
|
-
- `convertDate`: Remove method
|
|
23
|
-
- `encrypt`, `decrypt`: Add basic validation check (more fix)
|
|
24
|
-
|
|
25
|
-
## 1.0.3 (2022-05-24)
|
|
26
|
-
|
|
27
|
-
- `encrypt`, `decrypt`: Add basic validation check
|
|
28
|
-
|
|
29
|
-
## 1.0.2 (2022-05-23)
|
|
30
|
-
|
|
31
|
-
- `encrypt` `decrypt`: Add basic validation check
|
|
32
|
-
- `strBlindRandom`: Override the deprecated substr method
|
|
33
|
-
|
|
34
|
-
## 1.0.1 (2022-05-12)
|
|
35
|
-
|
|
36
|
-
- Minimize bundle size and clean up code
|
|
37
|
-
|
|
38
|
-
## 1.0.0 (2022-05-09)
|
|
39
|
-
|
|
40
|
-
- First version release
|
|
41
|
-
|
|
42
|
-
## 0.0.1 ~ 0.5.5 (2021-03-16 ~ 2022-04-09)
|
|
43
|
-
|
|
44
|
-
- This is for the Alpha release and is not recommended for use
|