@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
package/src/clean/string.js
CHANGED
|
@@ -1,72 +1,96 @@
|
|
|
1
1
|
export default function cleanString(x, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
required = false,
|
|
3
|
+
minLength = false,
|
|
4
|
+
maxLength = false,
|
|
5
|
+
allowHtml = false,
|
|
6
|
+
allowScripts = false,
|
|
7
|
+
validValues = false
|
|
8
8
|
} = {}){
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
10
|
+
if(allowScripts && !allowHtml){
|
|
11
|
+
|
|
12
|
+
allowHtml = true;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
|
|
18
|
+
if(typeof x !== 'string') {
|
|
19
|
+
|
|
20
|
+
throw {
|
|
21
|
+
name: 'TypeError',
|
|
22
|
+
message: 'Input must be a string',
|
|
23
|
+
value: x
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if(minLength !== false && x.length < minLength) {
|
|
29
|
+
|
|
30
|
+
throw {
|
|
31
|
+
message: `String length must be between ${minLength} `,
|
|
32
|
+
length: x.length,
|
|
33
|
+
value: x
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if(maxLength !== false && x.length > maxLength) {
|
|
39
|
+
|
|
40
|
+
throw {
|
|
41
|
+
message: `String length must be less than or equal to ${maxLength}`,
|
|
42
|
+
length: x.length,
|
|
43
|
+
value: x
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if(!allowHtml && /<[^>]*>/g.test(x)) {
|
|
49
|
+
|
|
50
|
+
throw {
|
|
51
|
+
message: 'HTML tags are not allowed',
|
|
52
|
+
value: x
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if(!allowScripts && /<script[^>]*>.*<\/script>/g.test(x)) {
|
|
58
|
+
|
|
59
|
+
throw {
|
|
60
|
+
message: 'Script tags are not allowed',
|
|
61
|
+
value: x
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if(
|
|
67
|
+
validValues
|
|
68
|
+
&& Array.isArray(validValues)
|
|
69
|
+
&& !validValues.includes(x)
|
|
70
|
+
) {
|
|
71
|
+
|
|
72
|
+
throw {
|
|
73
|
+
message: `Value invalid`,
|
|
74
|
+
validValues,
|
|
75
|
+
value: x
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return x;
|
|
81
|
+
|
|
82
|
+
} catch (e) {
|
|
83
|
+
|
|
84
|
+
if(required) {
|
|
85
|
+
|
|
86
|
+
throw e;
|
|
87
|
+
|
|
88
|
+
} else {
|
|
89
|
+
|
|
90
|
+
return null;
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
}
|
|
71
95
|
|
|
72
96
|
}
|
package/src/clean/timestamp.js
CHANGED
|
@@ -1,50 +1,66 @@
|
|
|
1
1
|
export default function cleanTimestamp( isoDateTimeString , {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
required = false,
|
|
3
|
+
maxDaysInFuture = false,
|
|
4
|
+
maxDaysInFPast = false,
|
|
5
5
|
} = {}){
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
|
|
9
|
+
if(typeof isoDateTimeString !== 'string') {
|
|
10
|
+
|
|
11
|
+
throw {
|
|
12
|
+
message: 'Input must be a string',
|
|
13
|
+
isoDateTimeString
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const date = new Date(isoDateTimeString);
|
|
19
|
+
|
|
20
|
+
if(isNaN(date.getTime())) {
|
|
21
|
+
|
|
22
|
+
throw {
|
|
23
|
+
message: 'Invalid date string',
|
|
24
|
+
isoDateTimeString
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const now = new Date();
|
|
30
|
+
|
|
31
|
+
if(maxDaysInFuture !== false && (date - now) > maxDaysInFuture * 24 * 60 * 60 * 1000) {
|
|
32
|
+
|
|
33
|
+
throw {
|
|
34
|
+
message: `Date is more than ${maxDaysInFuture} days in the future`,
|
|
35
|
+
isoDateTimeString
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if(maxDaysInFPast !== false && (now - date) > maxDaysInFPast * 24 * 60 * 60 * 1000) {
|
|
41
|
+
|
|
42
|
+
throw {
|
|
43
|
+
message: `Date is more than ${maxDaysInFPast} days in the past`,
|
|
44
|
+
value: isoDateTimeString
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return date.toISOString();
|
|
50
|
+
|
|
51
|
+
} catch (e) {
|
|
52
|
+
|
|
53
|
+
if(required) {
|
|
54
|
+
|
|
55
|
+
throw e;
|
|
56
|
+
|
|
57
|
+
} else {
|
|
58
|
+
|
|
59
|
+
return null;
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
48
64
|
|
|
49
65
|
|
|
50
66
|
|
package/src/clean/uuid.js
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
import isUUID from "../isUUID.js";
|
|
2
|
+
|
|
2
3
|
export default function cleanUUID(uuid,{
|
|
3
|
-
|
|
4
|
+
required = false,
|
|
4
5
|
} = {}){
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
|
|
9
|
+
if(typeof uuid !== 'string'){
|
|
10
|
+
|
|
11
|
+
throw {
|
|
12
|
+
message: 'Input must be a string',
|
|
13
|
+
uuid
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if(!isUUID(uuid)){
|
|
19
|
+
|
|
20
|
+
throw {
|
|
21
|
+
message: 'Invalid UUID format',
|
|
22
|
+
uuid
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return uuid;
|
|
28
|
+
|
|
29
|
+
} catch (e) {
|
|
30
|
+
|
|
31
|
+
if(required) {
|
|
32
|
+
|
|
33
|
+
throw e;
|
|
34
|
+
|
|
35
|
+
} else {
|
|
36
|
+
|
|
37
|
+
return null;
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
29
42
|
|
|
30
43
|
|
|
31
44
|
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import md5 from './md5.js';
|
|
4
|
+
import each from './each.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function collectImports(filePath, seen = new Set(), collected = []) {
|
|
8
|
+
|
|
9
|
+
const fullPath = path.resolve(filePath);
|
|
10
|
+
|
|
11
|
+
if (seen.has(fullPath)) return;
|
|
12
|
+
seen.add(fullPath);
|
|
13
|
+
|
|
14
|
+
const code = fs.readFileSync(fullPath, 'utf-8');
|
|
15
|
+
const hash = md5(code);
|
|
16
|
+
|
|
17
|
+
collected.push({
|
|
18
|
+
fullPath,
|
|
19
|
+
hash,
|
|
20
|
+
code,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const importRegex = /import\s+.*?['"](.+?)['"];?/g;
|
|
24
|
+
let match;
|
|
25
|
+
|
|
26
|
+
while ((match = importRegex.exec(code)) !== null) {
|
|
27
|
+
|
|
28
|
+
const importPath = match[1];
|
|
29
|
+
|
|
30
|
+
// Skip package imports (non-relative paths)
|
|
31
|
+
if (!importPath.startsWith('.')) continue;
|
|
32
|
+
|
|
33
|
+
const resolved = resolveImport(path.dirname(fullPath), importPath);
|
|
34
|
+
|
|
35
|
+
if (resolved) collectImports(resolved, seen, collected);
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return collected;
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function findProjectRoot(from = process.cwd()) {
|
|
44
|
+
|
|
45
|
+
let currentPath = from;
|
|
46
|
+
|
|
47
|
+
while (true) {
|
|
48
|
+
|
|
49
|
+
if (fs.existsSync(path.join(currentPath, 'package.json'))) {
|
|
50
|
+
|
|
51
|
+
return currentPath;
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const parent = path.dirname(currentPath);
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if (parent === currentPath) {
|
|
59
|
+
|
|
60
|
+
throw new Error('Project root not found (no package.json)');
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
currentPath = parent;
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
function resolveImport(baseDir, importPath) {
|
|
72
|
+
|
|
73
|
+
const candidates = [
|
|
74
|
+
importPath,
|
|
75
|
+
`${importPath}.js`,
|
|
76
|
+
`${importPath}.css`,
|
|
77
|
+
path.join(importPath, 'index.js'),
|
|
78
|
+
path.join(importPath, 'index.css'),
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
for (const candidate of candidates) {
|
|
82
|
+
|
|
83
|
+
const full = path.resolve(baseDir, candidate);
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if (fs.existsSync(full) && fs.statSync(full).isFile()) {
|
|
87
|
+
|
|
88
|
+
return full;
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return null;
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function jsName( file ){
|
|
99
|
+
|
|
100
|
+
return file.rootPath
|
|
101
|
+
.replace('.'+file.type, '')
|
|
102
|
+
.replaceAll('/', '.');
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function cssName( file ){
|
|
107
|
+
|
|
108
|
+
return file.rootPath
|
|
109
|
+
.replace('.'+file.type, '')
|
|
110
|
+
.replaceAll('/', '_');
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function run(filePath, {
|
|
115
|
+
returnCode = true,
|
|
116
|
+
jsMaps = {},
|
|
117
|
+
cssMaps = {}
|
|
118
|
+
} = {}){
|
|
119
|
+
|
|
120
|
+
const root = findProjectRoot(__dirname);
|
|
121
|
+
|
|
122
|
+
const imports = collectImports(filePath);
|
|
123
|
+
|
|
124
|
+
imports.forEach((file) => {
|
|
125
|
+
|
|
126
|
+
const rootPath = path.relative(root, file.fullPath).replace(/\\/g, '/');
|
|
127
|
+
|
|
128
|
+
file.rootPath = rootPath;
|
|
129
|
+
|
|
130
|
+
// strip file type
|
|
131
|
+
const fileType = rootPath.split('.').pop();
|
|
132
|
+
|
|
133
|
+
file.type = fileType;
|
|
134
|
+
|
|
135
|
+
if(fileType === 'js'){
|
|
136
|
+
|
|
137
|
+
file.name = jsName(file);
|
|
138
|
+
|
|
139
|
+
if(Object.keys(jsMaps).length){
|
|
140
|
+
|
|
141
|
+
each(jsMaps,( v, k ) => {
|
|
142
|
+
|
|
143
|
+
file.name = file.name.replace(k.replace(/\.\//g, ''),v);
|
|
144
|
+
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if(returnCode){
|
|
150
|
+
|
|
151
|
+
file.code = file.code.replace(/import\s+.*?['"](.+?)['"];?/g, '').replace('export default', `${file.name} =`);
|
|
152
|
+
|
|
153
|
+
} else {
|
|
154
|
+
|
|
155
|
+
delete file.code;
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if(fileType === 'css'){
|
|
163
|
+
|
|
164
|
+
file.name = cssName(file);
|
|
165
|
+
|
|
166
|
+
if(Object.keys(cssMaps).length){
|
|
167
|
+
|
|
168
|
+
each(cssMaps,( v, k ) => {
|
|
169
|
+
|
|
170
|
+
file.name = file.name.replace(k.replace(/\.\//g, ''),v);
|
|
171
|
+
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if(returnCode){
|
|
177
|
+
|
|
178
|
+
file.code = file.code.replace(/import\s+.*?['"](.+?)['"];?/g, '');
|
|
179
|
+
|
|
180
|
+
} else {
|
|
181
|
+
|
|
182
|
+
delete file.code;
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return imports;
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export default run;
|
package/src/combineFiles.js
CHANGED
|
@@ -1,66 +1,75 @@
|
|
|
1
1
|
// main-module/index.js
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
readdirSync, statSync, readFileSync
|
|
4
|
+
} from 'fs';
|
|
3
5
|
|
|
4
6
|
function combineFiles(dir, fileType, {
|
|
5
7
|
minify = false,
|
|
6
|
-
processContent = ({
|
|
8
|
+
processContent = ({
|
|
9
|
+
content, path
|
|
10
|
+
}) => {
|
|
11
|
+
|
|
12
|
+
return content;
|
|
13
|
+
|
|
14
|
+
},
|
|
7
15
|
} = {}) {
|
|
8
16
|
|
|
9
|
-
|
|
17
|
+
var returnString = "";
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
let stuff = readdirSync(dir);
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
// sort it
|
|
22
|
+
stuff = stuff.sort();
|
|
15
23
|
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
stuff.forEach((stuff) => {
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
const isDir = statSync(`${dir}/${stuff}`).isDirectory();
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
if(isDir){
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
returnString += combineFiles(`${dir}/${stuff}`, fileType, {
|
|
32
|
+
minify,
|
|
33
|
+
processContent,
|
|
34
|
+
});
|
|
27
35
|
|
|
28
|
-
|
|
36
|
+
} else {
|
|
29
37
|
|
|
30
|
-
|
|
38
|
+
// is file
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
// get file and extension from stuff
|
|
41
|
+
let file = stuff.split('.');
|
|
42
|
+
let ext = file[file.length - 1];
|
|
35
43
|
|
|
36
44
|
|
|
37
|
-
|
|
45
|
+
if(ext === fileType){
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if(typeof processContent === 'function'){
|
|
42
|
-
|
|
43
|
-
thisData = processContent({
|
|
44
|
-
path: `${dir}/${stuff}`,
|
|
45
|
-
content: thisData,
|
|
46
|
-
});
|
|
47
|
+
let thisData = readFileSync(`${dir}/${stuff}`, 'utf8');
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
if(typeof processContent === 'function'){
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
thisData = processContent({
|
|
52
|
+
path: `${dir}/${stuff}`,
|
|
53
|
+
content: thisData,
|
|
54
|
+
});
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
}
|
|
55
57
|
|
|
58
|
+
if(minify){
|
|
59
|
+
// todo
|
|
56
60
|
}
|
|
57
61
|
|
|
62
|
+
returnString += thisData + " \n ";
|
|
63
|
+
|
|
58
64
|
}
|
|
59
65
|
|
|
60
|
-
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return returnString;
|
|
61
71
|
|
|
62
|
-
|
|
72
|
+
}
|
|
63
73
|
|
|
64
|
-
};
|
|
65
74
|
|
|
66
|
-
|
|
75
|
+
export default combineFiles;
|
package/src/convertBytes.js
CHANGED
|
@@ -7,10 +7,15 @@
|
|
|
7
7
|
* @returns {string} The converted bytes in a string format with appropriate units.
|
|
8
8
|
*/
|
|
9
9
|
export default function convertBytes(bytes, precision = 2) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
|
|
11
|
+
const units = [ 'B', 'KB', 'MB', 'GB', 'TB' ];
|
|
12
|
+
|
|
13
|
+
bytes = Math.max(bytes, 0);
|
|
14
|
+
const pow = Math.floor((bytes ? Math.log(bytes) : 0) / Math.log(1024));
|
|
15
|
+
const index = Math.min(pow, units.length - 1);
|
|
16
|
+
|
|
17
|
+
bytes /= 2 ** (10 * pow);
|
|
18
|
+
|
|
19
|
+
return `${bytes.toFixed(precision)} ${units[index]}`;
|
|
20
|
+
|
|
21
|
+
}
|