@awesomeness-js/utils 1.0.19 → 1.0.21

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 (60) hide show
  1. package/build/build.js +7 -0
  2. package/index.js +35 -0
  3. package/package.json +13 -10
  4. package/schemas/schema1.js +121 -0
  5. package/schemas/schema2.js +121 -0
  6. package/schemas.js +15 -0
  7. package/src/clean/array.js +2 -0
  8. package/src/clean/boolean.js +22 -0
  9. package/src/clean/integer.js +74 -0
  10. package/src/clean/number.js +93 -0
  11. package/src/clean/object.js +3 -0
  12. package/src/clean/string.js +60 -0
  13. package/src/clean/timestamp.js +52 -0
  14. package/src/clean/uuid.js +33 -0
  15. package/src/combineFiles.js +10 -1
  16. package/src/decrypt.js +5 -3
  17. package/src/each.js +10 -0
  18. package/src/encrypt.js +5 -2
  19. package/src/setLocalEnvs.js +9 -4
  20. package/src/thingType.js +35 -0
  21. package/src/utils/clean.js +183 -0
  22. package/src/validateSchema.js +86 -0
  23. package/test/js/abc.test.js +6 -0
  24. package/test/secret.test.js +7 -1
  25. package/tests/clean/array.test.js +154 -0
  26. package/tests/clean/boolean.test.js +27 -0
  27. package/tests/clean/integer.test.js +39 -0
  28. package/tests/clean/number.test.js +49 -0
  29. package/tests/clean/object.test.js +172 -0
  30. package/tests/clean/string.test.js +44 -0
  31. package/tests/clean/timestamp.test.js +13 -0
  32. package/tests/clean/uuid.test.js +14 -0
  33. package/tests/combineFiles.test.js +24 -0
  34. package/tests/convertBytes.test.js +9 -0
  35. package/tests/env.test.js +17 -0
  36. package/tests/example.test.js +6 -0
  37. package/tests/fileList.test.js +21 -0
  38. package/tests/hash-and-encrypt.test.js +26 -0
  39. package/tests/md5.test.js +7 -0
  40. package/tests/uuid.test.js +15 -0
  41. package/tests/validateSchema.test.js +30 -0
  42. package/tsconfig.json +2 -1
  43. package/types/clean/array.d.ts +1 -0
  44. package/types/clean/boolean.d.ts +3 -0
  45. package/types/clean/integer.d.ts +6 -0
  46. package/types/clean/number.d.ts +8 -0
  47. package/types/clean/object.d.ts +1 -0
  48. package/types/clean/string.d.ts +7 -0
  49. package/types/clean/thing.d.ts +2 -0
  50. package/types/clean/timestamp.d.ts +5 -0
  51. package/types/clean/uuid.d.ts +3 -0
  52. package/types/each.d.ts +10 -1
  53. package/types/hashPassword.d.ts +1 -1
  54. package/types/index.d.ts +35 -0
  55. package/types/thingType.d.ts +2 -0
  56. package/types/utils/clean.d.ts +2 -0
  57. package/types/validatePassword.d.ts +1 -1
  58. package/types/validateSchema.d.ts +2 -0
  59. package/vitest.config.js +16 -0
  60. package/test.js +0 -58
package/types/index.d.ts CHANGED
@@ -4,6 +4,14 @@
4
4
  * Do not edit manually.
5
5
  */
6
6
  import type _build from './build';
7
+ import type _clean_array from './clean/array';
8
+ import type _clean_boolean from './clean/boolean';
9
+ import type _clean_integer from './clean/integer';
10
+ import type _clean_number from './clean/number';
11
+ import type _clean_object from './clean/object';
12
+ import type _clean_string from './clean/string';
13
+ import type _clean_timestamp from './clean/timestamp';
14
+ import type _clean_uuid from './clean/uuid';
7
15
  import type _combineFiles from './combineFiles';
8
16
  import type _convertBytes from './convertBytes';
9
17
  import type _decrypt from './decrypt';
@@ -18,9 +26,11 @@ import type _md5 from './md5';
18
26
  import type _password_check from './password/check';
19
27
  import type _password_hash from './password/hash';
20
28
  import type _setLocalEnvs from './setLocalEnvs';
29
+ import type _thingType from './thingType';
21
30
  import type _toPennies from './toPennies';
22
31
  import type _utils_buildExportsTree from './utils/buildExportsTree';
23
32
  import type _utils_buildFileDataList from './utils/buildFileDataList';
33
+ import type _utils_clean from './utils/clean';
24
34
  import type _utils_extractJSDocComment from './utils/extractJSDocComment';
25
35
  import type _utils_generateFile from './utils/generateFile';
26
36
  import type _utils_generateFlatExportLines from './utils/generateFlatExportLines';
@@ -30,6 +40,7 @@ import type _utils_generateNamespaceCode from './utils/generateNamespaceCode';
30
40
  import type _utils_generateNamespaceExportLines from './utils/generateNamespaceExportLines';
31
41
  import type _utils_shouldIgnore from './utils/shouldIgnore';
32
42
  import type _uuid from './uuid';
43
+ import type _validateSchema from './validateSchema';
33
44
 
34
45
  export declare const build: typeof _build;
35
46
  export declare const combineFiles: typeof _combineFiles;
@@ -43,8 +54,10 @@ export declare const ignoreMe: typeof _ignoreMe;
43
54
  export declare const isUUID: typeof _isUUID;
44
55
  export declare const md5: typeof _md5;
45
56
  export declare const setLocalEnvs: typeof _setLocalEnvs;
57
+ export declare const thingType: typeof _thingType;
46
58
  export declare const toPennies: typeof _toPennies;
47
59
  export declare const uuid: typeof _uuid;
