@awesomeness-js/utils 1.0.24 → 1.1.2

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 (90) hide show
  1. package/README.md +112 -86
  2. package/build/build.js +16 -11
  3. package/build/postBuild.js +8 -8
  4. package/eslint.config.js +90 -0
  5. package/index.js +108 -78
  6. package/package.json +26 -25
  7. package/schemas/schema1.js +5 -1
  8. package/schemas/schema2.js +5 -1
  9. package/schemas.js +3 -2
  10. package/src/build.js +88 -8
  11. package/src/clean/boolean.js +27 -17
  12. package/src/clean/integer.js +85 -69
  13. package/src/clean/number.js +103 -86
  14. package/src/clean/string.js +91 -67
  15. package/src/clean/timestamp.js +61 -45
  16. package/src/clean/uuid.js +38 -25
  17. package/src/collectImports.js +195 -0
  18. package/src/combineFiles.js +45 -36
  19. package/src/convertBytes.js +12 -7
  20. package/src/decrypt.js +17 -9
  21. package/src/each.js +26 -4
  22. package/src/eachAsync.js +35 -19
  23. package/src/encrypt.js +22 -17
  24. package/src/getAllFiles.js +56 -42
  25. package/src/ignoreFolder/ignoreMe.js +6 -2
  26. package/src/ignoreMe.js +4 -2
  27. package/src/isUUID.js +4 -0
  28. package/src/md5.js +5 -1
  29. package/src/password/check.js +7 -3
  30. package/src/password/hash.js +12 -7
  31. package/src/setLocalEnvs.js +16 -3
  32. package/src/shouldIgnore.js +99 -0
  33. package/src/thingType.js +62 -24
  34. package/src/toPennies.js +23 -5
  35. package/src/utils/buildExportsTree.js +45 -17
  36. package/src/utils/buildFileDataList.js +37 -18
  37. package/src/utils/clean.js +205 -120
  38. package/src/utils/extractJSDocComment.js +14 -7
  39. package/src/utils/generateFile.js +54 -18
  40. package/src/utils/generateFlatExportLines.js +40 -17
  41. package/src/utils/generateImportStatements.js +20 -8
  42. package/src/utils/generateNamedExports.js +55 -10
  43. package/src/utils/generateNamespaceCode.js +56 -24
  44. package/src/utils/generateNamespaceExportLines.js +27 -7
  45. package/src/utils/writeHotWrapper.js +42 -0
  46. package/src/uuid.js +9 -7
  47. package/src/validateSchema.js +95 -77
  48. package/test/collectImports.js +8 -0
  49. package/test/css/some.css +3 -0
  50. package/test/css/some.js +5 -0
  51. package/test/ignoreFolder/ignoreMe.js +3 -1
  52. package/test/ignoreFolder/ignoreMe2.js +3 -1
  53. package/test/ignoreFolder2/ignoreMe.js +6 -2
  54. package/test/js/abc.test.js +7 -3
  55. package/test/js/some.js +5 -0
  56. package/test/secret.test.js +1 -1
  57. package/tests/clean/array.test.js +122 -74
  58. package/tests/clean/boolean.test.js +18 -6
  59. package/tests/clean/integer.test.js +25 -9
  60. package/tests/clean/number.test.js +49 -13
  61. package/tests/clean/object.test.js +190 -119
  62. package/tests/clean/string.test.js +48 -17
  63. package/tests/clean/timestamp.test.js +12 -5
  64. package/tests/clean/uuid.test.js +13 -6
  65. package/tests/collectImports.test.js +66 -0
  66. package/tests/combineFiles.test.js +28 -26
  67. package/tests/convertBytes.test.js +8 -3
  68. package/tests/env.test.js +9 -3
  69. package/tests/example.test.js +7 -3
  70. package/tests/fileList.test.js +16 -12
  71. package/tests/hash-and-encrypt.test.js +13 -4
  72. package/tests/ignore.test.js +55 -0
  73. package/tests/md5.test.js +7 -2
  74. package/tests/namedExports.test.js +13 -0
  75. package/tests/uuid.test.js +10 -4
  76. package/tests/validateSchema.test.js +21 -9
  77. package/tsconfig.json +20 -16
  78. package/types/build.d.ts +5 -1
  79. package/types/collectImports.d.ts +6 -0
  80. package/types/index.d.ts +108 -78
  81. package/types/shouldIgnore.d.ts +1 -0
  82. package/types/utils/buildFileDataList.d.ts +5 -1
  83. package/types/utils/generateFile.d.ts +8 -1
  84. package/types/utils/generateFlatExportLines.d.ts +7 -1
  85. package/types/utils/generateImportStatements.d.ts +5 -1
  86. package/types/utils/generateNamedExports.d.ts +7 -1
  87. package/types/utils/generateNamespaceCode.d.ts +7 -1
  88. package/types/utils/generateNamespaceExportLines.d.ts +6 -1
  89. package/types/utils/writeHotWrapper.d.ts +4 -0
  90. package/src/utils/shouldIgnore.js +0 -43
