puvox-library 1.0.7 → 1.0.10
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/library_standard.js +154 -109
- package/npm_unpublish.bat +5 -0
- package/package.json +1 -1
package/library_standard.js
CHANGED
@@ -20,14 +20,13 @@ const puvox_library =
|
|
20
20
|
arrayValue(obj_arr, key, default_){
|
21
21
|
return (key in obj_arr ? obj_arr[key] : default_);
|
22
22
|
},
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
else return ( case_ ? val.toUpperCase() : val.toLowerCase() );
|
23
|
+
arrayValueLower(obj_arr, key, default_){
|
24
|
+
const val = this.arrayValue(obj_arr, key, default_);
|
25
|
+
return (val===null ? null : val.toLowerCase());
|
27
26
|
},
|
28
|
-
|
29
|
-
|
30
|
-
return (
|
27
|
+
arrayValueUpper(obj_arr, key, default_){
|
28
|
+
const val = this.arrayValue(obj_arr, key, default_);
|
29
|
+
return (val===null ? null : val.toUpperCase());
|
31
30
|
},
|
32
31
|
stringToArray(str, splitChar){
|
33
32
|
var splitChar= splitChar || '|';
|
@@ -2648,7 +2647,8 @@ const puvox_library =
|
|
2648
2647
|
}
|
2649
2648
|
options['headers'] = ('headers' in opts) ? opts.headers : {'Content-Type': 'application/json'};
|
2650
2649
|
const fetched = await fetch(url, options);
|
2651
|
-
|
2650
|
+
const text = (await (fetched).text());
|
2651
|
+
return text;
|
2652
2652
|
// return new Promise ((resolve, reject) => {
|
2653
2653
|
// try {
|
2654
2654
|
// // const https = require('https');
|
@@ -2665,25 +2665,152 @@ const puvox_library =
|
|
2665
2665
|
|
2666
2666
|
|
2667
2667
|
// ######## CACHE ITEMS (client-side JS) ########
|
2668
|
-
|
2669
|
-
|
2670
|
-
|
2671
|
-
|
2672
|
-
|
2673
|
-
|
2674
|
-
|
2675
|
-
|
2676
|
-
|
2677
|
-
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2681
|
-
|
2682
|
-
|
2683
|
-
|
2684
|
-
|
2685
|
-
|
2686
|
-
|
2668
|
+
AppName : 'puvox_', //override with anything you want
|
2669
|
+
setAppName (name){ this.AppName = name; },
|
2670
|
+
|
2671
|
+
cache : {
|
2672
|
+
localStorage : {
|
2673
|
+
parent(){ return puvox_library; },
|
2674
|
+
AppName(){ return puvox_library.AppName; },
|
2675
|
+
|
2676
|
+
storage: typeof window !== 'undefined' ? window.localStorage : null,
|
2677
|
+
|
2678
|
+
get(name, defaultValue, expireSeconds = 0){
|
2679
|
+
let appName = this.AppName();
|
2680
|
+
let val = this.storage.getItem(appName + '_' + name);
|
2681
|
+
let expireVal = this.storage.getItem(appName + '_createtime_' + name);
|
2682
|
+
if (val === null) {
|
2683
|
+
return defaultValue;
|
2684
|
+
} else {
|
2685
|
+
if (expireSeconds === 0){
|
2686
|
+
return val;
|
2687
|
+
} else {
|
2688
|
+
let now = (new Date()).getTime();
|
2689
|
+
if (now - expireVal > expireSeconds*1000){
|
2690
|
+
this.storage.removeItem(appName + '_' + name);
|
2691
|
+
this.storage.removeItem(appName + '_createtime_' + name);
|
2692
|
+
return defaultValue;
|
2693
|
+
}
|
2694
|
+
}
|
2695
|
+
}
|
2696
|
+
},
|
2697
|
+
set(name, value){
|
2698
|
+
try{
|
2699
|
+
this.storage.setItem(this.AppName() + '_' +name, value);
|
2700
|
+
this.storage.setItem(this.AppName() + '_createtime_' +name, (new Date()).getTime());
|
2701
|
+
return true;
|
2702
|
+
}
|
2703
|
+
catch(ex){ alert("Cache storage quote exceeded. can't save value. err598"); return false; }
|
2704
|
+
},
|
2705
|
+
remove(name, value){
|
2706
|
+
this.storage.removeItem(this.AppName() + '_' +name);
|
2707
|
+
this.storage.removeItem(this.AppName() + '_createtime_' +name);
|
2708
|
+
},
|
2709
|
+
getItem(name, subItemName, defaultValue){
|
2710
|
+
let val = this.get(name, '{}');
|
2711
|
+
let parsed = JSON.parse(val);
|
2712
|
+
return (subItemName in parsed ? parsed[subItemName] : defaultValue);
|
2713
|
+
},
|
2714
|
+
setItem(name, subItemName, value){
|
2715
|
+
let curr = this.get(name, '{}' );
|
2716
|
+
let parsed = JSON.parse(curr);
|
2717
|
+
parsed[subItemName] = value;
|
2718
|
+
return this.set(name, JSON.stringify(parsed) );
|
2719
|
+
},
|
2720
|
+
removeItem(name, subItemName, value){
|
2721
|
+
let curr = this.get(name, '{}' );
|
2722
|
+
let parsed = JSON.parse(curr);
|
2723
|
+
if (subItemName in parsed)
|
2724
|
+
delete parsed[subItemName];
|
2725
|
+
return this.set(name, JSON.stringify(parsed) );
|
2726
|
+
}
|
2727
|
+
},
|
2728
|
+
file : {
|
2729
|
+
// ########## CACHE DIRS (server-side JS) ##########
|
2730
|
+
parent(){ return puvox_library; },
|
2731
|
+
AppName(){ return puvox_library.AppName; },
|
2732
|
+
|
2733
|
+
customCacheDir:null,
|
2734
|
+
dirPath(){
|
2735
|
+
if (!this.customCacheDir){
|
2736
|
+
this.customCacheDir = this.parent().file.getTempDir() + '/';
|
2737
|
+
}
|
2738
|
+
let finaldir = this.customCacheDir + '_cache' + this.AppName() + '/';
|
2739
|
+
return finaldir;
|
2740
|
+
},
|
2741
|
+
filePath(uniqFileName){
|
2742
|
+
const parent = this.parent();
|
2743
|
+
uniqFileName = parent.isString(uniqFileName) || parent.isNumeric(uniqFileName) ? uniqFileName : JSON.stringify(uniqFileName);
|
2744
|
+
uniqFileName = parent.sanitize_key_dashed(parent.getCharsFromStart(uniqFileName, 15)) + "_"+ parent.md5(uniqFileName);
|
2745
|
+
filePath= this.dirPath() + uniqFileName + "_tmp"; //"/".
|
2746
|
+
return filePath;
|
2747
|
+
},
|
2748
|
+
//
|
2749
|
+
get(uniqFileName, defaultContent ='', expire_seconds=8640000, decode = true)
|
2750
|
+
{
|
2751
|
+
const parent = this.parent();
|
2752
|
+
let filePath = this.filePath(uniqFileName);
|
2753
|
+
if ( filePath.length < 3) return "too tiny filename";
|
2754
|
+
|
2755
|
+
if ( parent.file.exists(filePath) ){
|
2756
|
+
if ( parent.file.mtime(filePath) + expire_seconds *1000 < (new Date()).getTime() ){
|
2757
|
+
parent.file.unlink(filePath);
|
2758
|
+
return defaultContent;
|
2759
|
+
}
|
2760
|
+
else{
|
2761
|
+
cont = parent.file.read(filePath, null);
|
2762
|
+
// if specifically array, then on empty, reckon as array
|
2763
|
+
if (cont===null)
|
2764
|
+
{
|
2765
|
+
return defaultContent;
|
2766
|
+
}
|
2767
|
+
if (decode){
|
2768
|
+
try{
|
2769
|
+
return JSON.parse(cont);
|
2770
|
+
}
|
2771
|
+
catch(ex){
|
2772
|
+
return cont;
|
2773
|
+
}
|
2774
|
+
}
|
2775
|
+
else{
|
2776
|
+
return cont;
|
2777
|
+
}
|
2778
|
+
}
|
2779
|
+
}
|
2780
|
+
else {
|
2781
|
+
return defaultContent;
|
2782
|
+
}
|
2783
|
+
},
|
2784
|
+
set(uniqFileName, content)
|
2785
|
+
{
|
2786
|
+
const parent = this.parent();
|
2787
|
+
let filePath= this.filePath(uniqFileName);
|
2788
|
+
let contentFinal = parent.isString(content) ? content : ((parent.isArray(content) || parent.isObject(content)) ? JSON.stringify(content) : content);
|
2789
|
+
return parent.file.write(filePath, contentFinal);
|
2790
|
+
},
|
2791
|
+
|
2792
|
+
//
|
2793
|
+
// writeFileAppendJson(filePath, jsonContent, callback){
|
2794
|
+
// try{
|
2795
|
+
// var callback = callback || function(){};
|
2796
|
+
// var self = this;
|
2797
|
+
// puvox_library.modules('fs').readFile(filePath, 'utf8', function(err,data) {
|
2798
|
+
// let json = {};
|
2799
|
+
// if (typeof data !="undefined" && data!=''){
|
2800
|
+
// json=JSON.parse(data);
|
2801
|
+
// }
|
2802
|
+
// let jsonNew = self.jsonConcat(json, jsonContent);
|
2803
|
+
// let content = JSON.stringify(jsonNew);
|
2804
|
+
// puvox_library.modules('fs').writeFile(filePath, content, 'utf8', function(callback_) {
|
2805
|
+
// });
|
2806
|
+
// });
|
2807
|
+
// }
|
2808
|
+
// catch(e){
|
2809
|
+
// console.log("writeFileAppendJson", e);
|
2810
|
+
// }
|
2811
|
+
// },
|
2812
|
+
}
|
2813
|
+
},
|
2687
2814
|
|
2688
2815
|
// ################################################
|
2689
2816
|
// for node packs:_fs_instance :null,
|
@@ -2744,88 +2871,6 @@ const puvox_library =
|
|
2744
2871
|
});
|
2745
2872
|
return filesList;
|
2746
2873
|
},
|
2747
|
-
|
2748
|
-
|
2749
|
-
// ########## CACHE DIRS (server-side JS) ##########
|
2750
|
-
customCacheDir:null,
|
2751
|
-
cacheDirGet(appName = ''){
|
2752
|
-
if (!this.customCacheDir){
|
2753
|
-
this.customCacheDir = this.getTempDir() + '/_cache_dir_px/';
|
2754
|
-
}
|
2755
|
-
let finaldir = this.customCacheDir + appName + '/';
|
2756
|
-
return finaldir;
|
2757
|
-
},
|
2758
|
-
cacheFilePath(uniqFileName){
|
2759
|
-
const parent = this.parent();
|
2760
|
-
uniqFileName = parent.isString(uniqFileName) || parent.isNumeric(uniqFileName) ? uniqFileName : JSON.stringify(uniqFileName);
|
2761
|
-
uniqFileName = parent.sanitize_key_dashed(parent.getCharsFromStart(uniqFileName, 15)) + "_"+ parent.md5(uniqFileName);
|
2762
|
-
filePath= this.cacheDirGet() + uniqFileName + "_tmp"; //"/".
|
2763
|
-
return filePath;
|
2764
|
-
},
|
2765
|
-
//
|
2766
|
-
cacheGet(uniqFileName, defaultContent ='', expire_seconds=8640000, decode = true)
|
2767
|
-
{
|
2768
|
-
let filePath = this.cacheFilePath(uniqFileName);
|
2769
|
-
if ( filePath.length < 3) return "too tiny filename";
|
2770
|
-
|
2771
|
-
if ( this.exists(filePath) ){
|
2772
|
-
if ( this.mtime(filePath) + expire_seconds *1000 < (new Date()).getTime() ){
|
2773
|
-
this.unlink(filePath);
|
2774
|
-
return defaultContent;
|
2775
|
-
}
|
2776
|
-
else{
|
2777
|
-
cont = this.read(filePath, null);
|
2778
|
-
// if specifically array, then on empty, reckon as array
|
2779
|
-
if (cont===null)
|
2780
|
-
{
|
2781
|
-
return defaultContent;
|
2782
|
-
}
|
2783
|
-
if (decode){
|
2784
|
-
try{
|
2785
|
-
return JSON.parse(cont);
|
2786
|
-
}
|
2787
|
-
catch(ex){
|
2788
|
-
return cont;
|
2789
|
-
}
|
2790
|
-
}
|
2791
|
-
else{
|
2792
|
-
return cont;
|
2793
|
-
}
|
2794
|
-
}
|
2795
|
-
}
|
2796
|
-
else {
|
2797
|
-
return defaultContent;
|
2798
|
-
}
|
2799
|
-
},
|
2800
|
-
cacheSet(uniqFileName, content, encode=true)
|
2801
|
-
{
|
2802
|
-
const parent = this.parent();
|
2803
|
-
let filePath= this.cacheFilePath(uniqFileName);
|
2804
|
-
let contentFinal = (encode && (parent.isArray(content) || parent.isObject(content)) ) ? JSON.stringify(content) : content;
|
2805
|
-
return this.write(filePath, contentFinal);
|
2806
|
-
},
|
2807
|
-
|
2808
|
-
//
|
2809
|
-
// writeFileAppendJson(filePath, jsonContent, callback){
|
2810
|
-
// try{
|
2811
|
-
// var callback = callback || function(){};
|
2812
|
-
// var self = this;
|
2813
|
-
// puvox_library.modules('fs').readFile(filePath, 'utf8', function(err,data) {
|
2814
|
-
// let json = {};
|
2815
|
-
// if (typeof data !="undefined" && data!=''){
|
2816
|
-
// json=JSON.parse(data);
|
2817
|
-
// }
|
2818
|
-
// let jsonNew = self.jsonConcat(json, jsonContent);
|
2819
|
-
// let content = JSON.stringify(jsonNew);
|
2820
|
-
// puvox_library.modules('fs').writeFile(filePath, content, 'utf8', function(callback_) {
|
2821
|
-
// });
|
2822
|
-
// });
|
2823
|
-
// }
|
2824
|
-
// catch(e){
|
2825
|
-
// console.log("writeFileAppendJson", e);
|
2826
|
-
// }
|
2827
|
-
// },
|
2828
|
-
|
2829
2874
|
},
|
2830
2875
|
};
|
2831
2876
|
|