@awesomeness-js/utils 1.0.24 → 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 (75) 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 +77 -74
  5. package/package.json +25 -25
  6. package/schemas/schema1.js +5 -1
  7. package/schemas/schema2.js +5 -1
  8. package/schemas.js +2 -2
  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/collectImports.d.ts +6 -0
  75. package/types/index.d.ts +3 -0
package/build/build.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import build from '../src/build.js';
2
2
 
3
3
  build({
4
- src: './src',
5
- dest: './index.js',
6
- dts: false,
7
- ignore: [
8
- 'ignoreMe.js',
9
- 'ignoreFolder/*',
10
- //'namespaceExample/*',
11
- ],
4
+ src: './src',
5
+ dest: './index.js',
6
+ dts: false,
7
+ ignore: [
8
+ 'ignoreMe.js',
9
+ 'ignoreFolder/*',
10
+ //'namespaceExample/*',
11
+ ],
12
12
  });
13
13
 
14
14
  build({
15
- src: './schemas',
16
- dest: './schemas.js',
17
- dts: false
15
+ src: './schemas',
16
+ dest: './schemas.js',
17
+ dts: false
18
18
  });
@@ -1,11 +1,11 @@
1
1
  import build from '../src/build.js';
2
2
  build({
3
- src: './src',
4
- dest: './types/index.d.ts',
5
- dts: true,
6
- ignore: [
7
- 'ignoreMe.js',
8
- 'ignoreFolder/*',
9
- //'namespaceExample/*',
10
- ],
3
+ src: './src',
4
+ dest: './types/index.d.ts',
5
+ dts: true,
6
+ ignore: [
7
+ 'ignoreMe.js',
8
+ 'ignoreFolder/*',
9
+ //'namespaceExample/*',
10
+ ],
11
11
  });
@@ -0,0 +1,90 @@
1
+ export default [
2
+ // Here is where we fix "padding-line-between-statements"
3
+ {
4
+ rules: {
5
+ 'padding-line-between-statements': [
6
+ 'error',
7
+ // Insert a blank line **before** any block-like statement
8
+ {
9
+ blankLine: 'always',
10
+ prev: '*',
11
+ next: 'block-like'
12
+ },
13
+ // Insert a blank line **after** any block-like statement
14
+ {
15
+ blankLine: 'always',
16
+ prev: 'block-like',
17
+ next: '*'
18
+ },
19
+ // Keep the rest of your rules here as needed...
20
+ {
21
+ blankLine: 'always',
22
+ prev: '*',
23
+ next: 'function'
24
+ },
25
+ {
26
+ blankLine: 'always',
27
+ prev: 'function',
28
+ next: '*'
29
+ },
30
+ {
31
+ blankLine: 'always',
32
+ prev: '*',
33
+ next: 'throw'
34
+ }
35
+ ],
36
+ 'padded-blocks': [
37
+ 'error',
38
+ {
39
+ blocks: 'always',
40
+ classes: 'always',
41
+ switches: 'always'
42
+ }
43
+ ],
44
+
45
+ "object-curly-newline": [
46
+ "error",
47
+ {
48
+ ObjectExpression: {
49
+ minProperties: 2, // If object has 2+ props, break into multiple lines
50
+ multiline: true,
51
+ consistent: true
52
+ },
53
+ // You can also configure ImportDeclaration, ExportDeclaration, etc.
54
+ ObjectPattern: {
55
+ multiline: true,
56
+ minProperties: 2,
57
+ consistent: true
58
+ },
59
+ ImportDeclaration: {
60
+ multiline: true,
61
+ minProperties: 2
62
+ },
63
+ ExportDeclaration: {
64
+ multiline: true,
65
+ minProperties: 2
66
+ }
67
+ }
68
+ ],
69
+
70
+ // 2) If the object is multiline, put each property on its own line
71
+ "object-property-newline": [
72
+ "error",
73
+ {
74
+ allowAllPropertiesOnSameLine: false
75
+ }
76
+ ],
77
+
78
+ indent: [ "error", "tab", { "SwitchCase": 1 } ],
79
+ semi: [ "error", "always" ],
80
+ "arrow-parens": [ "error", "always" ],
81
+ "object-curly-spacing": [ "error", "always" ],
82
+ "array-bracket-spacing": [ "error", "always" ],
83
+ 'lines-between-class-members': [ 'error', 'always' ],
84
+ 'newline-after-var': [ 'error', 'always' ],
85
+ 'newline-before-return': 'error',
86
+ 'brace-style': [ 'error', '1tbs', { allowSingleLine: false } ],
87
+ "no-unreachable": "off"
88
+ }
89
+ }
90
+ ];
package/index.js CHANGED
@@ -12,6 +12,7 @@ import _clean_object from './src/clean/object.js';
12
12
  import _clean_string from './src/clean/string.js';
