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