@awesomeness-js/utils 1.1.22 → 1.2.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.
Files changed (77) hide show
  1. package/index.js +32 -0
  2. package/package.json +1 -1
  3. package/schemas/schema1.js +1 -8
  4. package/schemas/schema2.js +1 -8
  5. package/src/random/array.js +46 -0
  6. package/src/random/arrayValue.js +5 -0
  7. package/src/random/boolean.js +5 -0
  8. package/src/random/integer.js +8 -0
  9. package/src/random/number.js +17 -0
  10. package/src/random/object.js +46 -0
  11. package/src/random/string.js +10 -0
  12. package/src/random/timestamp.js +15 -0
  13. package/src/random/uuid.js +7 -0
  14. package/src/utils/clean.js +66 -73
  15. package/test/js/abc.test.js +1 -3
  16. package/tests/clean/array.test.js +1 -3
  17. package/tests/clean/boolean.test.js +1 -3
  18. package/tests/clean/integer.test.js +1 -3
  19. package/tests/clean/number.test.js +1 -3
  20. package/tests/clean/object.test.js +3 -4
  21. package/tests/clean/string.test.js +1 -3
  22. package/tests/clean/timestamp.test.js +1 -3
  23. package/tests/clean/uuid.test.js +1 -3
  24. package/tests/collectImports.test.js +1 -3
  25. package/tests/combineFiles.test.js +1 -3
  26. package/tests/convertBytes.test.js +1 -3
  27. package/tests/env.test.js +1 -3
  28. package/tests/example.test.js +1 -3
  29. package/tests/fileList.test.js +1 -3
  30. package/tests/hash-and-encrypt.test.js +1 -3
  31. package/tests/md5.test.js +1 -3
  32. package/tests/namedExports.test.js +1 -3
  33. package/tests/random.test.js +110 -0
  34. package/tests/uuid.test.js +1 -3
  35. package/tests/validateSchema.test.js +1 -3
  36. package/types/build.d.ts +10 -10
  37. package/types/clean/array.d.ts +6 -6
  38. package/types/clean/boolean.d.ts +3 -3
  39. package/types/clean/buffer.d.ts +12 -12
  40. package/types/clean/custom.d.ts +4 -4
  41. package/types/clean/file.d.ts +11 -11
  42. package/types/clean/integer.d.ts +6 -6
  43. package/types/clean/number.d.ts +8 -8
  44. package/types/clean/object.d.ts +6 -6
  45. package/types/clean/string.d.ts +10 -10
  46. package/types/clean/timestamp.d.ts +5 -5
  47. package/types/clean/uuid.d.ts +3 -3
  48. package/types/collectImports.d.ts +6 -6
  49. package/types/combineFiles.d.ts +8 -8
  50. package/types/convertBytes.d.ts +8 -8
  51. package/types/decrypt.d.ts +1 -1
  52. package/types/each.d.ts +10 -10
  53. package/types/eachAsync.d.ts +1 -1
  54. package/types/encrypt.d.ts +5 -5
  55. package/types/getAllFiles.d.ts +6 -6
  56. package/types/index.d.ts +150 -150
  57. package/types/isUUID.d.ts +1 -1
  58. package/types/md5.d.ts +2 -2
  59. package/types/password/check.d.ts +1 -1
  60. package/types/password/hash.d.ts +1 -1
  61. package/types/setLocalEnvs.d.ts +2 -2
  62. package/types/shouldIgnore.d.ts +1 -1
  63. package/types/thingType.d.ts +2 -2
  64. package/types/toPennies.d.ts +1 -1
  65. package/types/utils/buildExportsTree.d.ts +4 -4
  66. package/types/utils/buildFileDataList.d.ts +12 -12
  67. package/types/utils/clean.d.ts +27 -27
  68. package/types/utils/extractJSDocComment.d.ts +1 -1
  69. package/types/utils/generateFile.d.ts +8 -8
  70. package/types/utils/generateFlatExportLines.d.ts +7 -7
  71. package/types/utils/generateImportStatements.d.ts +5 -5
  72. package/types/utils/generateNamedExports.d.ts +7 -7
  73. package/types/utils/generateNamespaceCode.d.ts +7 -7
  74. package/types/utils/generateNamespaceExportLines.d.ts +6 -6
  75. package/types/uuid.d.ts +2 -2
  76. package/types/validateSchema.d.ts +2 -2
  77. package/types/wait.d.ts +1 -1