13
13
  import _clean_timestamp from './src/clean/timestamp.js';
14
14
  import _clean_uuid from './src/clean/uuid.js';
15
+ import _collectImports from './src/collectImports.js';
15
16
  import _combineFiles from './src/combineFiles.js';
16
17
  import _convertBytes from './src/convertBytes.js';
17
18
  import _decrypt from './src/decrypt.js';
@@ -43,6 +44,7 @@ import _uuid from './src/uuid.js';
43
44
  import _validateSchema from './src/validateSchema.js';
44
45
 
45
46
  export { _build as build };
47
+ export { _collectImports as collectImports };
46
48
  export { _combineFiles as combineFiles };
47
49
  export { _convertBytes as convertBytes };
48
50
  export { _decrypt as decrypt };
@@ -60,78 +62,79 @@ export { _uuid as uuid };
60
62
  export { _validateSchema as validateSchema };
61
63
 
62
64
  export default {
63
- /**
64
- * Builds a file from the specified source directory and writes it to the destination file.
65
- *
66
- * @param {Object} options - The options for the build process.
67
- * @param {string} [options.src='./src'] - The source directory to build from.
68
- * @param {string} [options.dest='./index.js'] - The destination file to write the built content to.
69
- * @param {boolean} [options.exportRoots=true] - Whether to export root files.
70
- * @param {string[]} [options.ignore=[]] - An array of file patterns to ignore.
71
- * @param {boolean} [options.includeComments=true] - Whether to include comments in the generated file.
72
- * @param {boolean} [options.dts=false] - Whether to generate TypeScript declaration files.
73
- * @returns {Promise<boolean>} A promise that resolves to true when the build is complete.
74
- */
75
- build: _build,
76
- combineFiles: _combineFiles,
77
- /**
78
- * Converts a given number of bytes into a more readable string format with appropriate units.
79
- *
80
- * @param {number} bytes - The number of bytes to convert.
81
- * @param {number} [precision=2] - The number of decimal places to include in the result.
82
- * @returns {string} The converted bytes in a string format with appropriate units.
83
- */
84
- convertBytes: _convertBytes,
85
- decrypt: _decrypt,
86
- /**
87
- * Iterates over elements of an array or properties of an object, invoking a callback for each element/property.
88
- * The iteration stops if the callback returns `false`.
89
- *
90
- * @example each({ a: 1, b: 2 }, (value, key) => { console.log(value, key); });
91
- * @param {Object|Array} objectOrArray - The object or array to iterate over.
92
- * @param {Function} callback - The function to invoke per iteration. It is invoked with two arguments: (value, key/index).
93
- * @returns {void}
94
- */
95
- each: _each,
96
- eachAsync: _eachAsync,
97
- encrypt: _encrypt,
98
- getAllFiles: _getAllFiles,
99
- ignoreMe: _ignoreMe,
100
- isUUID: _isUUID,
101
- md5: _md5,
102
- setLocalEnvs: _setLocalEnvs,
103
- thingType: _thingType,
104
- toPennies: _toPennies,
105
- uuid: _uuid,
106
- validateSchema: _validateSchema,
107
- clean: {
108
- array: _clean_array,
109
- boolean: _clean_boolean,
110
- integer: _clean_integer,
111
- number: _clean_number,
112
- object: _clean_object,
113
- string: _clean_string,
114
- timestamp: _clean_timestamp,
115
- uuid: _clean_uuid,
116
- },
117
- ignoreFolder: {
118
- ignoreMe: _ignoreFolder_ignoreMe,
119
- },
120
- password: {
121
- check: _password_check,
122
- hash: _password_hash,
123
- },
124
- utils: {
125
- buildExportsTree: _utils_buildExportsTree,
126
- buildFileDataList: _utils_buildFileDataList,
127
- clean: _utils_clean,
128
- extractJSDocComment: _utils_extractJSDocComment,
129
- generateFile: _utils_generateFile,
130
- generateFlatExportLines: _utils_generateFlatExportLines,
131
- generateImportStatements: _utils_generateImportStatements,
132
- generateNamedExports: _utils_generateNamedExports,
133
- generateNamespaceCode: _utils_generateNamespaceCode,
134
- generateNamespaceExportLines: _utils_generateNamespaceExportLines,
135
- shouldIgnore: _utils_shouldIgnore,
136
- },
65
+ /**
66
+ * Builds a file from the specified source directory and writes it to the destination file.
67
+ *
68
+ * @param {Object} options - The options for the build process.
69
+ * @param {string} [options.src='./src'] - The source directory to build from.
70
+ * @param {string} [options.dest='./index.js'] - The destination file to write the built content to.
71
+ * @param {boolean} [options.exportRoots=true] - Whether to export root files.
72
+ * @param {string[]} [options.ignore=[]] - An array of file patterns to ignore.
73
+ * @param {boolean} [options.includeComments=true] - Whether to include comments in the generated file.
74
+ * @param {boolean} [options.dts=false] - Whether to generate TypeScript declaration files.
75
+ * @returns {Promise<boolean>} A promise that resolves to true when the build is complete.
76
+ */
77
+ build: _build,
78
+ collectImports: _collectImports,
79
+ combineFiles: _combineFiles,
80
+ /**
81
+ * Converts a given number of bytes into a more readable string format with appropriate units.
82
+ *
83
+ * @param {number} bytes - The number of bytes to convert.
84
+ * @param {number} [precision=2] - The number of decimal places to include in the result.
85
+ * @returns {string} The converted bytes in a string format with appropriate units.
86
+ */
87
+ convertBytes: _convertBytes,
88
+ decrypt: _decrypt,
89
+ /**
90
+ * Iterates over elements of an array or properties of an object, invoking a callback for each element/property.
91
+ * The iteration stops if the callback returns `false`.
92
+ *
93
+ * @example each({ a: 1, b: 2 }, (value, key) => { console.log(value, key); });
94
+ * @param {Object|Array} objectOrArray - The object or array to iterate over.
95
+ * @param {Function} callback - The function to invoke per iteration. It is invoked with two arguments: (value, key/index).
96
+ * @returns {void}
97
+ */
98
+ each: _each,
99
+ eachAsync: _eachAsync,
100
+ encrypt: _encrypt,
101
+ getAllFiles: _getAllFiles,
102
+ ignoreMe: _ignoreMe,
103
+ isUUID: _isUUID,
104
+ md5: _md5,
105
+ setLocalEnvs: _setLocalEnvs,
106
+ thingType: _thingType,
107
+ toPennies: _toPennies,
108
+ uuid: _uuid,
109
+ validateSchema: _validateSchema,
110
+ clean: {
111
+ array: _clean_array,
112
+ boolean: _clean_boolean,
113
+ integer: _clean_integer,
114
+ number: _clean_number,
115
+ object: _clean_object,
116
+ string: _clean_string,
117
+ timestamp: _clean_timestamp,
118
+ uuid: _clean_uuid,
119
+ },
120
+ ignoreFolder: {
121
+ ignoreMe: _ignoreFolder_ignoreMe,
122
+ },
123
+ password: {
124
+ check: _password_check,
125
+ hash: _password_hash,
126
+ },
127
+ utils: {
128
+ buildExportsTree: _utils_buildExportsTree,
129
+ buildFileDataList: _utils_buildFileDataList,
130
+ clean: _utils_clean,
131
+ extractJSDocComment: _utils_extractJSDocComment,
132
+ generateFile: _utils_generateFile,
133
+ generateFlatExportLines: _utils_generateFlatExportLines,
134
+ generateImportStatements: _utils_generateImportStatements,
135
+ generateNamedExports: _utils_generateNamedExports,
136
+ generateNamespaceCode: _utils_generateNamespaceCode,
137
+ generateNamespaceExportLines: _utils_generateNamespaceExportLines,
138
+ shouldIgnore: _utils_shouldIgnore,
139
+ },
137
140
  };