@@ -1,172 +1,243 @@
1
1
  // example.test.js
2
- import { expect, test } from 'vitest'
2
+ import {
3
+ expect, test
4
+ } from 'vitest';
3
5
  import utils from '../../index.js';
4
6
 
5
7
  const testObject = {
6
- stringProp: 'a string',
7
- integerProp: 42,
8
- numberProp: 3.14,
9
- booleanProp: true,
10
- timestampProp: new Date().toISOString(),
11
- uuidProp: utils.uuid(), // generate a valid UUID
8
+ stringProp: 'a string',
9
+ integerProp: 42,
10
+ numberProp: 3.14,
11
+ booleanProp: true,
12
+ timestampProp: new Date().toISOString(),
13
+ uuidProp: utils.uuid(), // generate a valid UUID
12
14
  };
13
15
 
14
16
  const invalidTestObject = {
15
- stringProp: 123, // should be a string
16
- integerProp: 'not an integer', // should be an integer
17
- numberProp: 'not a number', // should be a number
18
- booleanProp: 'not a boolean', // should be a boolean
19
- timestampProp: 'not a timestamp', // should be a timestamp
20
- uuidProp: 'not a uuid', // should be a uuid
21
- optionalStringProp: 456, // should be a string
22
- optionalIntegerProp: 'not an integer', // should be an integer
23
- optionalNumberProp: 'not a number', // should be a number
24
- optionalBooleanProp: 'not a boolean', // should be a boolean
25
- optionalTimestampProp: 'not a timestamp', // should be a timestamp
26
- optionalUuidProp: 'not a uuid' // should be a uuid
17
+ stringProp: 123, // should be a string
18
+ integerProp: 'not an integer', // should be an integer
19
+ numberProp: 'not a number', // should be a number
20
+ booleanProp: 'not a boolean', // should be a boolean
21
+ timestampProp: 'not a timestamp', // should be a timestamp
22
+ uuidProp: 'not a uuid', // should be a uuid
23
+ optionalStringProp: 456, // should be a string
24
+ optionalIntegerProp: 'not an integer', // should be an integer
25
+ optionalNumberProp: 'not a number', // should be a number
26
+ optionalBooleanProp: 'not a boolean', // should be a boolean
27
+ optionalTimestampProp: 'not a timestamp', // should be a timestamp
28
+ optionalUuidProp: 'not a uuid' // should be a uuid
27
29
  };
28
30
 
29
31
  const testObject2 = {
30
- obj1: { ...testObject },
31
- obj2: { ...testObject }
32
+ obj1: { ...testObject },
33
+ obj2: { ...testObject }
32
34
  };
33
35
 
34
36
  const invalidTestObject2 = {
35
- obj1: { ...invalidTestObject },
36
- obj2: { ...invalidTestObject }
37
+ obj1: { ...invalidTestObject },
38
+ obj2: { ...invalidTestObject }
37
39
  };
38
40
 
