@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomeness-js/utils",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "Awesomeness - Utils",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3,7 +3,7 @@ import { readdirSync, statSync, readFileSync } from 'fs';
3
3
 
4
4
  function combineFiles(dir, fileType, {
5
5
  minify = false,
6
- moduleToBrowser = false,
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
- moduleToBrowser,
25
+ processContent,
26
26
  });
27
27
 
28
28
  } else {
29
29
 
30
30
  // is file
31
31
 
32
- // get file and extenstion from stuff
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(moduleToBrowser){
41
+ if(typeof processContent === 'function'){
42
42
 
43
- // can this file be converted to browser?
44
- let browserFriendly = thisData.startsWith('export default ');
45
-
46
- if(browserFriendly){
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
 
@@ -1,3 +1,3 @@
1
- export default function ignoreMeTest() {
1
+ export default () => {
2
2
  console.log('I should not be in the build!');
3
3
  };
@@ -0,0 +1,3 @@
1
+ export default async () => {
2
+ console.log('I should not be in the build!');
3
+ };
@@ -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('./src', 'js');
5
+ let combineTest = utils.combineFiles('./test', 'js');
6
6
 
7
- let combineTestBrowser = utils.combineFiles('./src', 'js', {
8
- moduleToBrowser: true
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(combineTestBrowser).toBeDefined();
14
- expect(combineTest.length).toBeGreaterThan(combineTestBrowser.length);
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
+ })
@@ -1 +1,2 @@
1
- export {};
1
+ declare const _default: (arr: any, schema?: {}) => any[];
2
+ export default _default;
@@ -1 +1,2 @@
1
- export {};
1
+ declare const _default: (obj: any, schema: any) => {};
2
+ export default _default;
@@ -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;
@@ -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;
@@ -1,5 +1,8 @@
1
1
  export default combineFiles;
2
- declare function combineFiles(dir: any, fileType: any, { minify, moduleToBrowser, }?: {
2
+ declare function combineFiles(dir: any, fileType: any, { minify, processContent, }?: {
3
3
  minify?: boolean;
4
- moduleToBrowser?: boolean;
4
+ processContent?: ({ content, path }: {
5
+ content: any;
6
+ path: any;
7
+ }) => any;
5
8
  }): string;
@@ -1 +1 @@
1
- export default function hashPassword(password: any): string;
1
+ export default function hashPassword(password: any): string;
@@ -1,2 +1,19 @@
1
- export default cleanArray;
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;