package/package.json CHANGED
@@ -1,26 +1,26 @@
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.0.25",
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
+ }
@@ -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
@@ -10,6 +10,6 @@ export { _schema1 as schema1 };
10
10
  export { _schema2 as schema2 };
11
11
 
12
12
  export default {
13
- schema1: _schema1,
14
- schema2: _schema2,
13
+ schema1: _schema1,
14
+ schema2: _schema2,
15
15
  };
package/src/build.js CHANGED
@@ -14,15 +14,19 @@ import { writeFileSync } from 'fs';
14
14
  import generateFile from './utils/generateFile.js';
15
15
 
16
16
  async function build({
17
- src = './src',
18
- dest = './index.js',
19
- exportRoots = true,
20
- ignore = [],
21
- includeComments = true,
22
- dts = false
17
+ src = './src',
18
+ dest = './index.js',
19
+ exportRoots = true,
20
+ ignore = [],
21
+ includeComments = true,
22
+ dts = false,
23
+ useTabs = true
23
24
  } = {}) {
24
- writeFileSync(dest, generateFile(src, exportRoots, ignore, includeComments, dts));
25
- return true;
25
+
26
+ writeFileSync(dest, generateFile(src, exportRoots, ignore, includeComments, dts, useTabs));
27
+
28
+ return true;
29
+
26
30
  }
27
31
 
28
32
  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