39
41
  const schema = {
40
- type: 'object',
41
- properties: {
42
- stringProp: { type: 'string', required: true },
43
- integerProp: { type: 'integer', required: true },
44
- numberProp: { type: 'number', required: true },
45
- booleanProp: { type: 'boolean', required: true },
46
- timestampProp: { type: 'timestamp', required: true },
47
- uuidProp: { type: 'uuid', required: true },
48
- optionalStringProp: { type: 'string', required: false },
49
- optionalIntegerProp: { type: 'integer', required: false },
50
- optionalNumberProp: { type: 'number', required: false },
51
- optionalBooleanProp: { type: 'boolean', required: false },
52
- optionalTimestampProp: { type: 'timestamp', required: false },
53
- optionalUuidProp: { type: 'uuid', required: false }
54
- },
42
+ type: 'object',
43
+ properties: {
44
+ stringProp: {
45
+ type: 'string',
46
+ required: true
47
+ },
48
+ integerProp: {
49
+ type: 'integer',
50
+ required: true
51
+ },
52
+ numberProp: {
53
+ type: 'number',
54
+ required: true
55
+ },
56
+ booleanProp: {
57
+ type: 'boolean',
58
+ required: true
59
+ },
60
+ timestampProp: {
61
+ type: 'timestamp',
62
+ required: true
63
+ },
64
+ uuidProp: {
65
+ type: 'uuid',
66
+ required: true
67
+ },
68
+ optionalStringProp: {
69
+ type: 'string',
70
+ required: false
71
+ },
72
+ optionalIntegerProp: {
73
+ type: 'integer',
74
+ required: false
75
+ },
76
+ optionalNumberProp: {
77
+ type: 'number',
78
+ required: false
79
+ },
80
+ optionalBooleanProp: {
81
+ type: 'boolean',
82
+ required: false
83
+ },
84
+ optionalTimestampProp: {
85
+ type: 'timestamp',
86
+ required: false
87
+ },
88
+ optionalUuidProp: {
89
+ type: 'uuid',
90
+ required: false
91
+ }
92
+ },
55
93
  };
56
94
 
57
95
  const schema2 = {
58
- type: 'object',
59
- properties: {
60
- obj1: {
61
- type: 'object',
62
- required: true,
63
- properties: { ... schema.properties }
64
- },
65
- obj2: {
66
- type: 'object',
67
- required: true,
68
- properties: { ... schema.properties }
69
- }
70
- },
96
+ type: 'object',
97
+ properties: {
98
+ obj1: {
99
+ type: 'object',
100
+ required: true,
101
+ properties: { ... schema.properties }
102
+ },
103
+ obj2: {
104
+ type: 'object',
105
+ required: true,
106
+ properties: { ... schema.properties }
107
+ }
108
+ },
71
109
  };
72
110
 
73
111
 
74
112
  const testArraysOfIntegers = [
75
- [1, 2, 3],
76
- [4, 5, 6],
77
- [7, 8, 9]
113
+ [ 1, 2, 3 ],
114
+ [ 4, 5, 6 ],
115
+ [ 7, 8, 9 ]
78
116
  ];
79
117
 
80
118
  const testStringArrayOfArrays = [
81
- ['a', 'b', 'c'],
82
- ['d', 'e', 'f'],
83
- ['g', 'h', 'i'],
119
+ [ 'a', 'b', 'c' ],
120
+ [ 'd', 'e', 'f' ],
121
+ [ 'g', 'h', 'i' ],
84
122
  ];
85
123
 
86
124
  const testArrayOfBooleans = [
87
- [true, false, true],
88
- [false, true, false],
89
- [true, true, false]
125
+ [ true, false, true ],
126
+ [ false, true, false ],
127
+ [ true, true, false ]
90
128
  ];
91
129
 
92
130
  const objectOfArrays = {
93
- testArraysOfIntegers: [...testArraysOfIntegers],
94
- testStringArrayOfArrays: [...testStringArrayOfArrays],
95
- testArrayOfBooleans: [...testArrayOfBooleans],
131
+ testArraysOfIntegers: [ ...testArraysOfIntegers ],
132
+ testStringArrayOfArrays: [ ...testStringArrayOfArrays ],
133
+ testArrayOfBooleans: [ ...testArrayOfBooleans ],
96
134
  };
97
135
 