@@ -0,0 +1,110 @@
1
+ import { expect, test } from 'vitest';
2
+ import utils from '../index.js';
3
+ import schemas from '../schemas.js';
4
+
5
+ // string
6
+ test('should create a random string', () => {
7
+
8
+ const randomString = utils.random.string({ minLength: 5, maxLength: 10 });
9
+
10
+ console.log('Generated random string:', randomString);
11
+
12
+ expect(randomString.length).toBeGreaterThanOrEqual(5);
13
+ expect(randomString.length).toBeLessThanOrEqual(10);
14
+
15
+ });
16
+
17
+ // array value
18
+ test('should create a random array value', () => {
19
+ const sampleArray = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
20
+
21
+ const randomValue = utils.random.arrayValue(sampleArray);
22
+ console.log('Generated random array value:', randomValue);
23
+
24
+ expect(sampleArray).toContain(randomValue);
25
+
26
+ });
27
+
28
+ // boolean
29
+ test('should create a random boolean', () => {
30
+ const randomBoolean = utils.random.boolean();
31
+ console.log('Generated random boolean:', randomBoolean);
32
+ expect(typeof randomBoolean).toBe('boolean');
33
+ });
34
+
35
+ // integer
36
+ test('should create a random integer', () => {
37
+ const randomInteger = utils.random.integer({ min: 10, max: 20 });
38
+ console.log('Generated random integer:', randomInteger);
39
+
40
+ expect(randomInteger).toBeGreaterThanOrEqual(10);
41
+ expect(randomInteger).toBeLessThanOrEqual(20);
42
+ });
43
+
44
+ // number
45
+ test('should create a random number', () => {
46
+ const decimalPlaces = 3;
47
+ const randomNumber = utils.random.number({
48
+ min: 1.5,
49
+ max: 5.5,
50
+ decimalPlaces
51
+ });
52
+
53
+ console.log('Generated random number:', randomNumber);
54
+
55
+ expect(randomNumber).toBeGreaterThanOrEqual(1.5);
56
+ expect(randomNumber).toBeLessThanOrEqual(5.5);
57
+
58
+ const decimals =
59
+ Number.isInteger(randomNumber)
60
+ ? 0
61
+ : randomNumber.toString().split('.')[1].length;
62
+
63
+ expect(decimals).toBeLessThanOrEqual(decimalPlaces);
64
+ });
65
+
66
+ // timestamp
67
+ test('should create a random timestamp', () => {
68
+
69
+ const randomTimestamp = utils.random.timestamp({
70
+ maxDays: 10,
71
+ minDays: 5,
72
+ future: true
73
+ });
74
+
75
+ console.log('Generated random timestamp:', randomTimestamp);
76
+
77
+ const randomTimestampPast = utils.random.timestamp({
78
+ maxDays: 10,
79
+ minDays: 5,
80
+ future: false
81
+ });
82
+
83
+ console.log('Generated random past timestamp:', randomTimestampPast);
84
+
85
+ // should be an ISO string
86
+ expect(new Date(randomTimestamp).toISOString()).toBe(randomTimestamp);
87
+ expect(new Date(randomTimestampPast).toISOString()).toBe(randomTimestampPast);
88
+
89
+ });
90
+
91
+ // uuid
92
+ test('should create a random UUID', () => {
93
+ const randomUUID = utils.random.uuid();
94
+ console.log('Generated random UUID:', randomUUID);
95
+ expect(utils.isUUID(randomUUID)).toBe(true);
96
+ });
97
+
98
+ // object
99
+ test('should create a random object based on schema1', () => {
100
+
101
+ const randomObject = utils.random.object(schemas.schema1);
102
+ console.log('Generated random object (schema1):', randomObject);
103
+ expect(typeof randomObject).toBe('object');
104
+
105
+ expect(typeof randomObject.exampleId).toBe('string');
106
+ expect(Array.isArray(randomObject.exampleArray)).toBe(true);
107
+ expect(Array.isArray(randomObject.exampleArrayOfObjects)).toBe(true);
108
+ expect(typeof randomObject.exampleObject).toBe('object');
109
+
110
+ });
@@ -1,7 +1,5 @@
1
1
  // example.test.js
