@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.
Files changed (90) hide show
  1. package/README.md +112 -86
  2. package/build/build.js +16 -11
  3. package/build/postBuild.js +8 -8
  4. package/eslint.config.js +90 -0
  5. package/index.js +108 -78
  6. package/package.json +26 -25
  7. package/schemas/schema1.js +5 -1
  8. package/schemas/schema2.js +5 -1
  9. package/schemas.js +3 -2
  10. package/src/build.js +88 -8
  11. package/src/clean/boolean.js +27 -17
  12. package/src/clean/integer.js +85 -69
  13. package/src/clean/number.js +103 -86
  14. package/src/clean/string.js +91 -67
  15. package/src/clean/timestamp.js +61 -45
  16. package/src/clean/uuid.js +38 -25
  17. package/src/collectImports.js +195 -0
  18. package/src/combineFiles.js +45 -36
  19. package/src/convertBytes.js +12 -7
  20. package/src/decrypt.js +17 -9
  21. package/src/each.js +26 -4
  22. package/src/eachAsync.js +35 -19
  23. package/src/encrypt.js +22 -17
  24. package/src/getAllFiles.js +56 -42
  25. package/src/ignoreFolder/ignoreMe.js +6 -2
  26. package/src/ignoreMe.js +4 -2
  27. package/src/isUUID.js +4 -0
  28. package/src/md5.js +5 -1
  29. package/src/password/check.js +7 -3
  30. package/src/password/hash.js +12 -7
  31. package/src/setLocalEnvs.js +16 -3
  32. package/src/shouldIgnore.js +99 -0
  33. package/src/thingType.js +62 -24
  34. package/src/toPennies.js +23 -5
  35. package/src/utils/buildExportsTree.js +45 -17
  36. package/src/utils/buildFileDataList.js +37 -18
  37. package/src/utils/clean.js +205 -120
  38. package/src/utils/extractJSDocComment.js +14 -7
  39. package/src/utils/generateFile.js +54 -18
  40. package/src/utils/generateFlatExportLines.js +40 -17
  41. package/src/utils/generateImportStatements.js +20 -8
  42. package/src/utils/generateNamedExports.js +55 -10
  43. package/src/utils/generateNamespaceCode.js +56 -24
  44. package/src/utils/generateNamespaceExportLines.js +27 -7
  45. package/src/utils/writeHotWrapper.js +42 -0
  46. package/src/uuid.js +9 -7
  47. package/src/validateSchema.js +95 -77
  48. package/test/collectImports.js +8 -0
  49. package/test/css/some.css +3 -0
  50. package/test/css/some.js +5 -0
  51. package/test/ignoreFolder/ignoreMe.js +3 -1
  52. package/test/ignoreFolder/ignoreMe2.js +3 -1
  53. package/test/ignoreFolder2/ignoreMe.js +6 -2
  54. package/test/js/abc.test.js +7 -3
  55. package/test/js/some.js +5 -0
  56. package/test/secret.test.js +1 -1
  57. package/tests/clean/array.test.js +122 -74
  58. package/tests/clean/boolean.test.js +18 -6
  59. package/tests/clean/integer.test.js +25 -9
  60. package/tests/clean/number.test.js +49 -13
  61. package/tests/clean/object.test.js +190 -119
  62. package/tests/clean/string.test.js +48 -17
  63. package/tests/clean/timestamp.test.js +12 -5
  64. package/tests/clean/uuid.test.js +13 -6
  65. package/tests/collectImports.test.js +66 -0
  66. package/tests/combineFiles.test.js +28 -26
  67. package/tests/convertBytes.test.js +8 -3
  68. package/tests/env.test.js +9 -3
  69. package/tests/example.test.js +7 -3
  70. package/tests/fileList.test.js +16 -12
  71. package/tests/hash-and-encrypt.test.js +13 -4
  72. package/tests/ignore.test.js +55 -0
  73. package/tests/md5.test.js +7 -2
  74. package/tests/namedExports.test.js +13 -0
  75. package/tests/uuid.test.js +10 -4
  76. package/tests/validateSchema.test.js +21 -9
  77. package/tsconfig.json +20 -16
  78. package/types/build.d.ts +5 -1
  79. package/types/collectImports.d.ts +6 -0
  80. package/types/index.d.ts +108 -78
  81. package/types/shouldIgnore.d.ts +1 -0
  82. package/types/utils/buildFileDataList.d.ts +5 -1
  83. package/types/utils/generateFile.d.ts +8 -1
  84. package/types/utils/generateFlatExportLines.d.ts +7 -1
  85. package/types/utils/generateImportStatements.d.ts +5 -1
  86. package/types/utils/generateNamedExports.d.ts +7 -1
  87. package/types/utils/generateNamespaceCode.d.ts +7 -1
  88. package/types/utils/generateNamespaceExportLines.d.ts +6 -1
  89. package/types/utils/writeHotWrapper.d.ts +4 -0
  90. package/src/utils/shouldIgnore.js +0 -43
