@awesomeness-js/utils 1.0.2 → 1.0.4

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/index.js CHANGED
@@ -5,14 +5,16 @@
5
5
  */
6
6
  import _build from './src/build.js';
7
7
 
8
+ export { _build as build };
9
+
8
10
  export default {
9
- /**
10
- * Generates a output file that consolidates all src functions.
11
- *
12
- * @param {Object} [options] - The options for generating the output file.
13
- * @param {string} [options.src='./src'] - The source directory.
14
- * @param {array} [options.dest=['./', 'index.js']] - The destination file.
15
- * @returns {bool} - Returns true if the output file is generated successfully.
11
+ /**
12
+ * Generates a output file that consolidates all src functions.
13
+ *
14
+ * @param {Object} [options] - The options for generating the output file.
15
+ * @param {string} [options.src='./src'] - The source directory.
16
+ * @param {array} [options.dest=['./', 'index.js']] - The destination file.
17
+ * @returns {bool} - Returns true if the output file is generated successfully.
16
18
  */
17
19
  build: _build
18
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomeness-js/utils",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Awesomeness - Utils",
5
5
  "repository": {
6
6
  "type": "git",
package/src/build.js CHANGED
@@ -70,6 +70,7 @@ function generateExports(src) {
70
70
  allFiles.push(...fnFiles);
71
71
 
72
72
  let imports = '';
73
+ let allExports = '';
73
74
  let apiObject = {};
74
75
 
75
76
  let allComments = {};
@@ -94,6 +95,9 @@ function generateExports(src) {
94
95
  // Generate import statement with JSDoc comment if available
95
96
  imports += `import ${namespace}_${functionName} from '${importPath}.js';\n`;
96
97
 
98
+ // generate exports
99
+ if(!namespace){ allExports += `export { _${functionName} as ${functionName} };\n`; }
100
+
97
101
  // Populate the API object structure
98
102
  let current = apiObject;
99
103
  for (const part of parts) {
@@ -113,7 +117,7 @@ function generateExports(src) {
113
117
  */
114
118
  `;
115
119
 
116
- return headerComment + imports + '\n' + apiContent;
120
+ return headerComment + imports + '\n' + allExports + '\n' + apiContent;
117
121
  }
118
122
 
119
123
 
@@ -0,0 +1,8 @@
1
+ export default function convertBytes(bytes, precision = 2) {
2
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
3
+ bytes = Math.max(bytes, 0);
4
+ const pow = Math.floor((bytes ? Math.log(bytes) : 0) / Math.log(1024));
5
+ const index = Math.min(pow, units.length - 1);
6
+ bytes /= 2 ** (10 * pow);
7
+ return `${bytes.toFixed(precision)} ${units[index]}`;
8
+ };
package/src/each.js ADDED
@@ -0,0 +1,17 @@
1
+ export default function each(objectOrArray, callback) {
2
+
3
+ if(Array.isArray(objectOrArray)){
4
+
5
+ objectOrArray.every( (v, k) => {
6
+ if(callback( v, k ) === false){ return false; } else { return true; }
7
+ });
8
+
9
+ } else {
10
+
11
+ Object.entries(objectOrArray).every(entry => {
12
+ if(callback( entry[1], entry[0] ) === false){ return false; } else { return true; }
13
+ });
14
+
15
+ }
16
+
17
+ };
@@ -0,0 +1,21 @@
1
+ export default async function eachAsync(objectOrArray, callback) {
2
+ if (Array.isArray(objectOrArray)) {
3
+ // Use a for...of loop for arrays
4
+ for (const [k, v] of objectOrArray.entries()) {
5
+ // Await the callback
6
+ if (await callback(v, k) === false) {
7
+ break;
8
+ }
9
+ }
10
+ } else {
11
+ // Use a for...in loop for objects
12
+ for (const k in objectOrArray) {
13
+ if (objectOrArray.hasOwnProperty(k)) {
14
+ // Await the callback
15
+ if (await callback(objectOrArray[k], k) === false) {
16
+ break;
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,19 @@
1
+ export default function toPennies(uglyMoney){
2
+
3
+ if(!uglyMoney){ return 0; }
4
+ if(uglyMoney.length == 0){ return 0; }
5
+
6
+ // trim all whitespace from string
7
+ uglyMoney = uglyMoney.replace(/\s/g,'');
8
+
9
+ let hasDecimal = uglyMoney.includes(".");
10
+ let cleanMoney_v1 = uglyMoney.replace(/\D/g,'');
11
+
12
+ if(cleanMoney_v1.length == 0){ return 0; }
13
+
14
+ let cleanMoney = cleanMoney_v1*1;
15
+
16
+ if(!hasDecimal){ cleanMoney = cleanMoney * 100; }
17
+
18
+ return cleanMoney;
19
+ };