qsu 1.0.1 → 1.0.4
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/CHANGELOG.md +32 -0
- package/LICENSE +21 -21
- package/README.md +17 -13
- package/dist/index.d.ts +2 -2
- package/dist/index.js +59 -8
- package/package.json +13 -11
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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.
|
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
|
@@ -92,11 +92,13 @@ _.daydiff(new Date('2021-01-01'), new Date('2021-01-03')); // Returns 2
|
|
|
92
92
|
### `_.today (string)`
|
|
93
93
|
|
|
94
94
|
Returns today's date.
|
|
95
|
-
- `
|
|
95
|
+
- `separator::string = '-'`
|
|
96
|
+
- `yearFirst::boolean = false`
|
|
96
97
|
|
|
97
98
|
```javascript
|
|
98
99
|
_.today(); // Returns YYYY-MM-DD
|
|
99
|
-
_.today('
|
|
100
|
+
_.today('/'); // Returns YYYY/MM/DD
|
|
101
|
+
_.today('/', false); // Returns DD/MM/YYYY
|
|
100
102
|
```
|
|
101
103
|
|
|
102
104
|
### `_.isRealDate (boolean)`
|
|
@@ -109,17 +111,6 @@ _.isRealDate('2021-01-01'); // Returns true
|
|
|
109
111
|
_.isRealDate('2021-02-30'); // Returns false
|
|
110
112
|
```
|
|
111
113
|
|
|
112
|
-
### `_.convertDate (string)`
|
|
113
|
-
|
|
114
|
-
Returns a date in YYYY-MM-DD or desired format based on the first argument (date in String format).
|
|
115
|
-
- `date::string`
|
|
116
|
-
- `format::string?`
|
|
117
|
-
|
|
118
|
-
```javascript
|
|
119
|
-
_.convertDate('2021-01-01', 'YYYY'); // Returns 2021
|
|
120
|
-
_.convertDate('2021', 'YYYY_MM_DD'); // Returns 2021_01_01
|
|
121
|
-
```
|
|
122
|
-
|
|
123
114
|
### `_.arrShuffle (any[])`
|
|
124
115
|
|
|
125
116
|
Shuffle the order of the given array and return.
|
|
@@ -273,6 +264,19 @@ _.truncate('hello', 3); // Returns 'hel'
|
|
|
273
264
|
_.truncate('hello', 2, '...'); // Returns 'he...'
|
|
274
265
|
```
|
|
275
266
|
|
|
267
|
+
### `_.split (string)`
|
|
268
|
+
|
|
269
|
+
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
|
+
- `str::string`
|
|
271
|
+
- `splitter::string||string[]||...string`
|
|
272
|
+
|
|
273
|
+
```javascript
|
|
274
|
+
_.split('hello% js world', '% '); // Returns ['hello', 'js world']
|
|
275
|
+
_.split('hello,js,world', ','); // Returns ['hello', 'js', 'world']
|
|
276
|
+
_.split('hello%js,world', ',', '%'); // Returns ['hello', 'js', 'world']
|
|
277
|
+
_.split('hello%js,world', [',', '%']); // Returns ['hello', 'js', 'world']
|
|
278
|
+
```
|
|
279
|
+
|
|
276
280
|
### `_.encrypt (string)`
|
|
277
281
|
|
|
278
282
|
Encrypt with the algorithm of your choice (algorithm default: `aes-256-cbc`, ivSize default: `16`) using a string and a secret (secret).
|
package/dist/index.d.ts
CHANGED
|
@@ -13,9 +13,8 @@ export default class Qsu {
|
|
|
13
13
|
static sum(...args: number[]): number;
|
|
14
14
|
static mul(...args: number[]): number;
|
|
15
15
|
static dayDiff(date1: Date, date2?: Date): number;
|
|
16
|
-
static today(
|
|
16
|
+
static today(separator?: string, yearFirst?: boolean): string;
|
|
17
17
|
static isRealDate(date: string | Date): boolean;
|
|
18
|
-
static convertDate(date: string, format?: string): string;
|
|
19
18
|
static arrShuffle(array: any[]): any[];
|
|
20
19
|
static arrWithDefault(defaultValue: any, length?: number): any[];
|
|
21
20
|
static arrUnique(array: any[]): any[];
|
|
@@ -31,6 +30,7 @@ export default class Qsu {
|
|
|
31
30
|
static strRandom<N extends number>(length: PositiveNumber<N>, additionalCharacters?: string): string;
|
|
32
31
|
static strBlindRandom<N extends number>(str: string, blindLength: PositiveNumber<N>, blindStr?: string): string;
|
|
33
32
|
static truncate<N extends number>(str: string, length: PositiveNumber<N>, ellipsis?: string): string;
|
|
33
|
+
static split(str: string, ...splitter: Array<string>): 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;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import moment from 'moment';
|
|
2
1
|
import path from 'path';
|
|
3
2
|
import crypto from 'crypto';
|
|
4
3
|
export default class Qsu {
|
|
@@ -48,8 +47,21 @@ export default class Qsu {
|
|
|
48
47
|
const date2c = date2 || new Date();
|
|
49
48
|
return Math.ceil(Math.abs(date2c.getTime() - date1.getTime()) / (1000 * 3600 * 24));
|
|
50
49
|
}
|
|
51
|
-
static today(
|
|
52
|
-
|
|
50
|
+
static today(separator = '-', yearFirst = true) {
|
|
51
|
+
const date = new Date();
|
|
52
|
+
const month = date.getMonth() + 1;
|
|
53
|
+
const day = date.getDate();
|
|
54
|
+
const dateArr = [
|
|
55
|
+
`${month < 10 ? '0' : ''}${month}`,
|
|
56
|
+
`${day < 10 ? '0' : ''}${day}`,
|
|
57
|
+
];
|
|
58
|
+
if (yearFirst) {
|
|
59
|
+
dateArr.unshift(date.getFullYear().toString());
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
dateArr.push(date.getFullYear().toString());
|
|
63
|
+
}
|
|
64
|
+
return dateArr.join(separator);
|
|
53
65
|
}
|
|
54
66
|
static isRealDate(date) {
|
|
55
67
|
const dateConverted = typeof date === 'string' ? new Date(date) : date;
|
|
@@ -58,9 +70,6 @@ export default class Qsu {
|
|
|
58
70
|
}
|
|
59
71
|
return dateConverted.toISOString().slice(0, 10) === date;
|
|
60
72
|
}
|
|
61
|
-
static convertDate(date, format) {
|
|
62
|
-
return moment(date).format(format || 'YYYY-MM-DD');
|
|
63
|
-
}
|
|
64
73
|
/*
|
|
65
74
|
* Array
|
|
66
75
|
* */
|
|
@@ -158,8 +167,8 @@ export default class Qsu {
|
|
|
158
167
|
const totalStrLength = currentStr.length;
|
|
159
168
|
while ((hideCount < blindLength) && (currentStrLength < totalStrLength)) {
|
|
160
169
|
tempIdx = this.numRandom(0, totalStrLength);
|
|
161
|
-
if (/[a-zA-Z가-힣]/.test(currentStr.
|
|
162
|
-
currentStr = `${currentStr.
|
|
170
|
+
if (/[a-zA-Z가-힣]/.test(currentStr.substring(tempIdx, tempIdx + 1))) {
|
|
171
|
+
currentStr = `${currentStr.substring(0, tempIdx + 1)}${blindStr}${currentStr.substring(tempIdx + 2)}`;
|
|
163
172
|
hideCount += 1;
|
|
164
173
|
}
|
|
165
174
|
currentStrLength += 1;
|
|
@@ -173,7 +182,46 @@ export default class Qsu {
|
|
|
173
182
|
}
|
|
174
183
|
return convStr;
|
|
175
184
|
}
|
|
185
|
+
static split(str, ...splitter) {
|
|
186
|
+
const splitters = splitter.length > 0 && typeof splitter[0] === 'object' ? splitter[0] : splitter;
|
|
187
|
+
const splitterLength = splitters.length;
|
|
188
|
+
let charPattern = '';
|
|
189
|
+
let strPattern = '';
|
|
190
|
+
for (let i = 0; i < splitterLength; i += 1) {
|
|
191
|
+
const spl = splitters[i];
|
|
192
|
+
if (spl.length > 1) {
|
|
193
|
+
strPattern += `${strPattern.length < 1 ? '' : '|'}${spl
|
|
194
|
+
.replace(/\\/g, '\\\\')
|
|
195
|
+
.replace(/\[/g, '\\[')
|
|
196
|
+
.replace(/]/g, '\\]')
|
|
197
|
+
.replace(/\?/g, '\\?')
|
|
198
|
+
.replace(/\./g, '\\.')
|
|
199
|
+
.replace(/\{/g, '\\{')
|
|
200
|
+
.replace(/}/g, '\\}')
|
|
201
|
+
.replace(/\+/g, '\\+')}`;
|
|
202
|
+
}
|
|
203
|
+
else if (spl === '-' || spl === '[' || spl === ']') {
|
|
204
|
+
charPattern += `\\${spl}`;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
charPattern += spl;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (charPattern.length < 1 && strPattern.length < 1) {
|
|
211
|
+
return str;
|
|
212
|
+
}
|
|
213
|
+
if (charPattern.length > 0) {
|
|
214
|
+
charPattern = `[${charPattern}]`;
|
|
215
|
+
if (strPattern.length > 0) {
|
|
216
|
+
strPattern = `|${strPattern}`;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return str.split(new RegExp(`${charPattern}${strPattern}+`, 'gi'));
|
|
220
|
+
}
|
|
176
221
|
static encrypt(str, secret, algorithm = 'aes-256-cbc', ivSize = 16) {
|
|
222
|
+
if (!str || str.length < 1) {
|
|
223
|
+
return '';
|
|
224
|
+
}
|
|
177
225
|
const iv = crypto.randomBytes(ivSize);
|
|
178
226
|
const cipher = crypto.createCipheriv(algorithm, secret, iv);
|
|
179
227
|
let enc = cipher.update(str);
|
|
@@ -181,6 +229,9 @@ export default class Qsu {
|
|
|
181
229
|
return `${iv.toString('hex')}:${enc.toString('hex')}`;
|
|
182
230
|
}
|
|
183
231
|
static decrypt(str, secret, algorithm = 'aes-256-cbc') {
|
|
232
|
+
if (!str || str.length < 1) {
|
|
233
|
+
return '';
|
|
234
|
+
}
|
|
184
235
|
const arrStr = str.split(':');
|
|
185
236
|
const decipher = crypto.createDecipheriv(algorithm, secret, Buffer.from(arrStr.shift(), 'hex'));
|
|
186
237
|
let decrypted = decipher.update(Buffer.from(arrStr.join(':'), 'hex'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qsu",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Quick and Simple Utility for javascript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,20 +36,22 @@
|
|
|
36
36
|
"tool",
|
|
37
37
|
"underscore",
|
|
38
38
|
"website",
|
|
39
|
-
"helper"
|
|
39
|
+
"helper",
|
|
40
|
+
"array",
|
|
41
|
+
"string",
|
|
42
|
+
"date",
|
|
43
|
+
"math"
|
|
40
44
|
],
|
|
41
45
|
"devDependencies": {
|
|
42
|
-
"@types/node": "^
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
44
|
-
"@typescript-eslint/parser": "^5.
|
|
45
|
-
"
|
|
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
51
|
"eslint-config-airbnb": "^19.0.4",
|
|
47
52
|
"eslint-plugin-import": "^2.26.0",
|
|
48
53
|
"mocha": "^10.0.0",
|
|
49
|
-
"ts-node": "^10.
|
|
50
|
-
"typescript": "^4.
|
|
51
|
-
},
|
|
52
|
-
"dependencies": {
|
|
53
|
-
"moment": "^2.29.3"
|
|
54
|
+
"ts-node": "^10.8.1",
|
|
55
|
+
"typescript": "^4.7.3"
|
|
54
56
|
}
|
|
55
57
|
}
|