qsu 1.0.3 → 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/README.md +17 -13
- package/dist/index.d.ts +2 -2
- package/dist/index.js +51 -6
- package/package.json +8 -10
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/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
|
* */
|
|
@@ -173,6 +182,42 @@ 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) {
|
|
177
222
|
if (!str || str.length < 1) {
|
|
178
223
|
return '';
|
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",
|
|
@@ -43,17 +43,15 @@
|
|
|
43
43
|
"math"
|
|
44
44
|
],
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
48
|
-
"@typescript-eslint/parser": "^5.
|
|
49
|
-
"
|
|
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",
|
|
50
51
|
"eslint-config-airbnb": "^19.0.4",
|
|
51
52
|
"eslint-plugin-import": "^2.26.0",
|
|
52
53
|
"mocha": "^10.0.0",
|
|
53
|
-
"ts-node": "^10.8.
|
|
54
|
-
"typescript": "^4.
|
|
55
|
-
},
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"moment": "^2.29.3"
|
|
54
|
+
"ts-node": "^10.8.1",
|
|
55
|
+
"typescript": "^4.7.3"
|
|
58
56
|
}
|
|
59
57
|
}
|