98
136
  const objectOfArrays_schema = {
99
- type: 'object',
100
- properties: {
101
- testArraysOfIntegers: {
102
- type: 'array',
103
- items: {
104
- type: 'array',
105
- items: { type: 'integer' }
106
- }
107
- },
108
- testStringArrayOfArrays: {
109
- type: 'array',
110
- items: {
111
- type: 'array',
112
- items: { type: 'string' }
113
- }
114
- },
115
- testArrayOfBooleans: {
116
- type: 'array',
117
- items: {
118
- type: 'array',
119
- items: { type: 'boolean' }
120
- }
121
- }
122
- }
137
+ type: 'object',
138
+ properties: {
139
+ testArraysOfIntegers: {
140
+ type: 'array',
141
+ items: {
142
+ type: 'array',
143
+ items: { type: 'integer' }
144
+ }
145
+ },
146
+ testStringArrayOfArrays: {
147
+ type: 'array',
148
+ items: {
149
+ type: 'array',
150
+ items: { type: 'string' }
151
+ }
152
+ },
153
+ testArrayOfBooleans: {
154
+ type: 'array',
155
+ items: {
156
+ type: 'array',
157
+ items: { type: 'boolean' }
158
+ }
159
+ }
160
+ }
123
161
  };
124
162
 
125
163
  test('testObject', () => {
126
- try {
127
- const cleanedObject = utils.clean.object(testObject, schema);
128
- expect(cleanedObject).toStrictEqual(testObject);
129
- } catch (error) {
130
- console.error('Error cleaning object:', error);
131
- throw error; // rethrow to fail the test
132
- }
164
+
165
+ try {
166
+
167
+ const cleanedObject = utils.clean.object(testObject, schema);
168
+
169
+ expect(cleanedObject).toStrictEqual(testObject);
170
+
171
+ } catch (error) {
172
+
173
+ console.error('Error cleaning object:', error);
174
+
175
+ throw error; // rethrow to fail the test
176
+
177
+ }
178
+
133
179
  });
134
180
 
135
181
  test('invalidTestObject', () => {
136
- try {
137
- const cleanedObject = utils.clean.object(invalidTestObject, schema);
138
- //console.log({ cleanedObject })
139
- expect(cleanedObject).toStrictEqual(invalidTestObject);
140
- } catch (error) {
141
- //console.error('Error cleaning object:', error);
142
- expect(error.message).toBe('type invalid');
143
- }
182
+
183
+ try {
184
+
185
+ const cleanedObject = utils.clean.object(invalidTestObject, schema);
186
+ //console.log({ cleanedObject })
187
+
188
+ expect(cleanedObject).toStrictEqual(invalidTestObject);
189
+
190
+ } catch (error) {
191
+
192
+ //console.error('Error cleaning object:', error);
193
+ expect(error.message).toBe('type invalid');
194
+
195
+ }
196
+
144
197
  });
145
198
 
146
199
  test('testObject2', () => {
147
- try {
148
- const cleanedObject = utils.clean.object(testObject2, schema2);
149
- //console.log('cleanedObject', cleanedObject);
150
- expect(cleanedObject).toStrictEqual(testObject2);
151
- } catch (error) {
152
- console.error('Error cleaning object:', error);
153
- throw error; // rethrow to fail the test
154
- }
200
+
201
+ try {
202
+
203
+ const cleanedObject = utils.clean.object(testObject2, schema2);
204
+ //console.log('cleanedObject', cleanedObject);
205
+
206
+ expect(cleanedObject).toStrictEqual(testObject2);
207
+
208
+ } catch (error) {
209
+
210
+ console.error('Error cleaning object:', error);
211
+
212
+ throw error; // rethrow to fail the test
213
+
214
+ }
215
+
155
216
  });
156
217
 
157
218
 
158
219
  test('incorrect should throw', () => {
159
- expect(()=> utils.clean.object(testObject, schema2)).toThrow();
220
+
221
+ expect(()=> utils.clean.object(testObject, schema2)).toThrow();
222
+
160
223
  });
161
224
 
162
225
 
