qsu 0.5.3 → 1.0.0
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/.eslintignore +2 -0
- package/.eslintrc.cjs +44 -0
- package/.idea/git_toolbox_prj.xml +15 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/jsLinters/eslint.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/qsu.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -21
- package/README.md +522 -158
- package/dist/index.d.ts +57 -0
- package/dist/index.js +343 -0
- package/package.json +55 -32
- package/tsconfig.json +23 -0
- package/.babelrc +0 -7
- package/.eslintrc.js +0 -25
- package/array.js +0 -47
- package/date.js +0 -36
- package/format.js +0 -76
- package/index.js +0 -17
- package/math.js +0 -32
- package/misc.js +0 -7
- package/string.js +0 -145
- package/test/array.spec.js +0 -42
- package/test/date.spec.js +0 -36
- package/test/format.spec.js +0 -56
- package/test/math.spec.js +0 -30
- package/test/misc.spec.js +0 -8
- package/test/string.spec.js +0 -107
- package/test/verify.spec.js +0 -74
- package/verify.js +0 -88
package/format.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
const number = (v) => new Intl.NumberFormat().format(v);
|
|
4
|
-
|
|
5
|
-
const fileName = (filePath, withExtension) => {
|
|
6
|
-
if (!filePath || typeof filePath !== 'string' || filePath.length < 1) {
|
|
7
|
-
throw new Error('Unknown file path');
|
|
8
|
-
}
|
|
9
|
-
if (withExtension) {
|
|
10
|
-
return path.basename(filePath);
|
|
11
|
-
}
|
|
12
|
-
return path.basename(filePath, path.extname(filePath));
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const fileSize = (bytes, decimals = 2) => {
|
|
16
|
-
if (bytes === null || typeof bytes !== 'number' || typeof decimals !== 'number') return 'Unknown';
|
|
17
|
-
if (bytes === 0 || bytes < 0) return '0 Bytes';
|
|
18
|
-
const byteCalc = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
19
|
-
return `${parseFloat((bytes / 1024 ** byteCalc).toFixed((decimals < 0 ? 0 : decimals)))} ${['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'][byteCalc]}`;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const fileExt = (filePath) => {
|
|
23
|
-
if (!filePath || typeof filePath !== 'string' || filePath.indexOf('.') === -1) return 'Unknown';
|
|
24
|
-
const p = filePath.trim().toLowerCase();
|
|
25
|
-
const pSpl = p.split('.');
|
|
26
|
-
return pSpl.length > 0 ? pSpl[pSpl.length - 1] : 'Unknown';
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const msToTime = (milliseconds = 0, withMilliseconds = false, separator = ':') => {
|
|
30
|
-
if (!milliseconds || typeof milliseconds !== 'number' || typeof separator !== 'string') return 'Unknown';
|
|
31
|
-
const ms = Math.floor((milliseconds % 1000) / 100);
|
|
32
|
-
let sec = Math.floor((milliseconds / 1000) % 60);
|
|
33
|
-
let min = Math.floor((milliseconds / (1000 * 60)) % 60);
|
|
34
|
-
let hour = Math.floor(milliseconds / (1000 * 60 * 60));
|
|
35
|
-
hour = (hour < 10) ? `0${hour}` : hour;
|
|
36
|
-
min = (min < 10) ? `0${min}` : min;
|
|
37
|
-
sec = (sec < 10) ? `0${sec}` : sec;
|
|
38
|
-
return `${hour}${separator}${min}${separator}${sec}${withMilliseconds ? `.${ms}` : ''}`;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const secToTime = (seconds = 0, separator = ':', onlyHour = false) => {
|
|
42
|
-
if (!seconds || typeof seconds !== 'number' || typeof separator !== 'string') return 'Unknown';
|
|
43
|
-
let sec = Math.floor(seconds % 60);
|
|
44
|
-
let min = Math.floor((seconds / 60) % 60);
|
|
45
|
-
let hour = Math.floor(seconds / (60 * 60));
|
|
46
|
-
hour = (hour < 10) ? `0${hour}` : hour;
|
|
47
|
-
min = (min < 10) ? `0${min}` : min;
|
|
48
|
-
sec = (sec < 10) ? `0${sec}` : sec;
|
|
49
|
-
return onlyHour ? hour : `${hour}${separator}${min}${separator}${sec}`;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const license = (args = {}) => {
|
|
53
|
-
if (typeof args !== 'object' || args.length < 1) {
|
|
54
|
-
throw new Error('An argument of type Object is required. Please refer to README.md.');
|
|
55
|
-
}
|
|
56
|
-
if (!args.author || !args.yearStart) {
|
|
57
|
-
throw new Error('holder and startYear are required.');
|
|
58
|
-
}
|
|
59
|
-
const br = args.htmlBr ? '<br/>' : '\n';
|
|
60
|
-
const type = args?.type?.toLowerCase() || 'mit';
|
|
61
|
-
switch (type) {
|
|
62
|
-
case 'mit':
|
|
63
|
-
default:
|
|
64
|
-
return `Copyright (c) ${args.yearStart}${args.yearEnd ? `-${args.yearEnd}` : ''} ${args.author}${args.email ? ` <${args.email}>` : ''}${br}${br}Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:${br}${br}The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.${br}${br}THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.`;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
module.exports = {
|
|
69
|
-
number,
|
|
70
|
-
fileName,
|
|
71
|
-
fileSize,
|
|
72
|
-
fileExt,
|
|
73
|
-
msToTime,
|
|
74
|
-
secToTime,
|
|
75
|
-
license,
|
|
76
|
-
};
|
package/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const date = require('./date');
|
|
2
|
-
const format = require('./format');
|
|
3
|
-
const misc = require('./misc');
|
|
4
|
-
const math = require('./math');
|
|
5
|
-
const array = require('./array');
|
|
6
|
-
const string = require('./string');
|
|
7
|
-
const verify = require('./verify');
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
date,
|
|
11
|
-
format,
|
|
12
|
-
misc,
|
|
13
|
-
math,
|
|
14
|
-
array,
|
|
15
|
-
string,
|
|
16
|
-
verify,
|
|
17
|
-
};
|
package/math.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const rand = (min, max) => {
|
|
2
|
-
if (!min && !max) return (Math.random() > 0.5) ? 1 : 0;
|
|
3
|
-
const limit = !max ? min : max;
|
|
4
|
-
const offset = (!max || min >= max) ? null : min;
|
|
5
|
-
return Math.floor(Math.random() * (offset ? (limit - offset + 1) : limit + 1)) + (offset || 0);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const add = (...args) => {
|
|
9
|
-
const val = args.length > 0 && typeof args[0] === 'object' ? args[0] : args;
|
|
10
|
-
if (val.length < 1) throw new Error('Invalid argument format!');
|
|
11
|
-
let total = 0;
|
|
12
|
-
for (let i = 0, iLen = val.length; i < iLen; i += 1) {
|
|
13
|
-
if (typeof val[i] === 'number') total += val[i];
|
|
14
|
-
}
|
|
15
|
-
return total;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const mul = (...args) => {
|
|
19
|
-
const val = args.length > 0 && typeof args[0] === 'object' ? args[0] : args;
|
|
20
|
-
if (val.length < 1) throw new Error('Invalid argument format!');
|
|
21
|
-
let total = val[0];
|
|
22
|
-
for (let i = 1, iLen = val.length; i < iLen; i += 1) {
|
|
23
|
-
if (typeof val[i] === 'number') total *= val[i];
|
|
24
|
-
}
|
|
25
|
-
return total;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
module.exports = {
|
|
29
|
-
rand,
|
|
30
|
-
add,
|
|
31
|
-
mul,
|
|
32
|
-
};
|
package/misc.js
DELETED
package/string.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
const crypto = require('crypto');
|
|
2
|
-
const { rand } = require('./math');
|
|
3
|
-
const { contains } = require('./verify');
|
|
4
|
-
|
|
5
|
-
const removeSpecialChar = (str, withoutSpace) => {
|
|
6
|
-
if (!str || typeof str !== 'string') return str;
|
|
7
|
-
return str.replace(new RegExp(`[^a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ0-9\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f${withoutSpace ? ' ' : ''}]`, 'gi'), '');
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const removeNewLine = (str, replaceTo = '') => {
|
|
11
|
-
if (!str || typeof str !== 'string') return null;
|
|
12
|
-
return str.replace(/(\r\n|\n|\r)/gm, replaceTo).trim();
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const capitalizeFirst = (str) => {
|
|
16
|
-
if (!str || typeof str !== 'string' || str.length < 1) return null;
|
|
17
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const capitalizeEachWords = (str, naturally) => {
|
|
21
|
-
if (!str || typeof str !== 'string' || str.length < 1) return null;
|
|
22
|
-
const splitStr = str.trim().toLowerCase().split(' ');
|
|
23
|
-
for (let i = 0, iLen = splitStr.length; i < iLen; i += 1) {
|
|
24
|
-
if (!naturally || !contains(splitStr[i], [
|
|
25
|
-
'in', 'on', 'the', 'at', 'and', 'or', 'of', 'for', 'to', 'that',
|
|
26
|
-
'a', 'by', 'it', 'is', 'as', 'are', 'were', 'was', 'nor', 'an',
|
|
27
|
-
], true)) {
|
|
28
|
-
splitStr[i] = capitalizeFirst(splitStr[i]);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return capitalizeFirst(splitStr.join(' '));
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const count = (str, search) => {
|
|
35
|
-
if (!str || typeof str !== 'string' || !search || typeof search !== 'string') return 0;
|
|
36
|
-
return (str.match(new RegExp(search, 'g')) || []).length;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const shuffle = (str) => {
|
|
40
|
-
if (!str || typeof str !== 'string') return null;
|
|
41
|
-
return [...str].sort(() => Math.random() - 0.5).join('');
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const createRandom = (length = 12) => {
|
|
45
|
-
if (typeof length !== 'number') {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
let result = '';
|
|
49
|
-
let newChar;
|
|
50
|
-
const AVAIL_CHARACTERS = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
51
|
-
const AVAIL_CHARACTERS_LENGTH = AVAIL_CHARACTERS.length;
|
|
52
|
-
for (let i = 0; i < length; i += 1) {
|
|
53
|
-
newChar = AVAIL_CHARACTERS.charAt(Math.floor(Math.random() * AVAIL_CHARACTERS_LENGTH));
|
|
54
|
-
newChar = Math.random() < 0.5 ? newChar.toUpperCase() : newChar;
|
|
55
|
-
result += newChar;
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const hideRandom = (str, hideLength = 1, hideStr = '*') => {
|
|
61
|
-
let currentStr = str;
|
|
62
|
-
let hideCount = 0;
|
|
63
|
-
let tempIdx = 0;
|
|
64
|
-
const totalStrLength = currentStr.length;
|
|
65
|
-
let currentStrLength = 0;
|
|
66
|
-
while ((hideCount < hideLength) && (currentStrLength < totalStrLength)) {
|
|
67
|
-
tempIdx = rand(0, totalStrLength);
|
|
68
|
-
if (/[a-zA-Z가-힣]/.test(currentStr.substr(tempIdx, 1))) {
|
|
69
|
-
currentStr = `${currentStr.substr(0, tempIdx)}${hideStr}${currentStr.substr(tempIdx + 1)}`;
|
|
70
|
-
hideCount += 1;
|
|
71
|
-
}
|
|
72
|
-
currentStrLength += 1;
|
|
73
|
-
}
|
|
74
|
-
return currentStr;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const truncate = (str, length = 0, ellipsis = '') => {
|
|
78
|
-
let convStr = str;
|
|
79
|
-
if (str.length > length) {
|
|
80
|
-
convStr = str.substring(0, length) + ellipsis;
|
|
81
|
-
}
|
|
82
|
-
return convStr;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const encrypt = (str, secret, algorithm = 'aes-256-cbc', ivSize = 16) => {
|
|
86
|
-
const iv = crypto.randomBytes(ivSize);
|
|
87
|
-
const cipher = crypto.createCipheriv(algorithm, secret, iv);
|
|
88
|
-
let enc = cipher.update(str);
|
|
89
|
-
enc = Buffer.concat([enc, cipher.final()]);
|
|
90
|
-
return `${iv.toString('hex')}:${enc.toString('hex')}`;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const decrypt = (str, secret, algorithm = 'aes-256-cbc') => {
|
|
94
|
-
const arrStr = str.split(':');
|
|
95
|
-
const decipher = crypto.createDecipheriv(algorithm, secret, Buffer.from(arrStr.shift(), 'hex'));
|
|
96
|
-
let decrypted = decipher.update(Buffer.from(arrStr.join(':'), 'hex'));
|
|
97
|
-
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
98
|
-
return decrypted.toString();
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const md5 = (str) => {
|
|
102
|
-
if (!str || typeof str !== 'string' || str.length < 1) {
|
|
103
|
-
throw new Error('string arguments required');
|
|
104
|
-
}
|
|
105
|
-
return crypto.createHash('md5').update(str).digest('hex');
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const sha1 = (str) => {
|
|
109
|
-
if (!str || typeof str !== 'string' || str.length < 1) {
|
|
110
|
-
throw new Error('string arguments required');
|
|
111
|
-
}
|
|
112
|
-
return crypto.createHash('sha1').update(str).digest('hex');
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const sha256 = (str) => {
|
|
116
|
-
if (!str || typeof str !== 'string' || str.length < 1) {
|
|
117
|
-
throw new Error('string arguments required');
|
|
118
|
-
}
|
|
119
|
-
return crypto.createHash('sha256').update(str).digest('hex');
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const unique = (str) => {
|
|
123
|
-
if (!str || typeof str !== 'string' || str.length < 1) {
|
|
124
|
-
throw new Error('string arguments required');
|
|
125
|
-
}
|
|
126
|
-
return String.prototype.concat(...new Set(str));
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
module.exports = {
|
|
130
|
-
removeSpecialChar,
|
|
131
|
-
removeNewLine,
|
|
132
|
-
capitalizeFirst,
|
|
133
|
-
capitalizeEachWords,
|
|
134
|
-
count,
|
|
135
|
-
shuffle,
|
|
136
|
-
createRandom,
|
|
137
|
-
hideRandom,
|
|
138
|
-
truncate,
|
|
139
|
-
encrypt,
|
|
140
|
-
decrypt,
|
|
141
|
-
md5,
|
|
142
|
-
sha1,
|
|
143
|
-
sha256,
|
|
144
|
-
unique,
|
|
145
|
-
};
|
package/test/array.spec.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const _ = require('../array');
|
|
3
|
-
|
|
4
|
-
describe('Array', () => {
|
|
5
|
-
it('shuffle', (done) => {
|
|
6
|
-
assert(_.shuffle([1, 2, 3, 4, 5, 6, 7, 8]));
|
|
7
|
-
assert(_.shuffle([[1, 2], [3, 4], [5, 6], [7, 8]]));
|
|
8
|
-
assert(_.shuffle([{ A: 1 }, { B: 2 }, { C: 3 }, { D: 4 }]));
|
|
9
|
-
done();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('setWithDefault', (done) => {
|
|
13
|
-
assert(_.setWithDefault());
|
|
14
|
-
assert(_.setWithDefault('test'));
|
|
15
|
-
assert(_.setWithDefault('test', 10));
|
|
16
|
-
assert(_.setWithDefault(100, 5));
|
|
17
|
-
done();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('unique', (done) => {
|
|
21
|
-
assert.deepStrictEqual(_.unique([1, 1, 2, 2, 3]), [1, 2, 3]);
|
|
22
|
-
assert.deepStrictEqual(_.unique(['1', '2', '3', '3', '4']), ['1', '2', '3', '4']);
|
|
23
|
-
assert.deepStrictEqual(_.unique([1, '1', 1, 'a', 2, 'b']), [1, '1', 'a', 2, 'b']);
|
|
24
|
-
assert.deepStrictEqual(_.unique([[1, 2], [1, 2], [2, 3], [2, 4]]), [[1, 2], [2, 3], [2, 4]]);
|
|
25
|
-
done();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('setWithNumber', (done) => {
|
|
29
|
-
assert.deepStrictEqual(_.setWithNumber(1, 2), [1, 2]);
|
|
30
|
-
assert.deepStrictEqual(_.setWithNumber(2, 1), null);
|
|
31
|
-
assert.deepStrictEqual(_.setWithNumber(0, 5), [0, 1, 2, 3, 4, 5]);
|
|
32
|
-
assert.deepStrictEqual(_.setWithNumber(1, 1), [1]);
|
|
33
|
-
done();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('average', (done) => {
|
|
37
|
-
assert.deepStrictEqual(_.average([1, 3, 5, 7, 9]), 5);
|
|
38
|
-
assert.deepStrictEqual(_.average([1, 5, 15, 50]), 17.75);
|
|
39
|
-
assert.deepStrictEqual(_.average([5, -5]), 0);
|
|
40
|
-
done();
|
|
41
|
-
});
|
|
42
|
-
});
|
package/test/date.spec.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const moment = require('moment');
|
|
3
|
-
const _ = require('../date');
|
|
4
|
-
|
|
5
|
-
describe('Date', () => {
|
|
6
|
-
it('dayDiff', (done) => {
|
|
7
|
-
assert.strictEqual(_.dayDiff('2021-01-01', '2021-01-02'), 1);
|
|
8
|
-
assert.strictEqual(_.dayDiff('2021-01-01', '2021-02-28'), 55);
|
|
9
|
-
done();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('today', (done) => {
|
|
13
|
-
assert.strictEqual(_.today(), moment().format('YYYY-MM-DD'));
|
|
14
|
-
assert.strictEqual(_.today(1), null);
|
|
15
|
-
assert.strictEqual(_.today('YYYY-MM-DD'), moment().format('YYYY-MM-DD'));
|
|
16
|
-
assert.strictEqual(_.today('yyyy'), moment().format('YYYY'));
|
|
17
|
-
done();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('isRealDate', (done) => {
|
|
21
|
-
assert.strictEqual(_.isRealDate('2021-01-01'), true);
|
|
22
|
-
assert.strictEqual(_.isRealDate('2021-02-28'), true);
|
|
23
|
-
assert.strictEqual(_.isRealDate('2021-02-29'), false);
|
|
24
|
-
assert.strictEqual(_.isRealDate('2021-03-32'), false);
|
|
25
|
-
assert.strictEqual(_.isRealDate('2021-13-01'), false);
|
|
26
|
-
done();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('convertDate', (done) => {
|
|
30
|
-
assert.strictEqual(_.convertDate('20210101'), '2021-01-01');
|
|
31
|
-
assert.strictEqual(_.convertDate('20210101', 'YYYY-MM-DD'), '2021-01-01');
|
|
32
|
-
assert.strictEqual(_.convertDate('20210101', 'YYYY'), '2021');
|
|
33
|
-
assert.strictEqual(_.convertDate('2021', 'YYYY-MM-DD'), '2021-01-01');
|
|
34
|
-
done();
|
|
35
|
-
});
|
|
36
|
-
});
|
package/test/format.spec.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const _ = require('../format');
|
|
3
|
-
|
|
4
|
-
describe('Format', () => {
|
|
5
|
-
it('number', (done) => {
|
|
6
|
-
assert.strictEqual(_.number('1234'), '1,234');
|
|
7
|
-
assert.strictEqual(_.number(1234), '1,234');
|
|
8
|
-
assert.strictEqual(_.number(12345678), '12,345,678');
|
|
9
|
-
assert.strictEqual(_.number(null), '0');
|
|
10
|
-
done();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('fileName', (done) => {
|
|
14
|
-
assert.strictEqual(_.fileName('C:\\Users\\test\\Desktop\\text.txt'), 'text');
|
|
15
|
-
assert.strictEqual(_.fileName('/home/user/Desktop/example.txt'), 'example');
|
|
16
|
-
assert.strictEqual(_.fileName('C:\\example.txt', true), 'example.txt');
|
|
17
|
-
done();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('fileSize', (done) => {
|
|
21
|
-
assert.strictEqual(_.fileExt('C:\\Users\\test\\Desktop\\text.txt'), 'txt');
|
|
22
|
-
assert.strictEqual(_.fileExt('hello.html'), 'html');
|
|
23
|
-
assert.strictEqual(_.fileExt('this.is.file.PNG'), 'png');
|
|
24
|
-
assert.strictEqual(_.fileExt('no-ext'), 'Unknown');
|
|
25
|
-
done();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('fileExt', (done) => {
|
|
29
|
-
assert.strictEqual(_.fileSize(1), '1 Bytes');
|
|
30
|
-
assert.strictEqual(_.fileSize(1000000), '976.56 KB');
|
|
31
|
-
assert.strictEqual(_.fileSize(2000, 3), '1.953 KB');
|
|
32
|
-
assert.strictEqual(_.fileSize(250000000), '238.42 MB');
|
|
33
|
-
done();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('msToTime', (done) => {
|
|
37
|
-
assert.strictEqual(_.msToTime(100000), '00:01:40');
|
|
38
|
-
assert.strictEqual(_.msToTime(100000, true), '00:01:40.0');
|
|
39
|
-
assert.strictEqual(_.msToTime(100000, false, '-'), '00-01-40');
|
|
40
|
-
assert.strictEqual(_.msToTime(123456789), '34:17:36');
|
|
41
|
-
done();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('secToTime', (done) => {
|
|
45
|
-
assert.strictEqual(_.secToTime(60), '00:01:00');
|
|
46
|
-
assert.strictEqual(_.secToTime(3800, '-'), '01-03-20');
|
|
47
|
-
assert.strictEqual(_.secToTime(360000), '100:00:00');
|
|
48
|
-
done();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('license', (done) => {
|
|
52
|
-
assert(_.license({ type: 'mit', author: 'example', yearStart: 2021 }));
|
|
53
|
-
assert(_.license({ author: 'example', yearStart: 2021 }));
|
|
54
|
-
done();
|
|
55
|
-
});
|
|
56
|
-
});
|
package/test/math.spec.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const _ = require('../math');
|
|
3
|
-
|
|
4
|
-
describe('Math', () => {
|
|
5
|
-
it('rand', (done) => {
|
|
6
|
-
assert(typeof _.rand() === 'number');
|
|
7
|
-
assert(typeof _.rand(1) === 'number');
|
|
8
|
-
assert(typeof _.rand(1, 2) === 'number');
|
|
9
|
-
for (let i = 0; i < 50; i += 1) {
|
|
10
|
-
assert(_.rand() <= 1);
|
|
11
|
-
assert(_.rand(5) <= 5);
|
|
12
|
-
const offsetTest = _.rand(5, 10);
|
|
13
|
-
assert(offsetTest >= 5 && offsetTest <= 10);
|
|
14
|
-
}
|
|
15
|
-
done();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('add', (done) => {
|
|
19
|
-
assert.strictEqual(_.add(1, 2, 3, 4), 10);
|
|
20
|
-
assert.strictEqual(_.add([1, 2, 3]), 6);
|
|
21
|
-
done();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('mul', (done) => {
|
|
25
|
-
assert.strictEqual(_.mul(1, 2, 3, 4), 24);
|
|
26
|
-
assert.strictEqual(_.mul([1, 2, 3]), 6);
|
|
27
|
-
assert.strictEqual(_.mul(1, 5, 7, 0, 9), 0);
|
|
28
|
-
done();
|
|
29
|
-
});
|
|
30
|
-
});
|
package/test/misc.spec.js
DELETED
package/test/string.spec.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const _ = require('../string');
|
|
3
|
-
|
|
4
|
-
describe('String', () => {
|
|
5
|
-
it('removeSpecialChar', (done) => {
|
|
6
|
-
assert.strictEqual(_.removeSpecialChar('1 2!3☆4@5+6─🌍'), '123456');
|
|
7
|
-
assert.strictEqual(_.removeSpecialChar('Hello, World!'), 'HelloWorld');
|
|
8
|
-
assert.strictEqual(_.removeSpecialChar('12 34-56,78=90'), '1234567890');
|
|
9
|
-
assert.strictEqual(_.removeSpecialChar('ABC가나다ㄱㄴㄷㅏㅑㅓ天地人'), 'ABC가나다ㄱㄴㄷㅏㅑㅓ天地人');
|
|
10
|
-
assert.strictEqual(_.removeSpecialChar('Hello World', true), 'Hello World');
|
|
11
|
-
done();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('removeNewLine', (done) => {
|
|
15
|
-
assert.strictEqual(_.removeNewLine(`te
|
|
16
|
-
st`), 'test');
|
|
17
|
-
assert.strictEqual(_.removeNewLine('te\rst'), 'test');
|
|
18
|
-
assert.strictEqual(_.removeNewLine('te\nst'), 'test');
|
|
19
|
-
assert.strictEqual(_.removeNewLine('te\r\nst'), 'test');
|
|
20
|
-
assert.strictEqual(_.removeNewLine('te\r\nst', '|'), 'te|st');
|
|
21
|
-
assert.strictEqual(_.removeNewLine('t\ne\r\ns\rt', '-'), 't-e-s-t');
|
|
22
|
-
done();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('capitalizeFirst', (done) => {
|
|
26
|
-
assert.strictEqual(_.capitalizeFirst('t'), 'T');
|
|
27
|
-
assert.strictEqual(_.capitalizeFirst('test'), 'Test');
|
|
28
|
-
assert.strictEqual(_.capitalizeFirst('tEST'), 'TEST');
|
|
29
|
-
done();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('capitalizeEachWords', (done) => {
|
|
33
|
-
assert.strictEqual(_.capitalizeEachWords('hello, world!'), 'Hello, World!');
|
|
34
|
-
assert.strictEqual(_.capitalizeEachWords('test'), 'Test');
|
|
35
|
-
assert.strictEqual(_.capitalizeEachWords('this is the test sentence.', true), 'This is the Test Sentence.');
|
|
36
|
-
done();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('count', (done) => {
|
|
40
|
-
assert.strictEqual(_.count('hello', 'l'), 2);
|
|
41
|
-
assert.strictEqual(_.count('abcdABCD', 'a'), 1);
|
|
42
|
-
assert.strictEqual(_.count('aaaaaa', 'a'), 6);
|
|
43
|
-
assert.strictEqual(_.count('hello', 'll'), 1);
|
|
44
|
-
done();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('shuffle', (done) => {
|
|
48
|
-
assert(_.shuffle('hi'));
|
|
49
|
-
assert(_.shuffle('abc def ghi'));
|
|
50
|
-
done();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('createRandomCode', (done) => {
|
|
54
|
-
assert(_.createRandom());
|
|
55
|
-
assert(_.createRandom(5));
|
|
56
|
-
assert(_.createRandom(10));
|
|
57
|
-
done();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('hideRandom', (done) => {
|
|
61
|
-
assert(_.hideRandom('test'));
|
|
62
|
-
assert(_.hideRandom('test', 2));
|
|
63
|
-
assert(_.hideRandom('test', 2, '#'));
|
|
64
|
-
done();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('truncate', (done) => {
|
|
68
|
-
assert.strictEqual(_.truncate('test', 2), 'te');
|
|
69
|
-
assert.strictEqual(_.truncate('test', 1, '...'), 't...');
|
|
70
|
-
done();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('encrypt', (done) => {
|
|
74
|
-
assert(_.encrypt('test', '12345678901234567890123456789012'));
|
|
75
|
-
assert(_.encrypt('test', '12345678901234567890123456789012', 'aes-256-gcm', 16));
|
|
76
|
-
done();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('decrypt', (done) => {
|
|
80
|
-
assert.strictEqual(_.decrypt('61ba43b65fc3fc2bdbd0d1ad8576344d:1831d7c37d12b3bf7ee73195d31af91b', '12345678901234567890123456789012'), 'test');
|
|
81
|
-
done();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('md5', (done) => {
|
|
85
|
-
assert.strictEqual(_.md5('test'), '098f6bcd4621d373cade4e832627b4f6');
|
|
86
|
-
assert.strictEqual(_.md5('qsu-md5'), '94af002364e42b514badb41b870ceb04');
|
|
87
|
-
done();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('sha1', (done) => {
|
|
91
|
-
assert.strictEqual(_.sha1('test'), 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3');
|
|
92
|
-
assert.strictEqual(_.sha1('qsu-md5'), 'e5c5dc3b2be3542475671d460f906c3b176bb5bf');
|
|
93
|
-
done();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('sha256', (done) => {
|
|
97
|
-
assert.strictEqual(_.sha256('test'), '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08');
|
|
98
|
-
assert.strictEqual(_.sha256('qsu-md5'), '8c4cfec3ec79dc572958ea7f0e3cfd24b90d174969df9a4773b37b68498871ed');
|
|
99
|
-
done();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('unique', (done) => {
|
|
103
|
-
assert.strictEqual(_.unique('ababcdcd'), 'abcd');
|
|
104
|
-
assert.strictEqual(_.unique('abc--11111'), 'abc-1');
|
|
105
|
-
done();
|
|
106
|
-
});
|
|
107
|
-
});
|
package/test/verify.spec.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const _ = require('../verify');
|
|
3
|
-
|
|
4
|
-
describe('Verify', () => {
|
|
5
|
-
it('empty', (done) => {
|
|
6
|
-
assert.strictEqual(_.empty(''), true);
|
|
7
|
-
assert.strictEqual(_.empty('1234'), false);
|
|
8
|
-
assert.strictEqual(_.empty(1234), false);
|
|
9
|
-
assert.strictEqual(_.empty(1.234), false);
|
|
10
|
-
assert.strictEqual(_.empty(null), true);
|
|
11
|
-
assert.strictEqual(_.empty([]), true);
|
|
12
|
-
assert.strictEqual(_.empty([{}]), false);
|
|
13
|
-
assert.strictEqual(_.empty([[]]), false);
|
|
14
|
-
assert.strictEqual(_.empty(['1234']), false);
|
|
15
|
-
assert.strictEqual(_.empty({}), true);
|
|
16
|
-
assert.strictEqual(_.empty({ a: '1234' }), false);
|
|
17
|
-
done();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('isUrl', (done) => {
|
|
21
|
-
assert.strictEqual(_.isUrl(''), false);
|
|
22
|
-
assert.strictEqual(_.isUrl('https://'), false);
|
|
23
|
-
assert.strictEqual(_.isUrl('www.google.com'), false);
|
|
24
|
-
assert.strictEqual(_.isUrl('www.google.com', true), true);
|
|
25
|
-
assert.strictEqual(_.isUrl('https://google.com'), true);
|
|
26
|
-
assert.strictEqual(_.isUrl('https://google.com', true), true);
|
|
27
|
-
assert.strictEqual(_.isUrl('https://google'), true);
|
|
28
|
-
assert.strictEqual(_.isUrl('https://google', false, true), false);
|
|
29
|
-
assert.strictEqual(_.isUrl('https://google.com?query=qsu'), true);
|
|
30
|
-
done();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('contains', (done) => {
|
|
34
|
-
assert.strictEqual(_.contains('12345', '3'), true);
|
|
35
|
-
assert.strictEqual(_.contains('12345', '10'), false);
|
|
36
|
-
assert.strictEqual(_.contains('ABC', ['A', 'B', 'C']), true);
|
|
37
|
-
assert.strictEqual(_.contains('ABC', ['D', 'E', 'F']), false);
|
|
38
|
-
assert.strictEqual(_.contains('ABC', ['AB', 'C'], true), false);
|
|
39
|
-
assert.strictEqual(_.contains('AB', ['AB', 'C', 'D'], true), true);
|
|
40
|
-
done();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('is2dArray', (done) => {
|
|
44
|
-
assert.strictEqual(_.is2dArray([]), false);
|
|
45
|
-
assert.strictEqual(_.is2dArray([[], []]), true);
|
|
46
|
-
assert.strictEqual(_.is2dArray('A'), false);
|
|
47
|
-
assert.strictEqual(_.is2dArray([{ a: 1 }, { b: 2 }]), false);
|
|
48
|
-
assert.strictEqual(_.is2dArray([[1], [2]]), true);
|
|
49
|
-
done();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('between', (done) => {
|
|
53
|
-
assert.strictEqual(_.between(1, [1, 10]), false);
|
|
54
|
-
assert.strictEqual(_.between(1, [1, 10], true), true);
|
|
55
|
-
assert.strictEqual(_.between(11, [10, 100]), true);
|
|
56
|
-
done();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('length', (done) => {
|
|
60
|
-
assert.strictEqual(_.length('12345'), 5);
|
|
61
|
-
assert.strictEqual(_.length(12345), 5);
|
|
62
|
-
assert.strictEqual(_.length(() => '123'), 3);
|
|
63
|
-
assert.strictEqual(_.length([1, 2, 3, 4]), 4);
|
|
64
|
-
assert.strictEqual(_.length({ hello: 'world', lorem: 'ipsum' }), 2);
|
|
65
|
-
assert.strictEqual(_.length([{ hello: 1, world: 2 }, { lorem: 3 }]), 2);
|
|
66
|
-
done();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('isBotAgent', (done) => {
|
|
70
|
-
assert.strictEqual(_.isBotAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html'), true);
|
|
71
|
-
assert.strictEqual(_.isBotAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'), false);
|
|
72
|
-
done();
|
|
73
|
-
});
|
|
74
|
-
});
|