@awesomeness-js/utils 1.0.23 → 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.
Files changed (88) hide show
  1. package/build/build.js +11 -11
  2. package/build/postBuild.js +8 -8
  3. package/eslint.config.js +90 -0
  4. package/index.js +139 -136
  5. package/package.json +25 -25
  6. package/schemas/schema1.js +5 -1
  7. package/schemas/schema2.js +5 -1
  8. package/schemas.js +14 -14
  9. package/src/build.js +12 -8
  10. package/src/clean/boolean.js +27 -17
  11. package/src/clean/integer.js +85 -69
  12. package/src/clean/number.js +103 -86
  13. package/src/clean/string.js +91 -67
  14. package/src/clean/timestamp.js +61 -45
  15. package/src/clean/uuid.js +38 -25
  16. package/src/collectImports.js +195 -0
  17. package/src/combineFiles.js +45 -36
  18. package/src/convertBytes.js +12 -7
  19. package/src/decrypt.js +17 -9
  20. package/src/each.js +26 -4
  21. package/src/eachAsync.js +35 -19
  22. package/src/encrypt.js +22 -17
  23. package/src/getAllFiles.js +55 -41
  24. package/src/ignoreFolder/ignoreMe.js +6 -2
  25. package/src/ignoreMe.js +4 -2
  26. package/src/isUUID.js +4 -0
  27. package/src/md5.js +5 -1
  28. package/src/password/check.js +7 -3
  29. package/src/password/hash.js +12 -7
  30. package/src/setLocalEnvs.js +16 -3
  31. package/src/thingType.js +62 -24
  32. package/src/toPennies.js +23 -5
  33. package/src/utils/buildExportsTree.js +45 -17
  34. package/src/utils/buildFileDataList.js +32 -17
  35. package/src/utils/clean.js +205 -120
  36. package/src/utils/extractJSDocComment.js +14 -7
  37. package/src/utils/generateFile.js +20 -18
  38. package/src/utils/generateFlatExportLines.js +34 -17
  39. package/src/utils/generateImportStatements.js +15 -7
  40. package/src/utils/generateNamedExports.js +20 -9
  41. package/src/utils/generateNamespaceCode.js +45 -24
  42. package/src/utils/generateNamespaceExportLines.js +16 -7
  43. package/src/utils/shouldIgnore.js +57 -37
  44. package/src/uuid.js +9 -7
  45. package/src/validateSchema.js +95 -77
  46. package/test/collectImports.js +8 -0
  47. package/test/css/some.css +3 -0
  48. package/test/css/some.js +5 -0
  49. package/test/ignoreFolder/ignoreMe.js +3 -1
  50. package/test/ignoreFolder/ignoreMe2.js +3 -1
  51. package/test/ignoreFolder2/ignoreMe.js +6 -2
  52. package/test/js/abc.test.js +7 -3
  53. package/test/js/some.js +5 -0
  54. package/test/secret.test.js +1 -1
  55. package/tests/clean/array.test.js +122 -74
  56. package/tests/clean/boolean.test.js +18 -6
  57. package/tests/clean/integer.test.js +25 -9
  58. package/tests/clean/number.test.js +49 -13
  59. package/tests/clean/object.test.js +190 -119
  60. package/tests/clean/string.test.js +48 -17
  61. package/tests/clean/timestamp.test.js +12 -5
  62. package/tests/clean/uuid.test.js +13 -6
  63. package/tests/collectImports.test.js +66 -0
  64. package/tests/combineFiles.test.js +28 -26
  65. package/tests/convertBytes.test.js +8 -3
  66. package/tests/env.test.js +9 -3
  67. package/tests/example.test.js +7 -3
  68. package/tests/fileList.test.js +16 -12
  69. package/tests/hash-and-encrypt.test.js +13 -4
  70. package/tests/md5.test.js +7 -2
  71. package/tests/uuid.test.js +10 -4
  72. package/tests/validateSchema.test.js +21 -9
  73. package/tsconfig.json +20 -16
  74. package/types/clean/array.d.ts +2 -1
  75. package/types/clean/boolean.d.ts +3 -3
  76. package/types/clean/integer.d.ts +6 -6
  77. package/types/clean/number.d.ts +8 -8
  78. package/types/clean/object.d.ts +2 -1
  79. package/types/clean/string.d.ts +8 -7
  80. package/types/clean/timestamp.d.ts +5 -5
  81. package/types/clean/uuid.d.ts +3 -3
  82. package/types/collectImports.d.ts +6 -0
  83. package/types/combineFiles.d.ts +5 -2
  84. package/types/each.d.ts +10 -10
  85. package/types/index.d.ts +117 -114
  86. package/types/thingType.d.ts +2 -2
  87. package/types/utils/clean.d.ts +19 -2
  88. package/types/validateSchema.d.ts +2 -2