2
- import {
3
- expect, test
4
- } from 'vitest';
2
+ import { expect, test } from 'vitest';
5
3
  import utils from '../index.js';
6
4
 
7
5
  let uuid = utils.uuid();
@@ -1,6 +1,4 @@
1
- import {
2
- expect, test
3
- } from 'vitest';
1
+ import { expect, test } from 'vitest';
4
2
  import utils from '../index.js';
5
3
  import schemas from '../schemas.js';
6
4
 
package/types/build.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export default build;
2
- declare function build({ src, dest, exportRoots, ignore, includeComments, dts, useTabs, }?: {
3
- src?: string;
4
- dest?: string;
5
- exportRoots?: boolean;
6
- ignore?: any[];
7
- includeComments?: boolean;
8
- dts?: boolean;
9
- useTabs?: boolean;
10
- }): Promise<boolean>;
1
+ export default build;
2
+ declare function build({ src, dest, exportRoots, ignore, includeComments, dts, useTabs, }?: {
3
+ src?: string;
4
+ dest?: string;
5
+ exportRoots?: boolean;
6
+ ignore?: any[];
7
+ includeComments?: boolean;
8
+ dts?: boolean;
9
+ useTabs?: boolean;
10
+ }): Promise<boolean>;
@@ -1,6 +1,6 @@
1
- declare const _default: (arr: any, schema?: {}, { testMode, allOrNothing, path }?: {
2
- testMode?: boolean;
3
- allOrNothing?: boolean;
4
- path?: string;
5
- }) => any[];
6
- export default _default;
1
+ declare const _default: (arr: any, schema?: {}, { testMode, allOrNothing, path }?: {
2
+ testMode?: boolean;
3
+ allOrNothing?: boolean;
4
+ path?: string;
5
+ }) => any[];
6
+ export default _default;
@@ -1,3 +1,3 @@
1
- export default function cleanBoolean(x: any, { required }?: {
2
- required?: boolean;
3
- }): any;
1
+ export default function cleanBoolean(x: any, { required }?: {
2
+ required?: boolean;
3
+ }): any;
@@ -1,12 +1,12 @@
1
- export default function cleanBuffer(fileObj: any, { required, validTypes, minSize, maxSize, }?: {
2
- required?: boolean;
3
- validTypes?: any[];
4
- minSize?: boolean;
5
- maxSize?: boolean;
6
- }): {
7
- name: any;
8
- type: any;
9
- size: number;
10
- encoding: any;
11
- createdAt: string;
12
- };
1
+ export default function cleanBuffer(fileObj: any, { required, validTypes, minSize, maxSize, }?: {
2
+ required?: boolean;
3
+ validTypes?: any[];
4
+ minSize?: boolean;
5
+ maxSize?: boolean;
6
+ }): {
7
+ name: any;
8
+ type: any;
9
+ size: number;
10
+ encoding: any;
11
+ createdAt: string;
12
+ };
@@ -1,4 +1,4 @@
1
- export default function cleanCustom(value: any, { required, validate, }?: {
2
- required?: boolean;
3
- validate?: any;
4
- }): any;
1
+ export default function cleanCustom(value: any, { required, validate, }?: {
2
+ required?: boolean;
3
+ validate?: any;
4
+ }): any;
@@ -1,11 +1,11 @@
1
- export default function cleanFile(file: any, { required, validTypes, minSize, maxSize, }?: {
2
- required?: boolean;
3
- validTypes?: any[];
4
- minSize?: boolean;
5
- maxSize?: boolean;
6
- }): {
7
- name: any;
8
- type: any;
9
- size: any;
10
- lastModified: string;
11
- };
1
+ export default function cleanFile(file: any, { required, validTypes, minSize, maxSize, }?: {
2
+ required?: boolean;
3
+ validTypes?: any[];
4
+ minSize?: boolean;
5
+ maxSize?: boolean;
6
+ }): {
7
+ name: any;
8
+ type: any;
9
+ size: any;
10
+ lastModified: string;
11
+ };
@@ -1,6 +1,6 @@
1
- export default function cleanInt(x: any, { required, convertString, min, max, }?: {
2
- required?: boolean;
3
- convertString?: boolean;
4
- min?: boolean;
5
- max?: boolean;
6
- }): any;
1
+ export default function cleanInt(x: any, { required, convertString, min, max, }?: {
2
+ required?: boolean;
3
+ convertString?: boolean;
4
+ min?: boolean;
5
+ max?: boolean;
6
+ }): any;
@@ -1,8 +1,8 @@
1
- export default function cleanNumber(x: any, { required, convertString, min, max, maxDecimal, minDecimal, }?: {
2
- required?: boolean;
3
- convertString?: boolean;
4
- min?: boolean;
5
- max?: boolean;
6
- maxDecimal?: boolean;
7
- minDecimal?: boolean;
8
- }): any;
1
+ export default function cleanNumber(x: any, { required, convertString, min, max, maxDecimal, minDecimal, }?: {
2
+ required?: boolean;
3
+ convertString?: boolean;
4
+ min?: boolean;
5
+ max?: boolean;
6
+ maxDecimal?: boolean;
7
+ minDecimal?: boolean;
8
+ }): any;
@@ -1,6 +1,6 @@
1
- declare const _default: (obj: any, schema: any, { testMode, allOrNothing, path }?: {
2
- testMode?: boolean;
3
- allOrNothing?: boolean;
4
- path?: string;
5
- }) => {};
6
- export default _default;
1
+ declare const _default: (obj: any, schema: any, { testMode, allOrNothing, path }?: {
2
+ testMode?: boolean;
3
+ allOrNothing?: boolean;
4
+ path?: string;
5
+ }) => {};
6
+ export default _default;
@@ -1,10 +1,10 @@
1
- export default function cleanString(x: any, { required, minLength, maxLength, allowHtml, allowScripts, validValues, format, pattern }?: {
2
- required?: boolean;
3
- minLength?: boolean;
4
- maxLength?: boolean;
5
- allowHtml?: boolean;
6
- allowScripts?: boolean;
7
- validValues?: boolean;
8
- format?: boolean;
9
- pattern?: boolean;
10
- }): string;
1
+ export default function cleanString(x: any, { required, minLength, maxLength, allowHtml, allowScripts, validValues, format, pattern }?: {
2
+ required?: boolean;
3
+ minLength?: boolean;
4
+ maxLength?: boolean;
5
+ allowHtml?: boolean;
6
+ allowScripts?: boolean;
7
+ validValues?: boolean;
8
+ format?: boolean;
9
+ pattern?: boolean;
10
+ }): string;
@@ -1,5 +1,5 @@
1
- export default function cleanTimestamp(isoDateTimeString: any, { required, maxDaysInFuture, maxDaysInFPast, }?: {
2
- required?: boolean;
3
- maxDaysInFuture?: boolean;
4
- maxDaysInFPast?: boolean;
5
- }): string;
1
+ export default function cleanTimestamp(isoDateTimeString: any, { required, maxDaysInFuture, maxDaysInFPast, }?: {
2
+ required?: boolean;
3
+ maxDaysInFuture?: boolean;
4
+ maxDaysInFPast?: boolean;
5
+ }): string;
@@ -1,3 +1,3 @@
1
- export default function cleanUUID(uuid: any, { required, }?: {
2
- required?: boolean;
3
- }): string;
1
+ export default function cleanUUID(uuid: any, { required, }?: {
2
+ required?: boolean;
3
+ }): string;
@@ -1,6 +1,6 @@
1
- export default run;
2
- declare function run(filePath: any, { returnCode, jsMaps, cssMaps }?: {
3
- returnCode?: boolean;
4
- jsMaps?: {};
5
- cssMaps?: {};
6
- }): any[];
1
+ export default run;
2
+ declare function run(filePath: any, { returnCode, jsMaps, cssMaps }?: {
3
+ returnCode?: boolean;
4
+ jsMaps?: {};
5
+ cssMaps?: {};
6
+ }): any[];
@@ -1,8 +1,8 @@
1
- export default combineFiles;
2
- declare function combineFiles(dir: any, fileType: any, { minify, processContent, }?: {
3
- minify?: boolean;
4
- processContent?: ({ content, path }: {
5
- content: any;
6
- path: any;
7
- }) => any;
8
- }): string;
1
+ export default combineFiles;
2
+ declare function combineFiles(dir: any, fileType: any, { minify, processContent, }?: {
3
+ minify?: boolean;
4
+ processContent?: ({ content, path }: {
5
+ content: any;
6
+ path: any;
7
+ }) => any;
8
+ }): string;
@@ -1,8 +1,8 @@
1
- /**
2
- * Converts a given number of bytes into a more readable string format with appropriate units.
3
- *
4
- * @param {number} bytes - The number of bytes to convert.
5
- * @param {number} [precision=2] - The number of decimal places to include in the result.
6
- * @returns {string} The converted bytes in a string format with appropriate units.
7
- */
8
- export default function convertBytes(bytes: number, precision?: number): string;
1
+ /**
2
+ * Converts a given number of bytes into a more readable string format with appropriate units.
3
+ *
4
+ * @param {number} bytes - The number of bytes to convert.
5
+ * @param {number} [precision=2] - The number of decimal places to include in the result.
6
+ * @returns {string} The converted bytes in a string format with appropriate units.
7
+ */
8
+ export default function convertBytes(bytes: number, precision?: number): string;
@@ -1 +1 @@
1
- export default function decrypt(encryptedData: any, key?: any): any;
1
+ export default function decrypt(encryptedData: any, key?: any): any;
package/types/each.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- /**
2
- * Iterates over elements of an array or properties of an object, invoking a callback for each element/property.
3
- * The iteration stops if the callback returns `false`.
4
- *
5
- * @example each({ a: 1, b: 2 }, (value, key) => { console.log(value, key); });
6
- * @param {Object|Array} objectOrArray - The object or array to iterate over.
7
- * @param {Function} callback - The function to invoke per iteration. It is invoked with two arguments: (value, key/index).
8
- * @returns {void}
9
- */
10
- export default function each(objectOrArray: any | any[], callback: Function): void;
1
+ /**
2
+ * Iterates over elements of an array or properties of an object, invoking a callback for each element/property.
3
+ * The iteration stops if the callback returns `false`.
4
+ *
5
+ * @example each({ a: 1, b: 2 }, (value, key) => { console.log(value, key); });
6
+ * @param {Object|Array} objectOrArray - The object or array to iterate over.
7
+ * @param {Function} callback - The function to invoke per iteration. It is invoked with two arguments: (value, key/index).
8
+ * @returns {void}
9
+ */
10
+ export default function each(objectOrArray: any | any[], callback: Function): void;
@@ -1 +1 @@
1
- export default function eachAsync(objectOrArray: any, callback: any): Promise<void>;
1
+ export default function eachAsync(objectOrArray: any, callback: any): Promise<void>;
@@ -1,5 +1,5 @@
1
- export default function encrypt(plainText: any, key?: any): {
2
- iv: any;
3
- authTag: any;
4
- cipherText: any;
5
- };
1
+ export default function encrypt(plainText: any, key?: any): {
2
+ iv: any;
3
+ authTag: any;
4
+ cipherText: any;
5
+ };
@@ -1,6 +1,6 @@
1
- export default function getAllFiles(base: any, { dir, files, ignore, fileTypes }?: {
2
- dir?: string;
3
- files?: any[];
4
- ignore?: any[];
5
- fileTypes?: any[];
6
- }): any[];
1
+ export default function getAllFiles(base: any, { dir, files, ignore, fileTypes }?: {
2
+ dir?: string;
3
+ files?: any[];
4
+ ignore?: any[];
5
+ fileTypes?: any[];
6
+ }): any[];