@awesomeness-js/utils 1.0.24 → 1.0.25
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/build/build.js +11 -11
- package/build/postBuild.js +8 -8
- package/eslint.config.js +90 -0
- package/index.js +77 -74
- package/package.json +25 -25
- package/schemas/schema1.js +5 -1
- package/schemas/schema2.js +5 -1
- package/schemas.js +2 -2
- package/src/build.js +12 -8
- package/src/clean/boolean.js +27 -17
- package/src/clean/integer.js +85 -69
- package/src/clean/number.js +103 -86
- package/src/clean/string.js +91 -67
- package/src/clean/timestamp.js +61 -45
- package/src/clean/uuid.js +38 -25
- package/src/collectImports.js +195 -0
- package/src/combineFiles.js +45 -36
- package/src/convertBytes.js +12 -7
- package/src/decrypt.js +17 -9
- package/src/each.js +26 -4
- package/src/eachAsync.js +35 -19
- package/src/encrypt.js +22 -17
- package/src/getAllFiles.js +55 -41
- package/src/ignoreFolder/ignoreMe.js +6 -2
- package/src/ignoreMe.js +4 -2
- package/src/isUUID.js +4 -0
- package/src/md5.js +5 -1
- package/src/password/check.js +7 -3
- package/src/password/hash.js +12 -7
- package/src/setLocalEnvs.js +16 -3
- package/src/thingType.js +62 -24
- package/src/toPennies.js +23 -5
- package/src/utils/buildExportsTree.js +45 -17
- package/src/utils/buildFileDataList.js +32 -17
- package/src/utils/clean.js +205 -120
- package/src/utils/extractJSDocComment.js +14 -7
- package/src/utils/generateFile.js +20 -18
- package/src/utils/generateFlatExportLines.js +34 -17
- package/src/utils/generateImportStatements.js +15 -7
- package/src/utils/generateNamedExports.js +20 -9
- package/src/utils/generateNamespaceCode.js +45 -24
- package/src/utils/generateNamespaceExportLines.js +16 -7
- package/src/utils/shouldIgnore.js +57 -37
- package/src/uuid.js +9 -7
- package/src/validateSchema.js +95 -77
- package/test/collectImports.js +8 -0
- package/test/css/some.css +3 -0
- package/test/css/some.js +5 -0
- package/test/ignoreFolder/ignoreMe.js +3 -1
- package/test/ignoreFolder/ignoreMe2.js +3 -1
- package/test/ignoreFolder2/ignoreMe.js +6 -2
- package/test/js/abc.test.js +7 -3
- package/test/js/some.js +5 -0
- package/test/secret.test.js +1 -1
- package/tests/clean/array.test.js +122 -74
- package/tests/clean/boolean.test.js +18 -6
- package/tests/clean/integer.test.js +25 -9
- package/tests/clean/number.test.js +49 -13
- package/tests/clean/object.test.js +190 -119
- package/tests/clean/string.test.js +48 -17
- package/tests/clean/timestamp.test.js +12 -5
- package/tests/clean/uuid.test.js +13 -6
- package/tests/collectImports.test.js +66 -0
- package/tests/combineFiles.test.js +28 -26
- package/tests/convertBytes.test.js +8 -3
- package/tests/env.test.js +9 -3
- package/tests/example.test.js +7 -3
- package/tests/fileList.test.js +16 -12
- package/tests/hash-and-encrypt.test.js +13 -4
- package/tests/md5.test.js +7 -2
- package/tests/uuid.test.js +10 -4
- package/tests/validateSchema.test.js +21 -9
- package/tsconfig.json +20 -16
- package/types/collectImports.d.ts +6 -0
- package/types/index.d.ts +3 -0
package/src/password/hash.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
randomBytes, pbkdf2Sync
|
|
3
|
+
} from 'crypto';
|
|
2
4
|
|
|
3
5
|
// Hash a password using Node.js built-in crypto (no external deps).
|
|
4
6
|
export default function hashPassword(password) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
|
|
8
|
+
// Generate a random 16-byte salt
|
|
9
|
+
const salt = randomBytes(16).toString('hex');
|
|
10
|
+
// Derive a 64-byte key using PBKDF2 with 100k iterations (adjust as needed)
|
|
11
|
+
const derivedKey = pbkdf2Sync(password, salt, 100000, 64, 'sha512');
|
|
12
|
+
// Return salt and hash combined as a single string
|
|
13
|
+
|
|
14
|
+
return `${salt}::${derivedKey.toString('hex')}`;
|
|
15
|
+
|
|
11
16
|
}
|
package/src/setLocalEnvs.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { readFile } from 'fs/promises';
|
|
2
|
+
|
|
2
3
|
export default async (localSecretsPath = './secrets/local.env') => {
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
// get the file
|
|
5
6
|
let localSecrets = await readFile(localSecretsPath, 'utf8');
|
|
6
7
|
|
|
7
8
|
// parse the file
|
|
8
9
|
let lines = localSecrets.split('\n');
|
|
10
|
+
|
|
11
|
+
|
|
9
12
|
for(let line of lines){
|
|
10
13
|
|
|
11
14
|
// skip #
|
|
12
|
-
if(line[0] === '#'){
|
|
15
|
+
if(line[0] === '#'){
|
|
16
|
+
|
|
17
|
+
continue;
|
|
18
|
+
|
|
19
|
+
}
|
|
13
20
|
|
|
14
21
|
let parts = line.split('=');
|
|
15
22
|
|
|
@@ -17,7 +24,9 @@ export default async (localSecretsPath = './secrets/local.env') => {
|
|
|
17
24
|
|
|
18
25
|
// remove \r
|
|
19
26
|
if(parts[1][parts[1].length - 1] === '\r'){
|
|
27
|
+
|
|
20
28
|
parts[1] = parts[1].substring(0, parts[1].length - 1);
|
|
29
|
+
|
|
21
30
|
}
|
|
22
31
|
|
|
23
32
|
// remove outside single quotes
|
|
@@ -25,14 +34,18 @@ export default async (localSecretsPath = './secrets/local.env') => {
|
|
|
25
34
|
parts[1][0] === "'"
|
|
26
35
|
&& parts[1][parts[1].length - 1] === "'"
|
|
27
36
|
){
|
|
37
|
+
|
|
28
38
|
parts[1] = parts[1].substring(1, parts[1].length - 1);
|
|
39
|
+
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
|
|
32
43
|
|
|
33
44
|
process.env[parts[0]] = parts[1];
|
|
45
|
+
|
|
34
46
|
}
|
|
47
|
+
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
|
|
38
|
-
}
|
|
51
|
+
};
|
package/src/thingType.js
CHANGED
|
@@ -1,35 +1,73 @@
|
|
|
1
|
-
import isUUID from './isUUID.js'
|
|
1
|
+
import isUUID from './isUUID.js';
|
|
2
|
+
|
|
2
3
|
export default (thing) => {
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
if (thing === undefined) {
|
|
6
|
+
|
|
7
|
+
return 'undefined';
|
|
8
|
+
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (thing === null) {
|
|
12
|
+
|
|
13
|
+
return 'null';
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let type = typeof thing;
|
|
18
|
+
|
|
19
|
+
let same = [ 'undefined', 'null', 'boolean', 'function', 'symbol', 'bigint' ].includes(type);
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if (same) {
|
|
23
|
+
|
|
24
|
+
return type;
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// array vs object
|
|
29
|
+
if (type === 'object' && thing !== null) {
|
|
30
|
+
|
|
31
|
+
type = Array.isArray(thing) ? 'array' : 'object';
|
|
32
|
+
|
|
33
|
+
return type;
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// integer vs double
|
|
38
|
+
if (type === 'number') {
|
|
39
|
+
|
|
40
|
+
type = Number.isInteger(thing) ? 'integer' : 'number';
|
|
41
|
+
|
|
42
|
+
return type;
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// string vs iso timestamp vs uuid
|
|
47
|
+
let is_uuid = isUUID(thing);
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if(is_uuid){
|
|
51
|
+
|
|
52
|
+
type = 'uuid';
|
|
53
|
+
|
|
54
|
+
return type;
|
|
55
|
+
|
|
56
|
+
}
|
|
6
57
|
|
|
7
|
-
|
|
58
|
+
let is_iso_dateTime = thing && typeof thing === 'string' && thing.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?$/);
|
|
8
59
|
|
|
9
|
-
let same = ['undefined', 'null', 'boolean', 'function', 'symbol', 'bigint'].includes(type);
|
|
10
|
-
if (same) { return type; }
|
|
11
60
|
|
|
12
|
-
|
|
13
|
-
if (type === 'object' && thing !== null) {
|
|
14
|
-
type = Array.isArray(thing) ? 'array' : 'object';
|
|
15
|
-
return type;
|
|
16
|
-
}
|
|
61
|
+
if(is_iso_dateTime) {
|
|
17
62
|
|
|
18
|
-
|
|
19
|
-
if (type === 'number') {
|
|
20
|
-
type = Number.isInteger(thing) ? 'integer' : 'number';
|
|
21
|
-
return type;
|
|
22
|
-
}
|
|
63
|
+
type = 'timestamp';
|
|
23
64
|
|
|
24
|
-
|
|
25
|
-
let is_uuid = isUUID(thing);
|
|
26
|
-
if(is_uuid){ type = 'uuid'; return type; }
|
|
65
|
+
return type;
|
|
27
66
|
|
|
28
|
-
|
|
29
|
-
if(is_iso_dateTime) { type = 'timestamp'; return type; }
|
|
67
|
+
}
|
|
30
68
|
|
|
31
|
-
|
|
69
|
+
return type;
|
|
32
70
|
|
|
33
|
-
|
|
34
|
-
}
|
|
71
|
+
|
|
72
|
+
};
|
|
35
73
|
|
package/src/toPennies.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
export default function toPennies(uglyMoney){
|
|
2
2
|
|
|
3
|
-
if(!uglyMoney){
|
|
4
|
-
|
|
3
|
+
if(!uglyMoney){
|
|
4
|
+
|
|
5
|
+
return 0;
|
|
6
|
+
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if(uglyMoney.length == 0){
|
|
10
|
+
|
|
11
|
+
return 0;
|
|
12
|
+
|
|
13
|
+
}
|
|
5
14
|
|
|
6
15
|
// trim all whitespace from string
|
|
7
16
|
uglyMoney = uglyMoney.replace(/\s/g,'');
|
|
@@ -9,11 +18,20 @@ export default function toPennies(uglyMoney){
|
|
|
9
18
|
let hasDecimal = uglyMoney.includes(".");
|
|
10
19
|
let cleanMoney_v1 = uglyMoney.replace(/\D/g,'');
|
|
11
20
|
|
|
12
|
-
if(cleanMoney_v1.length == 0){
|
|
21
|
+
if(cleanMoney_v1.length == 0){
|
|
22
|
+
|
|
23
|
+
return 0;
|
|
24
|
+
|
|
25
|
+
}
|
|
13
26
|
|
|
14
27
|
let cleanMoney = cleanMoney_v1*1;
|
|
15
28
|
|
|
16
|
-
if(!hasDecimal){
|
|
29
|
+
if(!hasDecimal){
|
|
30
|
+
|
|
31
|
+
cleanMoney = cleanMoney * 100;
|
|
32
|
+
|
|
33
|
+
}
|
|
17
34
|
|
|
18
35
|
return cleanMoney;
|
|
19
|
-
|
|
36
|
+
|
|
37
|
+
}
|
|
@@ -1,19 +1,47 @@
|
|
|
1
1
|
export default function buildExportsTree(fileDataList) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
|
|
3
|
+
const flatExports = [];
|
|
4
|
+
const nestedExports = {};
|
|
5
|
+
|
|
6
|
+
fileDataList.forEach(({
|
|
7
|
+
parts, functionName, importVarName, jsDocComment
|
|
8
|
+
}) => {
|
|
9
|
+
|
|
10
|
+
if (parts.length === 0) {
|
|
11
|
+
|
|
12
|
+
flatExports.push({
|
|
13
|
+
functionName,
|
|
14
|
+
importVarName,
|
|
15
|
+
jsDocComment
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
} else {
|
|
19
|
+
|
|
20
|
+
let current = nestedExports;
|
|
21
|
+
|
|
22
|
+
parts.forEach((part) => {
|
|
23
|
+
|
|
24
|
+
if (!current[part]) {
|
|
25
|
+
|
|
26
|
+
current[part] = {};
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
current = current[part];
|
|
31
|
+
|
|
32
|
+
});
|
|
33
|
+
current[functionName] = {
|
|
34
|
+
importVarName,
|
|
35
|
+
jsDocComment
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
flatExports,
|
|
44
|
+
nestedExports
|
|
45
|
+
};
|
|
46
|
+
|
|
19
47
|
}
|
|
@@ -3,21 +3,36 @@ import extractJSDocComment from './extractJSDocComment.js';
|
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
|
|
5
5
|
export default function buildFileDataList(src, ignore, includeComments) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
|
|
7
|
+
const allFiles = getAllFiles(src, {
|
|
8
|
+
ignore,
|
|
9
|
+
fileTypes: [ '.js' ]
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
return allFiles.map((file) => {
|
|
14
|
+
|
|
15
|
+
const normalizedFile = file.replace(/\\/g, '/');
|
|
16
|
+
const parts = normalizedFile.split('/');
|
|
17
|
+
const fileName = parts.pop();
|
|
18
|
+
const functionName = fileName.replace(/\.js$/, '');
|
|
19
|
+
const namespaceParts = parts;
|
|
20
|
+
const importVarName = namespaceParts.length > 0
|
|
21
|
+
? '_' + [ ...namespaceParts, functionName ].join('_')
|
|
22
|
+
: '_' + functionName;
|
|
23
|
+
const importPath = src + '/' + normalizedFile.replace(/\.js$/, '');
|
|
24
|
+
const jsDocComment = includeComments ? extractJSDocComment(join(src, normalizedFile)) : '';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
normalizedFile,
|
|
29
|
+
parts: namespaceParts,
|
|
30
|
+
functionName,
|
|
31
|
+
importVarName,
|
|
32
|
+
importPath,
|
|
33
|
+
jsDocComment
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
});
|
|
37
|
+
|
|
23
38
|
}
|