163
226
  test('object of arrays test', () => {
164
- try {
165
- const cleanedObject = utils.clean.object(objectOfArrays, objectOfArrays_schema);
166
- //console.log('cleanedObject', cleanedObject);
167
- expect(cleanedObject).toStrictEqual(objectOfArrays);
168
- } catch (error) {
169
- console.error('Error cleaning object:', error);
170
- throw error; // rethrow to fail the test
171
- }
227
+
228
+ try {
229
+
230
+ const cleanedObject = utils.clean.object(objectOfArrays, objectOfArrays_schema);
231
+ //console.log('cleanedObject', cleanedObject);
232
+
233
+ expect(cleanedObject).toStrictEqual(objectOfArrays);
234
+
235
+ } catch (error) {
236
+
237
+ console.error('Error cleaning object:', error);
238
+
239
+ throw error; // rethrow to fail the test
240
+
241
+ }
242
+
172
243
  });
@@ -1,44 +1,75 @@
1
1
  // example.test.js
2
- import { expect, test } from 'vitest'
2
+ import {
3
+ expect, test
4
+ } from 'vitest';
3
5
  import utils from '../../index.js';
4
6
 
5
7
  test('good string', () => {
6
- expect(utils.clean.string('good string')).toBe('good string');
8
+
9
+ expect(utils.clean.string('good string')).toBe('good string');
10
+
7
11
  });
8
12
 
9
13
  test('number', () => {
10
- expect(utils.clean.string(123)).toBe(null);
11
- expect(()=> utils.clean.string(123, { required: true })).toThrow();
14
+
15
+ expect(utils.clean.string(123)).toBe(null);
16
+ expect(()=> utils.clean.string(123, { required: true })).toThrow();
17
+
12
18
  });
13
19
 
14
20
  test('string too short', () => {
15
- expect(utils.clean.string('123456789', { minLength: 10 })).toBe(null);
16
- expect(()=> utils.clean.string('123456789', { minLength: 10, required: true })).toThrow();
21
+
22
+ expect(utils.clean.string('123456789', { minLength: 10 })).toBe(null);
23
+ expect(()=> utils.clean.string('123456789', {
24
+ minLength: 10,
25
+ required: true
26
+ })).toThrow();
27
+
17
28
  });
18
29
 
19
30
  test('string too long', () => {
20
- expect(utils.clean.string('123456789', { maxLength: 5 })).toBe(null);
21
- expect(()=> utils.clean.string('123456789', { maxLength: 5, required: true })).toThrow();
31
+
32
+ expect(utils.clean.string('123456789', { maxLength: 5 })).toBe(null);
33
+ expect(()=> utils.clean.string('123456789', {
34
+ maxLength: 5,
35
+ required: true
36
+ })).toThrow();
37
+
22
38
  });
23
39
 
24
40
  test('no html', () => {
25
- expect(utils.clean.string('<div>no go</div>')).toBe(null);
26
- expect(()=> utils.clean.string('<div>no go</div>', { required: true })).toThrow();
41
+
42
+ expect(utils.clean.string('<div>no go</div>')).toBe(null);
43
+ expect(()=> utils.clean.string('<div>no go</div>', { required: true })).toThrow();
44
+
27
45
  });
28
46
 
29
47
  test('no script', () => {
30
- expect(utils.clean.string('<script>no go</script>')).toBe(null);
31
- expect(()=> utils.clean.string('<script>no go</script>', { required: true })).toThrow();
48
+
49
+ expect(utils.clean.string('<script>no go</script>')).toBe(null);
50
+ expect(()=> utils.clean.string('<script>no go</script>', { required: true })).toThrow();
51
+
32
52
  });
33
53
 
34
54
  test('allow html', () => {
35
- let x = utils.clean.string('<div>all good/div>', { allowHtml: true });
36
- expect(utils.clean.string('<div>all good</div>', { allowHtml: true })).toBe('<div>all good</div>');
37
- expect(utils.clean.string('<div>all good</div>', { allowHtml: true, required: true })).toBe('<div>all good</div>');
55
+
56
+ let x = utils.clean.string('<div>all good/div>', { allowHtml: true });
57
+
58
+ expect(utils.clean.string('<div>all good</div>', { allowHtml: true })).toBe('<div>all good</div>');
59
+ expect(utils.clean.string('<div>all good</div>', {
60
+ allowHtml: true,
61
+ required: true
62
+ })).toBe('<div>all good</div>');
63
+
38
64
  });
