@awesomeness-js/utils 1.0.22 → 1.0.24
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/package.json +1 -1
- package/src/combineFiles.js +8 -20
- package/test/ignoreFolder/ignoreMe.js +1 -1
- package/test/ignoreFolder/ignoreMe2.js +3 -0
- package/tests/combineFiles.test.js +26 -15
- package/types/clean/array.d.ts +2 -1
- package/types/clean/object.d.ts +2 -1
- package/types/clean/string.d.ts +2 -1
- package/types/clean/thing.d.ts +2 -2
- package/types/combineFiles.d.ts +5 -2
- package/types/hashPassword.d.ts +1 -1
- package/types/utils/clean.d.ts +18 -1
- package/types/validatePassword.d.ts +1 -1
package/package.json
CHANGED
package/src/combineFiles.js
CHANGED
|
@@ -3,7 +3,7 @@ import { readdirSync, statSync, readFileSync } from 'fs';
|
|
|
3
3
|
|
|
4
4
|
function combineFiles(dir, fileType, {
|
|
5
5
|
minify = false,
|
|
6
|
-
|
|
6
|
+
processContent = ({ content, path }) => { return content; },
|
|
7
7
|
} = {}) {
|
|
8
8
|
|
|
9
9
|
var returnString = "";
|
|
@@ -22,14 +22,14 @@ function combineFiles(dir, fileType, {
|
|
|
22
22
|
|
|
23
23
|
returnString += combineFiles(`${dir}/${stuff}`, fileType, {
|
|
24
24
|
minify,
|
|
25
|
-
|
|
25
|
+
processContent,
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
} else {
|
|
29
29
|
|
|
30
30
|
// is file
|
|
31
31
|
|
|
32
|
-
// get file and
|
|
32
|
+
// get file and extension from stuff
|
|
33
33
|
let file = stuff.split('.');
|
|
34
34
|
let ext = file[file.length - 1];
|
|
35
35
|
|
|
@@ -38,24 +38,12 @@ function combineFiles(dir, fileType, {
|
|
|
38
38
|
|
|
39
39
|
let thisData = readFileSync(`${dir}/${stuff}`, 'utf8');
|
|
40
40
|
|
|
41
|
-
if(
|
|
41
|
+
if(typeof processContent === 'function'){
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
browserFriendly = thisData.includes('import') === false; // no imports allowed
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if(browserFriendly){
|
|
52
|
-
|
|
53
|
-
// strip properly formatted file
|
|
54
|
-
thisData = thisData.replace('export default ', '');
|
|
55
|
-
|
|
56
|
-
} else {
|
|
57
|
-
thisData = "";
|
|
58
|
-
}
|
|
43
|
+
thisData = processContent({
|
|
44
|
+
path: `${dir}/${stuff}`,
|
|
45
|
+
content: thisData,
|
|
46
|
+
});
|
|
59
47
|
|
|
60
48
|
}
|
|
61
49
|
|
|
@@ -2,23 +2,34 @@
|
|
|
2
2
|
import { expect, test } from 'vitest'
|
|
3
3
|
import utils from '../index.js';
|
|
4
4
|
|
|
5
|
-
let combineTest = utils.combineFiles('./
|
|
5
|
+
let combineTest = utils.combineFiles('./test', 'js');
|
|
6
6
|
|
|
7
|
-
let
|
|
8
|
-
|
|
7
|
+
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
|
+
},
|
|
9
28
|
});
|
|
10
29
|
|
|
11
30
|
test('combineFiles - combine all files in src/js', () => {
|
|
12
31
|
expect(combineTest).toBeDefined();
|
|
13
|
-
expect(
|
|
14
|
-
expect(combineTest
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
test('has import', () => {
|
|
19
|
-
expect(combineTest.includes('import')).toBe(true);
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test('should not have import', () => {
|
|
23
|
-
expect(combineTestBrowser.includes('import')).toBe(false);
|
|
24
|
-
})
|
|
32
|
+
expect(combineTest2).toBeDefined();
|
|
33
|
+
expect(combineTest).not.toEqual(combineTest2);
|
|
34
|
+
console.log({combineTest2});
|
|
35
|
+
})
|
package/types/clean/array.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
declare const _default: (arr: any, schema?: {}) => any[];
|
|
2
|
+
export default _default;
|
package/types/clean/object.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
declare const _default: (obj: any, schema: any) => {};
|
|
2
|
+
export default _default;
|
package/types/clean/string.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export default function cleanString(x: any, { required, minLength, maxLength, allowHtml, allowScripts }?: {
|
|
1
|
+
export default function cleanString(x: any, { required, minLength, maxLength, allowHtml, allowScripts, validValues }?: {
|
|
2
2
|
required?: boolean;
|
|
3
3
|
minLength?: boolean;
|
|
4
4
|
maxLength?: boolean;
|
|
5
5
|
allowHtml?: boolean;
|
|
6
6
|
allowScripts?: boolean;
|
|
7
|
+
validValues?: boolean;
|
|
7
8
|
}): string;
|
package/types/clean/thing.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function _default(thing: any, schema: any): any;
|
|
2
|
-
export default _default;
|
|
1
|
+
declare function _default(thing: any, schema: any): any;
|
|
2
|
+
export default _default;
|
package/types/combineFiles.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export default combineFiles;
|
|
2
|
-
declare function combineFiles(dir: any, fileType: any, { minify,
|
|
2
|
+
declare function combineFiles(dir: any, fileType: any, { minify, processContent, }?: {
|
|
3
3
|
minify?: boolean;
|
|
4
|
-
|
|
4
|
+
processContent?: ({ content, path }: {
|
|
5
|
+
content: any;
|
|
6
|
+
path: any;
|
|
7
|
+
}) => any;
|
|
5
8
|
}): string;
|
package/types/hashPassword.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function hashPassword(password: any): string;
|
|
1
|
+
export default function hashPassword(password: any): string;
|
package/types/utils/clean.d.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { cleanArray as array };
|
|
3
|
+
export { cleanObject as object };
|
|
4
|
+
export { cleanBoolean as boolean };
|
|
5
|
+
export { cleanInteger as integer };
|
|
6
|
+
export { cleanNumber as number };
|
|
7
|
+
export { cleanString as string };
|
|
8
|
+
export { cleanTimestamp as timestamp };
|
|
9
|
+
export { cleanUUID as uuid };
|
|
10
|
+
}
|
|
11
|
+
export default _default;
|
|
2
12
|
declare function cleanArray(arr: any, schema?: {}): any[];
|
|
13
|
+
declare function cleanObject(obj: any, schema: any): {};
|
|
14
|
+
import cleanBoolean from '../clean/boolean.js';
|
|
15
|
+
import cleanInteger from '../clean/integer.js';
|
|
16
|
+
import cleanNumber from '../clean/number.js';
|
|
17
|
+
import cleanString from '../clean/string.js';
|
|
18
|
+
import cleanTimestamp from '../clean/timestamp.js';
|
|
19
|
+
import cleanUUID from '../clean/uuid.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function validatePassword(password: any, storedHash: any): boolean;
|
|
1
|
+
export default function validatePassword(password: any, storedHash: any): boolean;
|