@@ -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
 
@@ -1,72 +1,96 @@
1
1
  export default function cleanString(x, {
2
- required = false,
3
- minLength = false,
4
- maxLength = false,
5
- allowHtml = false,
6
- allowScripts = false,
7
- validValues = false
2
+ required = false,
3
+ minLength = false,
4
+ maxLength = false,
5
+ allowHtml = false,
6
+ allowScripts = false,
7
+ validValues = false
8
8
  } = {}){
9
9
 
10
- if(allowScripts && !allowHtml){ allowHtml = true; }
11
-
12
- try {
13
-
14
- if(typeof x !== 'string') {
15
- throw {
16
- name: 'TypeError',
17
- message: 'Input must be a string',
18
- value: x
19
- };
20
- }
21
-
22
- if(minLength !== false && x.length < minLength) {
23
- throw {
24
- message: `String length must be between ${minLength} `,
25
- length: x.length,
26
- value: x
27
- };
28
- }
29
-
30
- if(maxLength !== false && x.length > maxLength) {
31
- throw {
32
- message: `String length must be less than or equal to ${maxLength}`,
33
- length: x.length,
34
- value: x
35
- };
36
- }
37
-
38
- if(!allowHtml && /<[^>]*>/g.test(x)) {
39
- throw {
40
- message: 'HTML tags are not allowed',
41
- value: x
42
- };
43
- }
44
-
45
- if(!allowScripts && /<script[^>]*>.*<\/script>/g.test(x)) {
46
- throw {
47
- message: 'Script tags are not allowed',
48
- value: x
49
- };
50
- }
51
-
52
- if(
53
- validValues
54
- && Array.isArray(validValues)
55
- && !validValues.includes(x)
56
- ) {
57
- throw {
58
- message: `Value invalid`,
59
- validValues,
60
- value: x
61
- };
62
- }
63
-
64
- return x;
65
-
66
- } catch (e) {
67
-
68
- if(required) { throw e; } else { return null; }
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
  }
@@ -1,50 +1,66 @@
1
1
  export default function cleanTimestamp( isoDateTimeString , {
2
- required = false,
3
- maxDaysInFuture = false,
4
- maxDaysInFPast = false,
2
+ required = false,
3
+ maxDaysInFuture = false,
4
+ maxDaysInFPast = false,
5
5
  } = {}){
6
-
7
- try {
8
-
9
- if(typeof isoDateTimeString !== 'string') {
10
- throw {
11
- message: 'Input must be a string',
12
- isoDateTimeString
13
- };
14
- }
15
-
16
- const date = new Date(isoDateTimeString);
17
-
18
- if(isNaN(date.getTime())) {
19
- throw {
20
- message: 'Invalid date string',
21
- isoDateTimeString
22
- };
23
- }
24
-
25
- const now = new Date();
26
-
27
- if(maxDaysInFuture !== false && (date - now) > maxDaysInFuture * 24 * 60 * 60 * 1000) {
28
- throw {
29
- message: `Date is more than ${maxDaysInFuture} days in the future`,
30
- isoDateTimeString
31
- };
32
- }
33
-
34
- if(maxDaysInFPast !== false && (now - date) > maxDaysInFPast * 24 * 60 * 60 * 1000) {
35
- throw {
36
- message: `Date is more than ${maxDaysInFPast} days in the past`,
37
- value: isoDateTimeString
38
- };
39
- }
40
-
41
- return date.toISOString();
42
-
43
- } catch (e) {
44
-
45
- if(required) { throw e; } else { return null; }
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