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