@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.
- package/README.md +112 -86
- package/build/build.js +16 -11
- package/build/postBuild.js +8 -8
- package/eslint.config.js +90 -0
- package/index.js +108 -78
- package/package.json +26 -25
- package/schemas/schema1.js +5 -1
- package/schemas/schema2.js +5 -1
- package/schemas.js +3 -2
- package/src/build.js +88 -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 +56 -42
- 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/shouldIgnore.js +99 -0
- package/src/thingType.js +62 -24
- package/src/toPennies.js +23 -5
- package/src/utils/buildExportsTree.js +45 -17
- package/src/utils/buildFileDataList.js +37 -18
- package/src/utils/clean.js +205 -120
- package/src/utils/extractJSDocComment.js +14 -7
- package/src/utils/generateFile.js +54 -18
- package/src/utils/generateFlatExportLines.js +40 -17
- package/src/utils/generateImportStatements.js +20 -8
- package/src/utils/generateNamedExports.js +55 -10
- package/src/utils/generateNamespaceCode.js +56 -24
- package/src/utils/generateNamespaceExportLines.js +27 -7
- package/src/utils/writeHotWrapper.js +42 -0
- 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/ignore.test.js +55 -0
- package/tests/md5.test.js +7 -2
- package/tests/namedExports.test.js +13 -0
- package/tests/uuid.test.js +10 -4
- package/tests/validateSchema.test.js +21 -9
- package/tsconfig.json +20 -16
- package/types/build.d.ts +5 -1
- package/types/collectImports.d.ts +6 -0
- package/types/index.d.ts +108 -78
- package/types/shouldIgnore.d.ts +1 -0
- package/types/utils/buildFileDataList.d.ts +5 -1
- package/types/utils/generateFile.d.ts +8 -1
- package/types/utils/generateFlatExportLines.d.ts +7 -1
- package/types/utils/generateImportStatements.d.ts +5 -1
- package/types/utils/generateNamedExports.d.ts +7 -1
- package/types/utils/generateNamespaceCode.d.ts +7 -1
- package/types/utils/generateNamespaceExportLines.d.ts +6 -1
- package/types/utils/writeHotWrapper.d.ts +4 -0
- package/src/utils/shouldIgnore.js +0 -43
|
@@ -1,172 +1,243 @@
|
|
|
1
1
|
// example.test.js
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
expect, test
|
|
4
|
+
} from 'vitest';
|
|
3
5
|
import utils from '../../index.js';
|
|
4
6
|
|
|
5
7
|
const testObject = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
+
obj1: { ...testObject },
|
|
33
|
+
obj2: { ...testObject }
|
|
32
34
|
};
|
|
33
35
|
|
|
34
36
|
const invalidTestObject2 = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
obj1: { ...invalidTestObject },
|
|
38
|
+
obj2: { ...invalidTestObject }
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
const schema = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
113
|
+
[ 1, 2, 3 ],
|
|
114
|
+
[ 4, 5, 6 ],
|
|
115
|
+
[ 7, 8, 9 ]
|
|
78
116
|
];
|
|
79
117
|
|
|
80
118
|
const testStringArrayOfArrays = [
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
119
|
+
[ 'a', 'b', 'c' ],
|
|
120
|
+
[ 'd', 'e', 'f' ],
|
|
121
|
+
[ 'g', 'h', 'i' ],
|
|
84
122
|
];
|
|
85
123
|
|
|
86
124
|
const testArrayOfBooleans = [
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
125
|
+
[ true, false, true ],
|
|
126
|
+
[ false, true, false ],
|
|
127
|
+
[ true, true, false ]
|
|
90
128
|
];
|
|
91
129
|
|
|
92
130
|
const objectOfArrays = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
131
|
+
testArraysOfIntegers: [ ...testArraysOfIntegers ],
|
|
132
|
+
testStringArrayOfArrays: [ ...testStringArrayOfArrays ],
|
|
133
|
+
testArrayOfBooleans: [ ...testArrayOfBooleans ],
|
|
96
134
|
};
|
|
97
135
|
|
|
98
136
|
const objectOfArrays_schema = {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
220
|
+
|
|
221
|
+
expect(()=> utils.clean.object(testObject, schema2)).toThrow();
|
|
222
|
+
|
|
160
223
|
});
|
|
161
224
|
|
|
162
225
|
|
|
163
226
|
test('object of arrays test', () => {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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 {
|
|
2
|
+
import {
|
|
3
|
+
expect, test
|
|
4
|
+
} from 'vitest';
|
|
3
5
|
import utils from '../../index.js';
|
|
4
6
|
|
|
5
7
|
test('good string', () => {
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
expect(utils.clean.string('good string')).toBe('good string');
|
|
10
|
+
|
|
7
11
|
});
|
|
8
12
|
|
|
9
13
|
test('number', () => {
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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 {
|
|
2
|
+
import {
|
|
3
|
+
expect, test
|
|
4
|
+
} from 'vitest';
|
|
3
5
|
import utils from '../../index.js';
|
|
4
6
|
|
|
5
7
|
test('good timestamp', () => {
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
12
|
-
|
|
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
|
});
|
package/tests/clean/uuid.test.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
// example.test.js
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
expect, test
|
|
4
|
+
} from 'vitest';
|
|
3
5
|
import utils from '../../index.js';
|
|
4
6
|
|
|
5
7
|
test('good uuid', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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 {
|
|
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: ({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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 {
|
|
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
|
-
|
|
8
|
-
|
|
10
|
+
|
|
11
|
+
expect(convertBytesTest).toBeDefined();
|
|
12
|
+
expect(convertBytesTest).toEqual('1.00 KB');
|
|
13
|
+
|
|
9
14
|
});
|