puvox-library 1.0.4 → 1.0.6

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 (2) hide show
  1. package/library_standard.js +42 -11
  2. package/package.json +1 -1
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  *
3
- * ################################################################################
4
- * ############################### Our JS Library ##############################
5
- * ##### Here we collect frequently used methods across our JS applications. #####
6
- * ##### (Some of them are generic javascript functions, some are for NodeJS) #####
7
- * ################################################################################
3
+ * ############################################################################
4
+ * ############################# Our JS Library ############################
5
+ * ### Here we collect frequently used methods across our JS applications. ###
6
+ * ### (Some of them are generic javascript functions, some are for NodeJS) ###
7
+ * ############################################################################
8
8
  *
9
9
  * ########## Example usage: ##########
10
10
  * const helpers = new PuvoxLibrary();
@@ -1287,6 +1287,14 @@ const puvox_library =
1287
1287
  return obj1;
1288
1288
  },
1289
1289
 
1290
+ // returns a new object with the values at each key mapped using mapFn(value)
1291
+ objectMap(obj, fn) {
1292
+ return Object.fromEntries(
1293
+ Object.entries(obj).map(
1294
+ ([k, v], i) => [k, fn(v, k, i)]
1295
+ )
1296
+ )
1297
+ },
1290
1298
 
1291
1299
  fancyTimeFormat(time)
1292
1300
  {
@@ -1473,7 +1481,7 @@ const puvox_library =
1473
1481
  },
1474
1482
 
1475
1483
  // https://stackoverflow.com/a/41407246/2377343
1476
- consoleLogColor (text, color, backgroundOrForeground = false) {
1484
+ consoleLogColor (text, backgroundColor=null, foregroundColor=null) {
1477
1485
  const prefix = '\x1b[';
1478
1486
  const suffix = 'm';
1479
1487
  const objectTree = {
@@ -1481,8 +1489,15 @@ const puvox_library =
1481
1489
  foreground: { black: "30", red: "31", green: "32", yellow: "33", blue: "34", magenta: "35", cyan: "36", white: "37", },
1482
1490
  background: { black: "40", red: "41", green: "42", yellow: "43", blue: "44", magenta: "45", cyan: "46", white: "47", }
1483
1491
  };
1484
- const bfKeyname = backgroundOrForeground ? 'background' : 'foreground';
1485
- console.log (prefix + objectTree[bfKeyname][color] + suffix + "%s" + prefix + objectTree.types.reset + suffix, text);
1492
+ let backColorString = '';
1493
+ let foreColorString = '';
1494
+ if (backgroundColor) {
1495
+ backColorString = prefix + objectTree['background'][backgroundColor] + suffix;
1496
+ }
1497
+ if (foregroundColor) {
1498
+ foreColorString = prefix + objectTree['foreground'][foregroundColor] + suffix;
1499
+ }
1500
+ console.log (backColorString + foreColorString + "%s" + prefix + objectTree.types.reset + suffix, text);
1486
1501
  },
1487
1502
 
1488
1503
  toggleWindowsMessages_WindowConfirm() { return window.confirm },
@@ -2633,9 +2648,16 @@ const puvox_library =
2633
2648
  return this._fs_instance;
2634
2649
  }
2635
2650
  },
2636
- async getRemoteData(url){
2651
+ async getRemoteData(url, postOptions = null, opts = {}){
2637
2652
  // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
2638
- return await (await fetch(url)).text();
2653
+ const options = {};
2654
+ if (postOptions) {
2655
+ options['method'] = 'POST';
2656
+ options['body'] = JSON.stringify(postOptions);
2657
+ }
2658
+ options['headers'] = ('headers' in opts) ? opts.headers : {'Content-Type': 'application/json'};
2659
+ const fetched = await fetch(url, options);
2660
+ return await (fetched).text();
2639
2661
  // return new Promise ((resolve, reject) => {
2640
2662
  // try {
2641
2663
  // // const https = require('https');
@@ -2655,7 +2677,7 @@ const puvox_library =
2655
2677
  }
2656
2678
  let jsonNew = self.jsonConcat(json, jsonContent);
2657
2679
  let content = JSON.stringify(jsonNew);
2658
- this.fs().writeFile(filePath, content, 'utf8', function(callback_) {
2680
+ self.fs().writeFile(filePath, content, 'utf8', function(callback_) {
2659
2681
  });
2660
2682
  });
2661
2683
  }
@@ -2663,6 +2685,15 @@ const puvox_library =
2663
2685
  console.log("writeFileAppendJson", e);
2664
2686
  }
2665
2687
  },
2688
+ getFilesListFromDir (dir) {
2689
+ const filesList = [];
2690
+ this.fs().readdirSync(dir, (err, files) => {
2691
+ files.forEach(file => {
2692
+ filesList.push(file);
2693
+ });
2694
+ });
2695
+ return filesList;
2696
+ },
2666
2697
  // if(setHashInAddress) { window.location.hash = id_or_Name; }
2667
2698
 
2668
2699
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puvox-library",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "library-class-javascript",
5
5
  "main": "library_standard.js",
6
6
  "scripts": {