@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.
- package/build/build.js +11 -11
- package/build/postBuild.js +8 -8
- package/eslint.config.js +90 -0
- package/index.js +77 -74
- package/package.json +25 -25
- package/schemas/schema1.js +5 -1
- package/schemas/schema2.js +5 -1
- package/schemas.js +2 -2
- package/src/build.js +12 -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 +55 -41
- 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/thingType.js +62 -24
- package/src/toPennies.js +23 -5
- package/src/utils/buildExportsTree.js +45 -17
- package/src/utils/buildFileDataList.js +32 -17
- package/src/utils/clean.js +205 -120
- package/src/utils/extractJSDocComment.js +14 -7
- package/src/utils/generateFile.js +20 -18
- package/src/utils/generateFlatExportLines.js +34 -17
- package/src/utils/generateImportStatements.js +15 -7
- package/src/utils/generateNamedExports.js +20 -9
- package/src/utils/generateNamespaceCode.js +45 -24
- package/src/utils/generateNamespaceExportLines.js +16 -7
- package/src/utils/shouldIgnore.js +57 -37
- 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/md5.test.js +7 -2
- package/tests/uuid.test.js +10 -4
- package/tests/validateSchema.test.js +21 -9
- package/tsconfig.json +20 -16
- package/types/collectImports.d.ts +6 -0
- package/types/index.d.ts +3 -0
package/src/utils/clean.js
CHANGED
|
@@ -11,88 +11,135 @@ import cleanUUID from '../clean/uuid.js';
|
|
|
11
11
|
|
|
12
12
|
function cleanArray(arr, schema = {}){
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
try {
|
|
15
|
+
|
|
16
|
+
if(!Array.isArray(arr)) {
|
|
17
|
+
|
|
18
|
+
throw {
|
|
19
|
+
message: 'Input must be an array',
|
|
20
|
+
arr
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
}
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
validateSchema(schema);
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
const cleanArrayItems = [];
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
const supposedToBeType = schema.items.type;
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
arr.forEach( (item, key) => {
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
const itemType = thingType(item);
|
|
32
34
|
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
if(itemType !== supposedToBeType){
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
throw {
|
|
39
|
+
message: 'type invalid',
|
|
40
|
+
itemType,
|
|
41
|
+
supposedToBeType
|
|
42
|
+
};
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
}
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
let cleanedItem = item;
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
if(supposedToBeType === 'boolean'){
|
|
49
|
+
|
|
50
|
+
cleanedItem = cleanBoolean(item);
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if(supposedToBeType === 'integer'){
|
|
55
|
+
|
|
56
|
+
cleanedItem = cleanInteger(item);
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if(supposedToBeType === 'number'){
|
|
61
|
+
|
|
62
|
+
cleanedItem = cleanNumber(item);
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if(supposedToBeType === 'string'){
|
|
67
|
+
|
|
68
|
+
cleanedItem = cleanString(item);
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if(supposedToBeType === 'timestamp'){
|
|
73
|
+
|
|
74
|
+
cleanedItem = cleanTimestamp(item);
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if(supposedToBeType === 'uuid'){
|
|
79
|
+
|
|
80
|
+
cleanedItem = cleanUUID(item);
|
|
81
|
+
|
|
82
|
+
}
|
|
52
83
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
if(supposedToBeType === 'array'){
|
|
85
|
+
|
|
86
|
+
cleanedItem = cleanArray(item, schema.items);
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if(supposedToBeType === 'object'){
|
|
91
|
+
|
|
92
|
+
cleanedItem = cleanObject(item, schema.items);
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if(cleanedItem === null){
|
|
97
|
+
|
|
98
|
+
if(schema.required === true){
|
|
99
|
+
|
|
100
|
+
throw {
|
|
101
|
+
message: 'required item is null',
|
|
102
|
+
item,
|
|
103
|
+
key
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
} else {
|
|
107
|
+
|
|
108
|
+
return; // skip this item if it's not required and is null
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
}
|
|
72
113
|
|
|
73
114
|
|
|
74
|
-
|
|
115
|
+
cleanArrayItems.push(cleanedItem);
|
|
75
116
|
|
|
76
|
-
|
|
117
|
+
});
|
|
77
118
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
119
|
+
if(cleanArrayItems.length === 0){
|
|
120
|
+
|
|
121
|
+
throw {
|
|
122
|
+
message: 'array is empty',
|
|
123
|
+
arr
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return cleanArrayItems;
|
|
84
129
|
|
|
85
|
-
|
|
130
|
+
} catch (e) {
|
|
86
131
|
|
|
87
|
-
|
|
132
|
+
if(schema.required === true){
|
|
88
133
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
134
|
+
throw e;
|
|
135
|
+
|
|
136
|
+
} else {
|
|
94
137
|
|
|
95
|
-
|
|
138
|
+
return null;
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
}
|
|
96
143
|
|
|
97
144
|
|
|
98
145
|
|
|
@@ -101,83 +148,121 @@ function cleanArray(arr, schema = {}){
|
|
|
101
148
|
|
|
102
149
|
function cleanObject(obj, schema){
|
|
103
150
|
|
|
104
|
-
|
|
151
|
+
validateSchema(schema);
|
|
152
|
+
|
|
153
|
+
if(typeof obj !== 'object' || obj === null){
|
|
154
|
+
|
|
155
|
+
throw {
|
|
156
|
+
message: 'Clean Object - Input must be an object',
|
|
157
|
+
obj,
|
|
158
|
+
schema
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let keysPassed = Object.keys(obj);
|
|
164
|
+
let keysSchema = Object.keys(schema.properties);
|
|
165
|
+
|
|
166
|
+
const origLength = keysPassed.length;
|
|
167
|
+
|
|
168
|
+
keysPassed = keysPassed.filter((key) => keysSchema.includes(key));
|
|
169
|
+
|
|
170
|
+
if(origLength !== keysPassed.length){
|
|
171
|
+
|
|
172
|
+
throw {
|
|
173
|
+
name: 'KeyError',
|
|
174
|
+
message: 'Object contains keys not in schema',
|
|
175
|
+
keysPassed,
|
|
176
|
+
keysSchema,
|
|
177
|
+
obj
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const cleanObj = {};
|
|
183
|
+
|
|
184
|
+
// Iterate over the schema keys
|
|
185
|
+
each(obj, (value, key) => {
|
|
186
|
+
|
|
187
|
+
const valType = thingType(value);
|
|
188
|
+
const supposedToBeType = schema.properties[key].type;
|
|
189
|
+
|
|
190
|
+
if(valType !== supposedToBeType){
|
|
191
|
+
|
|
192
|
+
throw {
|
|
193
|
+
message: 'type invalid',
|
|
194
|
+
valType,
|
|
195
|
+
supposedToBeType,
|
|
196
|
+
key
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let cleanedValue;
|
|
202
|
+
|
|
203
|
+
if(supposedToBeType === 'boolean'){
|
|
204
|
+
|
|
205
|
+
cleanedValue = cleanBoolean(value);
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if(supposedToBeType === 'integer'){
|
|
210
|
+
|
|
211
|
+
cleanedValue = cleanInteger(value);
|
|
212
|
+
|
|
213
|
+
}
|
|
105
214
|
|
|
106
|
-
|
|
107
|
-
throw {
|
|
108
|
-
message: 'Clean Object - Input must be an object',
|
|
109
|
-
obj,
|
|
110
|
-
schema
|
|
111
|
-
};
|
|
112
|
-
}
|
|
215
|
+
if(supposedToBeType === 'number'){
|
|
113
216
|
|
|
114
|
-
|
|
115
|
-
let keysSchema = Object.keys(schema.properties);
|
|
217
|
+
cleanedValue = cleanNumber(value);
|
|
116
218
|
|
|
117
|
-
|
|
118
|
-
keysPassed = keysPassed.filter(key => keysSchema.includes(key));
|
|
219
|
+
}
|
|
119
220
|
|
|
120
|
-
|
|
121
|
-
throw {
|
|
122
|
-
name: 'KeyError',
|
|
123
|
-
message: 'Object contains keys not in schema',
|
|
124
|
-
keysPassed,
|
|
125
|
-
keysSchema,
|
|
126
|
-
obj
|
|
127
|
-
};
|
|
128
|
-
}
|
|
221
|
+
if(supposedToBeType === 'string'){
|
|
129
222
|
|
|
130
|
-
|
|
223
|
+
cleanedValue = cleanString(value);
|
|
131
224
|
|
|
132
|
-
|
|
133
|
-
each(obj, (value, key) => {
|
|
225
|
+
}
|
|
134
226
|
|
|
135
|
-
|
|
136
|
-
const supposedToBeType = schema.properties[key].type;
|
|
227
|
+
if(supposedToBeType === 'timestamp'){
|
|
137
228
|
|
|
138
|
-
|
|
229
|
+
cleanedValue = cleanTimestamp(value);
|
|
139
230
|
|
|
140
|
-
|
|
141
|
-
message: 'type invalid',
|
|
142
|
-
valType,
|
|
143
|
-
supposedToBeType,
|
|
144
|
-
key
|
|
145
|
-
};
|
|
231
|
+
}
|
|
146
232
|
|
|
147
|
-
|
|
233
|
+
if(supposedToBeType === 'uuid'){
|
|
148
234
|
|
|
149
|
-
|
|
235
|
+
cleanedValue = cleanUUID(value);
|
|
150
236
|
|
|
151
|
-
|
|
152
|
-
if(supposedToBeType === 'integer'){ cleanedValue = cleanInteger(value); }
|
|
153
|
-
if(supposedToBeType === 'number'){ cleanedValue = cleanNumber(value); }
|
|
154
|
-
if(supposedToBeType === 'string'){ cleanedValue = cleanString(value); }
|
|
155
|
-
if(supposedToBeType === 'timestamp'){ cleanedValue = cleanTimestamp(value); }
|
|
156
|
-
if(supposedToBeType === 'uuid'){ cleanedValue = cleanUUID(value); }
|
|
237
|
+
}
|
|
157
238
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
239
|
+
if(supposedToBeType === 'object'){
|
|
240
|
+
|
|
241
|
+
cleanedValue = cleanObject(value, schema.properties[key]);
|
|
242
|
+
|
|
243
|
+
}
|
|
161
244
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
245
|
+
if(supposedToBeType === 'array'){
|
|
246
|
+
|
|
247
|
+
cleanedValue = cleanArray(value, schema.properties[key]);
|
|
248
|
+
|
|
249
|
+
}
|
|
165
250
|
|
|
166
|
-
|
|
251
|
+
cleanObj[key] = cleanedValue;
|
|
167
252
|
|
|
168
|
-
|
|
253
|
+
});
|
|
169
254
|
|
|
170
|
-
|
|
255
|
+
return cleanObj;
|
|
171
256
|
|
|
172
257
|
}
|
|
173
258
|
|
|
174
259
|
export default {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
260
|
+
array: cleanArray,
|
|
261
|
+
object: cleanObject,
|
|
262
|
+
boolean: cleanBoolean,
|
|
263
|
+
integer: cleanInteger,
|
|
264
|
+
number: cleanNumber,
|
|
265
|
+
string: cleanString,
|
|
266
|
+
timestamp: cleanTimestamp,
|
|
267
|
+
uuid: cleanUUID
|
|
183
268
|
};
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
|
|
3
3
|
export default function extractJSDocComment(filePath) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
|
|
5
|
+
const fileContent = readFileSync(filePath, 'utf8');
|
|
6
|
+
const match = fileContent.match(/\/\*\*([\s\S]*?)\*\//);
|
|
7
|
+
|
|
8
|
+
// If the match exists and doesn't contain an unresolved template placeholder, return it.
|
|
9
|
+
|
|
10
|
+
if (match && match[1] && !match[1].includes('${')) {
|
|
11
|
+
|
|
12
|
+
return `/**${match[1]}*/`;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return '';
|
|
17
|
+
|
|
11
18
|
}
|
|
@@ -5,30 +5,32 @@ import generateFlatExportLines from './generateFlatExportLines.js';
|
|
|
5
5
|
import generateNamespaceExportLines from './generateNamespaceExportLines.js';
|
|
6
6
|
import generateNamedExports from './generateNamedExports.js';
|
|
7
7
|
|
|
8
|
-
export default function generateFile(src, exportRoots, ignore, includeComments, dts) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export default function generateFile(src, exportRoots, ignore, includeComments, dts, useTabs = true) {
|
|
9
|
+
|
|
10
|
+
const fileDataList = buildFileDataList(src, ignore, includeComments);
|
|
11
|
+
const {
|
|
12
|
+
flatExports, nestedExports
|
|
13
|
+
} = buildExportsTree(fileDataList);
|
|
14
|
+
const headerComment = `/**
|
|
12
15
|
* This file is auto-generated by the build script.
|
|
13
16
|
* It consolidates API ${dts ? 'type declarations' : 'functions'} for use in the application.
|
|
14
17
|
* Do not edit manually.
|
|
15
18
|
*/
|
|
16
19
|
`;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const namedExports = generateNamedExports(flatExports, exportRoots, dts);
|
|
30
|
-
return headerComment +
|
|
20
|
+
const importStatements = generateImportStatements(fileDataList, dts, src);
|
|
21
|
+
const flatExportLines = generateFlatExportLines(flatExports, exportRoots, includeComments, dts, useTabs);
|
|
22
|
+
const namespaceExportLines = generateNamespaceExportLines(nestedExports, includeComments, dts, useTabs);
|
|
23
|
+
|
|
24
|
+
const defaultExportCode = dts
|
|
25
|
+
? `declare const _default: {\n${flatExportLines}${namespaceExportLines}};\n\nexport default _default;\n`
|
|
26
|
+
: `export default {\n${flatExportLines}${namespaceExportLines}};`;
|
|
27
|
+
|
|
28
|
+
const namedExports = generateNamedExports(flatExports, exportRoots, dts);
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
return headerComment +
|
|
31
32
|
importStatements + '\n' +
|
|
32
33
|
namedExports + '\n' +
|
|
33
34
|
defaultExportCode;
|
|
35
|
+
|
|
34
36
|
}
|
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
export default function generateFlatExportLines(flatExports, exportRoots, includeComments, dts) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
export default function generateFlatExportLines(flatExports, exportRoots, includeComments, dts, useTabs = true) {
|
|
2
|
+
|
|
3
|
+
let indentStyle = useTabs ? '\t' : ' ';
|
|
4
|
+
|
|
5
|
+
let lines = '';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if (exportRoots) {
|
|
9
|
+
|
|
10
|
+
flatExports.forEach(({
|
|
11
|
+
functionName, importVarName, jsDocComment
|
|
12
|
+
}) => {
|
|
13
|
+
|
|
14
|
+
if (includeComments && jsDocComment) {
|
|
15
|
+
|
|
16
|
+
const indentedComment = jsDocComment
|
|
17
|
+
.split('\n')
|
|
18
|
+
.map((line) => indentStyle + line)
|
|
19
|
+
.join('\n');
|
|
20
|
+
|
|
21
|
+
lines += indentedComment + '\n';
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
lines += dts
|
|
26
|
+
? `${indentStyle}${functionName}: typeof ${importVarName};\n`
|
|
27
|
+
: `${indentStyle}${functionName}: ${importVarName},\n`;
|
|
28
|
+
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return lines;
|
|
34
|
+
|
|
18
35
|
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
export default function generateImportStatements(fileDataList, dts, src) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
|
|
3
|
+
let statements = '';
|
|
4
|
+
|
|
5
|
+
fileDataList.forEach(({
|
|
6
|
+
importVarName, importPath
|
|
7
|
+
}) => {
|
|
8
|
+
|
|
9
|
+
statements += dts
|
|
10
|
+
? `import type ${importVarName} from '.${importPath.replace(src,'')}';\n`
|
|
11
|
+
: `import ${importVarName} from '${importPath}.js';\n`;
|
|
12
|
+
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return statements;
|
|
16
|
+
|
|
9
17
|
}
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
export default function generateNamedExports(flatExports, exportRoots, dts) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
|
|
3
|
+
let lines = '';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
if (exportRoots) {
|
|
7
|
+
|
|
8
|
+
flatExports.forEach(({
|
|
9
|
+
functionName, importVarName
|
|
10
|
+
}) => {
|
|
11
|
+
|
|
12
|
+
lines += dts
|
|
13
|
+
? `export declare const ${functionName}: typeof ${importVarName};\n`
|
|
14
|
+
: `export { ${importVarName} as ${functionName} };\n`;
|
|
15
|
+
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return lines;
|
|
21
|
+
|
|
11
22
|
}
|
|
@@ -1,25 +1,46 @@
|
|
|
1
|
-
export default function generateNamespaceCode(nsObj, indentLevel, includeComments, dts) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
export default function generateNamespaceCode(nsObj, indentLevel, includeComments, dts, useTabs = true) {
|
|
2
|
+
|
|
3
|
+
let indentStyle = useTabs ? '\t' : ' ';
|
|
4
|
+
|
|
5
|
+
const indent = indentStyle.repeat(indentLevel);
|
|
6
|
+
let lines = [ '{' ];
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
for (const key in nsObj) {
|
|
10
|
+
|
|
11
|
+
const value = nsObj[key];
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
if (typeof value === 'object' && value.hasOwnProperty('importVarName')) {
|
|
15
|
+
|
|
16
|
+
if (includeComments && value.jsDocComment) {
|
|
17
|
+
|
|
18
|
+
const indentedComment = value.jsDocComment
|
|
19
|
+
.split('\n')
|
|
20
|
+
.map((line) => indent + indentStyle + line)
|
|
21
|
+
.join('\n');
|
|
22
|
+
|
|
23
|
+
lines.push(indentedComment);
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
lines.push(dts
|
|
28
|
+
? `${indent}${indentStyle}${key}: typeof ${value.importVarName},`
|
|
29
|
+
: `${indent}${indentStyle}${key}: ${value.importVarName},`
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
} else {
|
|
33
|
+
|
|
34
|
+
const nestedCode = generateNamespaceCode(value, indentLevel + 1, includeComments, dts);
|
|
35
|
+
|
|
36
|
+
lines.push(`${indent}${indentStyle}${key}: ${nestedCode},`);
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
lines.push(indent + '}');
|
|
43
|
+
|
|
44
|
+
return lines.join('\n');
|
|
45
|
+
|
|
25
46
|
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import generateNamespaceCode from './generateNamespaceCode.js';
|
|
2
2
|
|
|
3
|
-
export default function generateNamespaceExportLines(nestedExports, includeComments, dts) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
export default function generateNamespaceExportLines(nestedExports, includeComments, dts, useTabs = true) {
|
|
4
|
+
|
|
5
|
+
const indentStyle = useTabs ? '\t' : ' ';
|
|
6
|
+
|
|
7
|
+
let lines = '';
|
|
8
|
+
|
|
9
|
+
for (const ns in nestedExports) {
|
|
10
|
+
|
|
11
|
+
const nsCode = generateNamespaceCode(nestedExports[ns], 1, includeComments, dts, useTabs);
|
|
12
|
+
|
|
13
|
+
lines += `${indentStyle}${ns}: ${nsCode},\n`;
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return lines;
|
|
18
|
+
|
|
10
19
|
}
|