package/package.json CHANGED
@@ -1,26 +1,27 @@
1
1
  {
2
- "name": "@awesomeness-js/utils",
3
- "version": "1.0.24",
4
- "description": "Awesomeness - Utils",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/awesomeness-js/utils.git"
8
- },
9
- "scripts": {
10
- "prebuild": "node ./build/build.js",
11
- "build": "tsc && npm run postBuild",
12
- "postBuild": "node ./build/postBuild.js",
13
- "test": "vitest"
14
- },
15
- "type": "module",
16
- "types": "./types/index.d.ts",
17
- "main": "index.js",
18
- "author": "Scott Forte",
19
- "license": "MIT",
20
- "publishConfig": {
21
- "access": "public"
22
- },
23
- "devDependencies": {
24
- "vitest": "^3.0.9"
25
- }
26
- }
2
+ "name": "@awesomeness-js/utils",
3
+ "version": "1.1.2",
4
+ "description": "Awesomeness - Utils",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/awesomeness-js/utils.git"
8
+ },
9
+ "scripts": {
10
+ "prebuild": "node ./build/build.js",
11
+ "build": "tsc && npm run postBuild",
12
+ "postBuild": "node ./build/postBuild.js",
13
+ "test": "vitest"
14
+ },
15
+ "type": "module",
16
+ "types": "./types/index.d.ts",
17
+ "main": "index.js",
18
+ "author": "Scott Forte",
19
+ "license": "MIT",
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "devDependencies": {
24
+ "vitest": "^3.0.9",
25
+ "chokidar": "^4.0.3"
26
+ }
27
+ }
@@ -5,7 +5,11 @@ const properties = {
5
5
  exampleId: {
6
6
  type: 'uuid',
7
7
  description: 'the id of the vertex',
8
- default: () => { return uuid(); },
8
+ default: () => {
9
+
10
+ return uuid();
11
+
12
+ },
9
13
  example: '00000000-0000-0000-0000-000000000000',
10
14
  immutable: true,
11
15
  required: true
@@ -5,7 +5,11 @@ const properties = {
5
5
  exampleId: {
6
6
  type: 'uuid',
7
7
  description: 'the id of the vertex',
8
- default: () => { return uuid(); },
8
+ default: () => {
9
+
10
+ return uuid();
11
+
12
+ },
9
13
  example: '00000000-0000-0000-0000-000000000000',
10
14
  immutable: true,
11
15
  required: true
package/schemas.js CHANGED
@@ -9,7 +9,8 @@ import _schema2 from './schemas/schema2.js';
9
9
  export { _schema1 as schema1 };
10
10
  export { _schema2 as schema2 };
11
11
 
12
+
12
13
  export default {
13
- schema1: _schema1,
14
- schema2: _schema2,
14
+ schema1: _schema1,
15
+ schema2: _schema2,
15
16
  };
package/src/build.js CHANGED
@@ -12,17 +12,97 @@
12
12
  */
13
13
  import { writeFileSync } from 'fs';
14
14
  import generateFile from './utils/generateFile.js';
15
+ import writeHotWrapper from './utils/writeHotWrapper.js';
15
16
 
16
17
  async function build({
17
- src = './src',
18
- dest = './index.js',
19
- exportRoots = true,
20
- ignore = [],
21
- includeComments = true,
22
- dts = false
18
+ src = './src',
19
+ dest = './index.js',
20
+ exportRoots = true,
21
+ ignore = [],
22
+ includeComments = true,
23
+ dts = false,
24
+ useTabs = true,
25
+ hotModuleReload = false,
26
+ hotCallback = null,
27
+ hotSource = './hot-source.js' // generated only when hot is enabled
23
28
  } = {}) {
24
- writeFileSync(dest, generateFile(src, exportRoots, ignore, includeComments, dts));
25
- return true;
29
+
30
+ const gen = () => generateFile({
31
+ src,
32
+ exportRoots,
33
+ ignore,
34
+ includeComments,
35
+ dts,
36
+ useTabs
37
+ });
38
+
39
+ const buildHot = () => {
40
+
41
+ // 1) write payload that the wrapper imports
42
+ writeFileSync(hotSource, gen());
43
+ console.log(`[build] wrote ${hotSource}`);
44
+
45
+ // 2) ensure index.js is a hot wrapper
46
+ writeHotWrapper({
47
+ dest,
48
+ hotSource
49
+ });
50
+
51
+ console.log(`[build] ensured hot wrapper ${dest}`);
52
+
53
+ };
54
+
55
+ const buildCold = () => {
56
+
57
+ // single-file classic output (no second file)
58
+ writeFileSync(dest, gen());
59
+ console.log(`[build] wrote ${dest}`);
60
+
61
+ };
62
+
63
+ if (hotModuleReload) {
64
+
65
+ buildHot();
66
+
67
+ // watch only src; each change regenerates hot-source.js (wrapper auto-reloads it)
68
+ const chokidar = (await import('chokidar')).default;
69
+
70
+ console.log(`[build] watching ${src} for changes...`);
71
+ const watcher = chokidar.watch(src, {
72
+ ignoreInitial: true,
73
+ ignored: ignore
74
+ });
75
+
76
+ let timeout;
77
+
78
+ watcher.on('all', (_event, file) => {
79
+
80
+ clearTimeout(timeout);
81
+ timeout = setTimeout(() => {
82
+
83
+ console.log(`[build] change detected in ${file}, rebuilding payload...`);
84
+ writeFileSync(hotSource, gen());
85
+
86
+ if(typeof hotCallback === 'function') {
87
+
88
+ hotCallback(file);
89
+
90
+ }
91
+
92
+ console.log(`[build] ready.`);
93
+
94
+ }, 50);
95
+
96
+ });
97
+
98
+ } else {
99
+
100
+ buildCold();
101
+
102
+ }
103
+
104
+ return true;
105
+
26
106
  }
27
107
 
28
108
  export default build;
@@ -1,22 +1,32 @@
1
1
  export default function cleanBoolean(x, {
2
- required = false
2
+ required = false
3
3
  } = {}){
4
4
 
5
- try {
6
-
7
- if(x !== true && x !== false){
8
- throw {
9
- message: `Invalid boolean value "${x}"`,
10
- }
11
- }
12
-
13
- return x;
14
-
15
- } catch (e) {
16
-
17
- if(required) { throw e; } else { return null; }
18
-
19
- }
20
-
5
+ try {
6
+
7
+ if(x !== true && x !== false){
8
+
9
+ throw {
10
+ message: `Invalid boolean value "${x}"`,
11
+ };
12
+
13
+ }
14
+
15
+ return x;
16
+
17
+ } catch (e) {
18
+
19
+ if(required) {
20
+
21
+ throw e;
22
+
23
+ } else {
24
+
25
+ return null;
26
+
27
+ }
28
+
29
+ }
30
+
21
31
  }
22
32
 
@@ -1,74 +1,90 @@
1
1
  export default function cleanInt(x, {
2
- required = false,
3
- convertString = true,
4
- min = false,
5
- max = false,
2
+ required = false,
3
+ convertString = true,
4
+ min = false,
5
+ max = false,
6
6
  } = {}){
7
7
 
8
- try {
9
-
10
- if (typeof x !== 'number' || !Number.isInteger(x)) {
11
-
12
- // convert string to number if possible
13
- // but not a decimal string
14
- if (convertString && typeof x === 'string') {
15
-
16
- if(x.includes('.')){
17
- throw {
18
- message: 'string contains decimal',
19
- value: x
20
- };
21
- }
22
-
23
- if(!isNaN(parseInt(x))){
24
- x = parseInt(x);
25
- } else {
26
- throw {
27
- message: 'string cannot be parsed to integer',
28
- value: x
29
- }
30
- }
31
-
32
-
33
- } else {
34
- throw {
35
- message: 'Input must be an integer',
36
- value: x
37
- }
38
- }
39
-
40
- }
41
-
42
- if (min !== false && x < min) {
43
-
44
- throw {
45
- message: `Integer must be greater than or equal to ${min}`,
46
- value: x,
47
- min,
48
- max
49
- }
50
-
51
- }
52
-
53
- if (max !== false && x > max) {
54
-
55
- throw {
56
- message: `Integer must be less than or equal to ${max}`,
57
- value: x,
58
- min,
59
- max
60
- }
61
-
62
- }
63
-
64
- return x;
65
-
66
- } catch (e) {
67
-
68
- if(required) { throw e; } else { return null; }
69
-
70
- }
71
-
72
-
8
+ try {
9
+
10
+ if (typeof x !== 'number' || !Number.isInteger(x)) {
11
+
12
+ // convert string to number if possible
13
+ // but not a decimal string
14
+ if (convertString && typeof x === 'string') {
15
+
16
+ if(x.includes('.')){
17
+
18
+ throw {
19
+ message: 'string contains decimal',
20
+ value: x
21
+ };
22
+
23
+ }
24
+
25
+ if(!isNaN(parseInt(x))){
26
+
27
+ x = parseInt(x);
28
+
29
+ } else {
30
+
31
+ throw {
32
+ message: 'string cannot be parsed to integer',
33
+ value: x
34
+ };
35
+
36
+ }
37
+
38
+
39
+ } else {
40
+
41
+ throw {
42
+ message: 'Input must be an integer',
43
+ value: x
44
+ };
45
+
46
+ }
47
+
48
+ }
49
+
50
+ if (min !== false && x < min) {
51
+
52
+ throw {
53
+ message: `Integer must be greater than or equal to ${min}`,
54
+ value: x,
55
+ min,
56
+ max
57
+ };
58
+
59
+ }
60
+
61
+ if (max !== false && x > max) {
62
+
63
+ throw {
64
+ message: `Integer must be less than or equal to ${max}`,
65
+ value: x,
66
+ min,
67
+ max
68
+ };
69
+
70
+ }
71
+
72
+ return x;
73
+
74
+ } catch (e) {
75
+
76
+ if(required) {
77
+
78
+ throw e;
79
+
80
+ } else {
81
+
82
+ return null;
83
+
84
+ }
85
+
86
+ }
87
+
88
+
73
89
  }
74
90
 
@@ -1,93 +1,110 @@
1
1
  export default function cleanNumber(x, {
2
- required = false,
3
- convertString = true,
4
- min = false,
5
- max = false,
6
- maxDecimal = false,
7
- minDecimal = false,
2
+ required = false,
3
+ convertString = true,
4
+ min = false,
5
+ max = false,
6
+ maxDecimal = false,
7
+ minDecimal = false,
8
8
  } = {}){
9
9
 
10
- try {
11
-
12
- if (typeof x !== 'number') {
13
-
14
- // convert string to number if possible
15
- if (convertString && typeof x === 'string') {
16
-
17
- try {
18
- x = parseFloat(x);
19
- } catch(e){
20
- throw {
21
- message: 'Input cannot be parsed',
22
- value: x
23
- }
24
- }
25
-
26
-
27
- if(isNaN(x)){
28
- throw {
29
- message: 'Input cannot be parsed NaN',
30
- value: x
31
- }
32
- }
33
-
34
- } else {
35
- throw {
36
- message: 'Input must be a number',
37
- value: x
38
- }
39
- }
40
-
41
- }
42
-
43
- if (min !== false && x < min) {
44
-
45
- throw {
46
- message: `Integer must be greater than or equal to ${min}`,
47
- value: x,
48
- min,
49
- max
50
- }
51
-
52
- }
53
-
54
- if (max !== false && x > max) {
55
-
56
- throw {
57
- message: `Integer must be less than or equal to ${max}`,
58
- value: x,
59
- min,
60
- max
61
- }
62
-
63
- }
64
-
65
- if (maxDecimal !== false && x.toString().split('.')[1]?.length > maxDecimal) {
66
-
67
- throw {
68
- message: `Number must have at most ${maxDecimal} decimal places`,
69
- value: x,
70
- maxDecimal
71
- }
72
-
73
- }
74
-
75
- if (minDecimal !== false && x.toString().split('.')[1]?.length < minDecimal) {
76
-
77
- throw {
78
- message: `Number must have at least ${minDecimal} decimal places`,
79
- value: x,
80
- minDecimal
81
- }
82
-
83
- }
84
-
85
- return x;
10
+ try {
11
+
12
+ if (typeof x !== 'number') {
13
+
14
+ // convert string to number if possible
15
+ if (convertString && typeof x === 'string') {
16
+
17
+ try {
18
+
19
+ x = parseFloat(x);
20
+
21
+ } catch(e){
22
+
23
+ throw {
24
+ message: 'Input cannot be parsed',
25
+ value: x
26
+ };
27
+
28
+ }
29
+
30
+
31
+ if(isNaN(x)){
32
+
33
+ throw {
34
+ message: 'Input cannot be parsed NaN',
35
+ value: x
36
+ };
37
+
38
+ }
39
+
40
+ } else {
41
+
42
+ throw {
43
+ message: 'Input must be a number',
44
+ value: x
45
+ };
46
+
47
+ }
48
+
49
+ }
50
+
51
+ if (min !== false && x < min) {
52
+
53
+ throw {
54
+ message: `Integer must be greater than or equal to ${min}`,
55
+ value: x,
56
+ min,
57
+ max
58
+ };
59
+
60
+ }
61
+
62
+ if (max !== false && x > max) {
63
+
64
+ throw {
65
+ message: `Integer must be less than or equal to ${max}`,
66
+ value: x,
67
+ min,
68
+ max
69
+ };
70
+
71
+ }
72
+
73
+ if (maxDecimal !== false && x.toString().split('.')[1]?.length > maxDecimal) {
74
+
75
+ throw {
76
+ message: `Number must have at most ${maxDecimal} decimal places`,
77
+ value: x,
78
+ maxDecimal
79
+ };
80
+
81
+ }
82
+
83
+ if (minDecimal !== false && x.toString().split('.')[1]?.length < minDecimal) {
84
+
85
+ throw {
86
+ message: `Number must have at least ${minDecimal} decimal places`,
87
+ value: x,
88
+ minDecimal
89
+ };
90
+
91
+ }
92
+
93
+ return x;
86
94
 
87
- } catch (e) {
95
+ } catch (e) {
96
+
97
+ if(required) {
98
+
99
+ throw e;
100
+
101
+ } else {
102
+
103
+ return null;
104
+
105
+ }
106
+
107
+ }
88
108
 
89
- if(required) { throw e; } else { return null; }
90
-
91
- }
92
109
  }
93
110