puvox-library 1.0.25 → 1.0.27

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 +67 -45
  2. package/package.json +1 -1
@@ -229,7 +229,7 @@ const puvox_library =
229
229
  );
230
230
  },
231
231
 
232
- move_to_top_in_parent (el_tag)
232
+ move_to_top_in_parent(el_tag)
233
233
  {
234
234
  $(el_tag).each(function() {
235
235
  $(this).parent().prepend(this);
@@ -804,7 +804,7 @@ const puvox_library =
804
804
  },
805
805
 
806
806
 
807
- dateUtils : {
807
+ datetime : {
808
808
  // 0940 type time-ints
809
809
  isBetweenHMS(target, start, end, equality) { }, // datetime, int/datetime, int/datetime, bool
810
810
  equalDays(d1,d2) {
@@ -1969,16 +1969,16 @@ const puvox_library =
1969
1969
  parsePOST(request, callback)
1970
1970
  {
1971
1971
  if (request.method == 'POST') {
1972
- let name='querystring';
1973
- var qs = require(name);
1974
- let stringData = '';
1975
- request.on('data', function (data) {
1976
- stringData += data;
1977
- // Too much POST data, kill the connection! 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
1978
- if (stringData.length > 1e6)
1979
- request.connection.destroy();
1980
- });
1981
- request.on('end', function(){ callback(qs.parse(stringData)); } );
1972
+ // let name='querystring';// deprecated by URLSearchParams
1973
+ // var qs = require(name);
1974
+ // let stringData = '';
1975
+ // request.on('data', function (data) {
1976
+ // stringData += data;
1977
+ // // Too much POST data, kill the connection! 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
1978
+ // if (stringData.length > 1e6)
1979
+ // request.connection.destroy();
1980
+ // });
1981
+ // request.on('end', function(){ callback(qs.parse(stringData)); } );
1982
1982
  }
1983
1983
  },
1984
1984
 
@@ -2417,6 +2417,14 @@ const puvox_library =
2417
2417
  else if (operator === '<=') return a <= b;
2418
2418
  else throw "Unknown operator";
2419
2419
  },
2420
+ calculate(a, b, operator) {
2421
+ if(operator === '+') return a + b;
2422
+ else if (operator === '-') return a - b;
2423
+ else if (operator === '*') return a * b;
2424
+ else if (operator === '/') return a / b;
2425
+ else if (operator === '%') return a % b;
2426
+ else throw "Unknown operator";
2427
+ },
2420
2428
 
2421
2429
  // random NUMBER or STRINGS
2422
2430
  RandomNum(maxNum) { return Math.floor((Math.random() * maxNum) + 1); },
@@ -2544,8 +2552,7 @@ const puvox_library =
2544
2552
  openUrlInBrowser(url)
2545
2553
  {
2546
2554
  var cmd = (process.platform == 'darwin'? `open ${url}`: process.platform == 'win32'? `start ${url}`: `xdg-open ${url}`);
2547
- let name='child_process';
2548
- require(name).exec(cmd);
2555
+ require('child_process').exec(cmd);
2549
2556
  },
2550
2557
 
2551
2558
  stringify(obj_or_str){
@@ -2704,17 +2711,24 @@ const puvox_library =
2704
2711
  },
2705
2712
  // if(setHashInAddress) { window.location.hash = id_or_Name; }
2706
2713
 
2707
-
2708
-
2714
+ unTrailingSlash(str){
2715
+ while (str.endsWith('/') || str.endsWith('\\')) {
2716
+ str = str.slice(0, -1);
2717
+ }
2718
+ return str;
2719
+ },
2720
+ trailingSlash(str){
2721
+ return this.unTrailingSlash(str) + '/';
2722
+ },
2709
2723
 
2710
2724
  // ######## CACHE ITEMS (client-side JS) ########
2711
- _privateAppName : null, //override with anything you want
2712
- setAppName (name){ this._privateAppName = name; },
2725
+ privateAppName__ : null, //override with anything you want
2726
+ setAppName (name){ this.privateAppName__ = name; },
2713
2727
  getAppName(){
2714
- if (!this._privateAppName || this._privateAppName === ''){
2728
+ if (!this.privateAppName__){
2715
2729
  throw new Error ('Before you start using caching functions, please at first define your appplication\'s name(identifier) at first with .setAppName("whatever_my_app_name"), so it will get its own cache-storage');
2716
2730
  }
2717
- return this._privateAppName;
2731
+ return this.privateAppName__;
2718
2732
  },
2719
2733
 
2720
2734
  cache: {
@@ -2776,18 +2790,28 @@ const puvox_library =
2776
2790
  file: {
2777
2791
  // ########## CACHE DIRS (server-side JS) ##########
2778
2792
  customCacheDir:null,
2779
- dir(){
2793
+ get_dir(){
2780
2794
  if (!this.customCacheDir){
2781
- this.customCacheDir = puvox_library.file.getTempDir() + '/';
2795
+ this.customCacheDir = puvox_library.file.tempDir();
2782
2796
  }
2783
- let finaldir = this.customCacheDir + '_cache_' + puvox_library.getAppName() + '/';
2797
+ let finaldir = puvox_library.trailingSlash(this.customCacheDir + '_cache_' + puvox_library.getAppName());
2784
2798
  return finaldir;
2785
2799
  },
2800
+ set_dir(dir, auto_clear_seconds=null){
2801
+ if(dir) this.customCacheDir = dir;
2802
+ const res = puvox_library.file.createDirectory(this.customCacheDir);
2803
+ if( !is_null(auto_clear_seconds))
2804
+ {
2805
+ throw new Error("Not implemented yet! 345346");
2806
+ //$this->clearCacheDir($auto_clear_seconds);
2807
+ }
2808
+ return res;
2809
+ },
2786
2810
  filePath(uniqFileName){
2787
2811
  const parent = puvox_library;
2788
2812
  uniqFileName = parent.isString(uniqFileName) || parent.isNumeric(uniqFileName) ? uniqFileName : JSON.stringify(uniqFileName);
2789
2813
  uniqFileName = parent.sanitize_key_dashed(parent.getCharsFromStart(uniqFileName, 15)) + "_"+ parent.md5(uniqFileName);
2790
- filePath= this.dir() + uniqFileName + "_tmp"; //"/".
2814
+ filePath= this.get_dir() + uniqFileName + "_tmp"; //"/".
2791
2815
  return filePath;
2792
2816
  },
2793
2817
  //
@@ -2795,8 +2819,6 @@ const puvox_library =
2795
2819
  {
2796
2820
  const parent = puvox_library;
2797
2821
  let filePath = this.filePath(uniqFileName);
2798
- if ( filePath.length < 3) return "too tiny filename";
2799
-
2800
2822
  if ( parent.file.exists(filePath) ){
2801
2823
  if ( parent.file.mtime(filePath) + expire_seconds *1000 < (new Date()).getTime() ){
2802
2824
  parent.file.unlink(filePath);
@@ -2864,14 +2886,14 @@ const puvox_library =
2864
2886
  },
2865
2887
  getIds(containerSlug) {
2866
2888
  if (! (containerSlug in this.tempIds)) {
2867
- const content = puvox_library.file.read(this.dir() + this.containerDefaultPrefix + containerSlug, '{}');
2889
+ const content = puvox_library.file.read(this.get_dir() + this.containerDefaultPrefix + containerSlug, '{}');
2868
2890
  this.tempIds[containerSlug] = JSON.parse(content);
2869
2891
  }
2870
2892
  return this.tempIds[containerSlug];
2871
2893
  },
2872
2894
  setIds(containerSlug, idsDict) {
2873
2895
  this.tempIds[containerSlug] = idsDict;
2874
- return puvox_library.file.write(this.dir() + this.containerDefaultPrefix + containerSlug, JSON.stringify(this.tempIds[containerSlug]));
2896
+ return puvox_library.file.write(this.get_dir() + this.containerDefaultPrefix + containerSlug, JSON.stringify(this.tempIds[containerSlug]));
2875
2897
  },
2876
2898
  addId(containerSlug, id){
2877
2899
  const ids = this.getIds(containerSlug);
@@ -2890,22 +2912,21 @@ const puvox_library =
2890
2912
 
2891
2913
  // ################################################
2892
2914
  // for node packs:_fs_instance :null,
2893
- _required_instances : {},
2894
- modules(name){
2895
- if (name in this._required_instances){
2896
- return this._required_instances[name];
2897
- } else {
2898
- this._required_instances[name] = require(name);
2899
- return this._required_instances[name];
2900
- }
2901
- },
2915
+ // _required_instances : {},
2916
+ // modules(name){
2917
+ // if (name in this._required_instances){
2918
+ // return this._required_instances[name];
2919
+ // } else {
2920
+ // this._required_instances[name] = require(name);
2921
+ // return this._required_instances[name];
2922
+ // }
2923
+ // },
2902
2924
  file: {
2903
- parent() {return puvox_library;},
2904
- fs() {return puvox_library.modules('fs');},
2905
- os() {return puvox_library.modules('os');},
2906
- path() {return puvox_library.modules('path');},
2925
+ fs() {return require('fs');}, //puvox_library.modules('fs')
2926
+ os() {return require('os');},
2927
+ path() {return require('path');},
2907
2928
  //
2908
- getTempDir(){ return this.os().tmpdir(); },
2929
+ tempDir(){ return puvox_library.trailingSlash(this.os().tmpdir()); },
2909
2930
 
2910
2931
  exists(filePath){
2911
2932
  return this.fs().existsSync(filePath);
@@ -2920,10 +2941,11 @@ const puvox_library =
2920
2941
  unlink(filePath){
2921
2942
  return (this.fs().unlinkSync(filePath));
2922
2943
  },
2923
- createDirectory(dirPath, force = false){
2924
- if (!this.exists(dirPath) || force){
2925
- this.fs().mkdirSync(dirPath, { recursive: true });
2944
+ createDirectory(dirPath){
2945
+ if (!this.exists(dirPath)){
2946
+ return this.fs().mkdirSync(dirPath, { recursive: true });
2926
2947
  }
2948
+ return true;
2927
2949
  },
2928
2950
  read(filePath, defaultContent = ''){
2929
2951
  if (!this.exists(filePath)){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puvox-library",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "library-class-javascript",
5
5
  "main": "library_standard.js",
6
6
  "scripts": {