60
+ export declare const validateSchema: typeof _validateSchema;
48
61
 
49
62
  declare const _default: {
50
63
  /**
@@ -70,6 +83,15 @@ declare const _default: {
70
83
  */
71
84
  convertBytes: typeof _convertBytes;
72
85
  decrypt: typeof _decrypt;
86
+ /**
87
+ * Iterates over elements of an array or properties of an object, invoking a callback for each element/property.
88
+ * The iteration stops if the callback returns `false`.
89
+ *
90
+ * @example each({ a: 1, b: 2 }, (value, key) => { console.log(value, key); });
91
+ * @param {Object|Array} objectOrArray - The object or array to iterate over.
92
+ * @param {Function} callback - The function to invoke per iteration. It is invoked with two arguments: (value, key/index).
93
+ * @returns {void}
94
+ */
73
95
  each: typeof _each;
74
96
  eachAsync: typeof _eachAsync;
75
97
  encrypt: typeof _encrypt;
@@ -78,8 +100,20 @@ declare const _default: {
78
100
  isUUID: typeof _isUUID;
79
101
  md5: typeof _md5;
80
102
  setLocalEnvs: typeof _setLocalEnvs;
103
+ thingType: typeof _thingType;
81
104
  toPennies: typeof _toPennies;
82
105
  uuid: typeof _uuid;
106
+ validateSchema: typeof _validateSchema;
107
+ clean: {
108
+ array: typeof _clean_array,
109
+ boolean: typeof _clean_boolean,
110
+ integer: typeof _clean_integer,
111
+ number: typeof _clean_number,
112
+ object: typeof _clean_object,
113
+ string: typeof _clean_string,
114
+ timestamp: typeof _clean_timestamp,
115
+ uuid: typeof _clean_uuid,
116
+ },
83
117
  ignoreFolder: {
84
118
  ignoreMe: typeof _ignoreFolder_ignoreMe,
85
119
  },
@@ -90,6 +124,7 @@ declare const _default: {
90
124
  utils: {
91
125
  buildExportsTree: typeof _utils_buildExportsTree,
92
126
  buildFileDataList: typeof _utils_buildFileDataList,
127
+ clean: typeof _utils_clean,
93
128
  extractJSDocComment: typeof _utils_extractJSDocComment,
94
129
  generateFile: typeof _utils_generateFile,
95
130
  generateFlatExportLines: typeof _utils_generateFlatExportLines,
@@ -0,0 +1,2 @@
1
+ declare function _default(thing: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null";
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ export default cleanArray;
2
+ declare function cleanArray(arr: any, schema?: {}): any[];
@@ -1 +1 @@
1
- export default function validatePassword(password: any, storedHash: any): boolean;
1
+ export default function validatePassword(password: any, storedHash: any): boolean;
@@ -0,0 +1,2 @@
1
+ export default validateSchema;
2
+ declare function validateSchema(schema: any): boolean;
@@ -0,0 +1,16 @@
1
+ export default {
2
+ test: {
3
+ globals: true,
4
+ environment: 'node',
5
+ watchExclude: [
6
+ '**/node_modules/**',
7
+ '**/dist/**',
8
+ '**/coverage/**',
9
+ '**/.git/**',
10
+ '**/!(**/*.test.js)' // Ignore everything except test files
11
+ ],
12
+ testMatch: [
13
+ '**/*.test.js'
14
+ ]
15
+ },
16
+ }
package/test.js DELETED
@@ -1,58 +0,0 @@
1
- import utils from './index.js';
2
-
3
- let fileList2 = utils.getAllFiles('./test', {
4
- // fileTypes: ['.css'],
5
- // fileTypes: ['.js'],
6
- ignore: [
7
- "/ignoreFolder",
8
- "/ignoreFolder2/",
9
- "*.env",
10
- "*.test.js",
11
- "/css/*.js",
12
- "/js/*.css"
13
- ]
14
- })
15
-
16
- console.log({fileList2});
17
-
18
- let md5Test = utils.md5('test');
19
- console.log({md5Test});
20
-
21
- let uuidTest = utils.uuid();
22
- console.log({uuidTest});
23
-
24
- let convertBytesTest = utils.convertBytes(1024);
25
- console.log({convertBytesTest});
26
-
27
- let isUUIDTest = utils.isUUID(uuidTest);
28
- console.log({isUUIDTest});
29
-
30
- let combineTest = utils.combineFiles('./src', 'js');
31
- console.log('combineTest', combineTest.length);
32
-
33
- let combineTestBrowser = utils.combineFiles('./src', 'js', {
34
- moduleToBrowser: true
35
- });
36
- console.log('combineTestBrowser', combineTestBrowser.length);
37
-
38
- await utils.setLocalEnvs('./secrets/local.env');
39
- console.log('localEnv', process.env.JUST_A_TEST);
40
-
41
- await utils.setLocalEnvs('./secrets/dev.env');
42
- console.log('localEnv', process.env.JUST_A_TEST);
43
-
44
- const storedHash = utils.password.hash('mySecret123');
45
- console.log('Stored Hash:', storedHash);
46
- console.log('Is valid (correct password)?', utils.password.check('mySecret123', storedHash));
47
- console.log('Is valid (wrong password)?', utils.password.check('wrongPassword', storedHash));
48
-
49
-
50
- // Example 256-bit key for AES-256
51
- // In real usage, store this securely (e.g., an environment variable or key vault).
52
-
53
- const secretMessage = 'This is top secret!';
54
- const encrypted = utils.encrypt(secretMessage);
55
- console.log('Encrypted Data:', encrypted);
56
-
57
- const decrypted = utils.decrypt(encrypted);
58
- console.log('Decrypted Data:', decrypted);