39
65
 
40
66
  test('allow script', () => {
41
- expect(utils.clean.string('<script>all good</script>', { allowScripts: true })).toBe('<script>all good</script>');
42
- expect(utils.clean.string('<script>all good</script>', { allowScripts: true, required: true })).toBe('<script>all good</script>');
67
+
68
+ expect(utils.clean.string('<script>all good</script>', { allowScripts: true })).toBe('<script>all good</script>');
69
+ expect(utils.clean.string('<script>all good</script>', {
70
+ allowScripts: true,
71
+ required: true
72
+ })).toBe('<script>all good</script>');
73
+
43
74
  });
44
75
 
@@ -1,13 +1,20 @@
1
1
  // example.test.js
2
- import { expect, test } from 'vitest'
2
+ import {
3
+ expect, test
4
+ } from 'vitest';
3
5
  import utils from '../../index.js';
4
6
 
5
7
  test('good timestamp', () => {
6
- const x = utils.clean.timestamp('2024-12-30');
7
- expect(x).toBe('2024-12-30T00:00:00.000Z');
8
+
9
+ const x = utils.clean.timestamp('2024-12-30');
10
+
11
+ expect(x).toBe('2024-12-30T00:00:00.000Z');
12
+
8
13
  });
9
14
 
10
15
  test('bad timestamp', () => {
11
- expect(utils.clean.timestamp('2024-12-32')).toBe(null);
12
- expect(()=>utils.clean.timestamp('2024-12-32', { required: true })).toThrow();
16
+
17
+ expect(utils.clean.timestamp('2024-12-32')).toBe(null);
18
+ expect(()=>utils.clean.timestamp('2024-12-32', { required: true })).toThrow();
19
+
13
20
  });
@@ -1,14 +1,21 @@
1
1
  // example.test.js
2
- import { expect, test } from 'vitest'
2
+ import {
3
+ expect, test
4
+ } from 'vitest';
3
5
  import utils from '../../index.js';
4
6
 
5
7
  test('good uuid', () => {
6
- const id = utils.uuid();
7
- const x = utils.clean.uuid(id);
8
- expect(x).toBe(id);
8
+
9
+ const id = utils.uuid();
10
+ const x = utils.clean.uuid(id);
11
+
12
+ expect(x).toBe(id);
13
+
9
14
  });
10
15
 
11
16
  test('bad uuid', () => {
12
- expect(utils.clean.uuid('2024-12-32')).toBe(null);
13
- expect(()=>utils.clean.uuid('2024-12-32', { required: true })).toThrow();
17
+
18
+ expect(utils.clean.uuid('2024-12-32')).toBe(null);
19
+ expect(()=>utils.clean.uuid('2024-12-32', { required: true })).toThrow();
20
+
14
21
  });
@@ -0,0 +1,66 @@
1
+ import utils from '../index.js';
2
+ import {
3
+ expect, test
4
+ } from 'vitest';
5
+
6
+ test('collectImports', () => {
7
+
8
+ const imports = utils.collectImports('./test/collectImports.js');
9
+
10
+ const names = imports.map((i) => i.name).sort();
11
+
12
+ expect(names).toStrictEqual([
13
+ 'test.collectImports',
14
+ 'test.js.some',
15
+ 'test_css_some',
16
+ ]);
17
+
18
+ expect(imports.length).toBe(3);
19
+
20
+ expect(Object.keys(imports[0]).sort()).toStrictEqual([
21
+ 'code',
22
+ 'fullPath',
23
+ 'hash',
24
+ 'name',
25
+ 'rootPath',
26
+ 'type',
27
+ ]);
28
+
29
+ });
30
+
31
+
32
+ test('collectImports - collect all imports in collectImports.js', () => {
33
+
34
+ const imports = utils.collectImports('./test/collectImports.js',{
35
+ returnCode: false,
36
+ jsMaps: {
37
+ 'test.js': 'app.print',
38
+ 'test': 'app.fn',
39
+ },
40
+ cssMaps: {
41
+ 'test': 'awesomeness',
42
+ },
43
+ });
44
+
45
+ const names = imports.map((i) => i.name).sort();
46
+
47
+
48
+ expect(names).toStrictEqual([
49
+ 'app.fn.collectImports', // test.collectImports
50
+ 'app.print.some', // test.js.some
51
+ 'awesomeness_css_some', // test_css_some
52
+ ]);
53
+
54
+ expect(imports.length).toBe(3);
55
+
56
+ expect(Object.keys(imports[0]).sort()).toStrictEqual([
57
+ //'code',
58
+ 'fullPath',
59
+ 'hash',
60
+ 'name',
61
+ 'rootPath',
62
+ 'type',
63
+ ]);
64
+
65
+ });
66
+
@@ -1,35 +1,37 @@
1
1
  // example.test.js
2
- import { expect, test } from 'vitest'
2
+ import {
3
+ expect, test
4
+ } from 'vitest';
3
5
  import utils from '../index.js';
4
6
 
5
7
  let combineTest = utils.combineFiles('./test', 'js');
6
8
 
7
9
  let combineTest2 = utils.combineFiles('./test', 'js', {
8
- processContent: ({ content, path }) => {
9
-
10
- const fnName = path.split('/')
11
- .filter(x => x !== '') // remove empty strings
12
- .join('.') // join with dots
13
- .replaceAll('..', '.') // remove double dots
14
- .replaceAll('.js', '') // remove .js
15
- .replace(/^\./, '');
16
-
17
- console.log({content, path});
18
- content = content.replaceAll('export default function', `${fnName} = function`);
19
- content = content.replaceAll('export default async function', `${fnName} = async function`);
20
- content = content.replaceAll('export default async', `${fnName} = async`);
21
- content = content.replaceAll('export default', `${fnName} =`);
22
- console.log(content);
23
- console.log('');
24
- console.log('');
25
- console.log('');
26
- return content;
27
- },
10
+ processContent: ({
11
+ content, path
12
+ }) => {
13
+
14
+ const fnName = path.split('/')
15
+ .filter((x) => x !== '') // remove empty strings
16
+ .join('.') // join with dots
17
+ .replaceAll('..', '.') // remove double dots
18
+ .replaceAll('.js', '') // remove .js
19
+ .replace(/^\./, '');
20
+
21
+ content = content.replaceAll('export default function', `${fnName} = function`);
22
+ content = content.replaceAll('export default async function', `${fnName} = async function`);
23
+ content = content.replaceAll('export default async', `${fnName} = async`);
24
+ content = content.replaceAll('export default', `${fnName} =`);
25
+
26
+ return content;
27
+
28
+ },
28
29
  });
29
30
 
30
31
  test('combineFiles - combine all files in src/js', () => {
31
- expect(combineTest).toBeDefined();
32
- expect(combineTest2).toBeDefined();
33
- expect(combineTest).not.toEqual(combineTest2);
34
- console.log({combineTest2});
35
- })
32
+
33
+ expect(combineTest).toBeDefined();
34
+ expect(combineTest2).toBeDefined();
35
+ expect(combineTest).not.toEqual(combineTest2);
36
+
37
+ });
@@ -1,9 +1,14 @@
1
1
  // example.test.js
2
- import { expect, test } from 'vitest'
2
+ import {
3
+ expect, test
4
+ } from 'vitest';
3
5
  import utils from '../index.js';
4
6
 
5
7
  let convertBytesTest = utils.convertBytes(1024);
8
+
6
9
  test('convertBytes 1024 => 1.00 KB', () => {
7
- expect(convertBytesTest).toBeDefined();
8
- expect(convertBytesTest).toEqual('1.00 KB');
10
+
11
+ expect(convertBytesTest).toBeDefined();
12
+ expect(convertBytesTest).toEqual('1.00 KB');
13
+
9
14
  });