puvox-library 1.0.40 → 1.0.43
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
CHANGED
@@ -2469,7 +2469,9 @@ const puvox_library =
|
|
2469
2469
|
arrayRemoveValue(array, value) {
|
2470
2470
|
const newArray = [...array];
|
2471
2471
|
const index = newArray.indexOf(value);
|
2472
|
-
|
2472
|
+
if (index > -1){
|
2473
|
+
newArray.splice(index, 1);
|
2474
|
+
}
|
2473
2475
|
return newArray;
|
2474
2476
|
},
|
2475
2477
|
|
@@ -2737,75 +2739,6 @@ const puvox_library =
|
|
2737
2739
|
md5(str){var md5cycle=function(x,k){var a=x[0],b=x[1],c=x[2],d=x[3];a=ff(a,b,c,d,k[0],7,-680876936);d=ff(d,a,b,c,k[1],12,-389564586);c=ff(c,d,a,b,k[2],17,606105819);b=ff(b,c,d,a,k[3],22,-1044525330);a=ff(a,b,c,d,k[4],7,-176418897);d=ff(d,a,b,c,k[5],12,1200080426);c=ff(c,d,a,b,k[6],17,-1473231341);b=ff(b,c,d,a,k[7],22,-45705983);a=ff(a,b,c,d,k[8],7,1770035416);d=ff(d,a,b,c,k[9],12,-1958414417);c=ff(c,d,a,b,k[10],17,-42063);b=ff(b,c,d,a,k[11],22,-1990404162);a=ff(a,b,c,d,k[12],7,1804603682);d=ff(d,a,b,c,k[13],12,-40341101);c=ff(c,d,a,b,k[14],17,-1502002290);b=ff(b,c,d,a,k[15],22,1236535329);a=gg(a,b,c,d,k[1],5,-165796510);d=gg(d,a,b,c,k[6],9,-1069501632);c=gg(c,d,a,b,k[11],14,643717713);b=gg(b,c,d,a,k[0],20,-373897302);a=gg(a,b,c,d,k[5],5,-701558691);d=gg(d,a,b,c,k[10],9,38016083);c=gg(c,d,a,b,k[15],14,-660478335);b=gg(b,c,d,a,k[4],20,-405537848);a=gg(a,b,c,d,k[9],5,568446438);d=gg(d,a,b,c,k[14],9,-1019803690);c=gg(c,d,a,b,k[3],14,-187363961);b=gg(b,c,d,a,k[8],20,1163531501);a=gg(a,b,c,d,k[13],5,-1444681467);d=gg(d,a,b,c,k[2],9,-51403784);c=gg(c,d,a,b,k[7],14,1735328473);b=gg(b,c,d,a,k[12],20,-1926607734);a=hh(a,b,c,d,k[5],4,-378558);d=hh(d,a,b,c,k[8],11,-2022574463);c=hh(c,d,a,b,k[11],16,1839030562);b=hh(b,c,d,a,k[14],23,-35309556);a=hh(a,b,c,d,k[1],4,-1530992060);d=hh(d,a,b,c,k[4],11,1272893353);c=hh(c,d,a,b,k[7],16,-155497632);b=hh(b,c,d,a,k[10],23,-1094730640);a=hh(a,b,c,d,k[13],4,681279174);d=hh(d,a,b,c,k[0],11,-358537222);c=hh(c,d,a,b,k[3],16,-722521979);b=hh(b,c,d,a,k[6],23,76029189);a=hh(a,b,c,d,k[9],4,-640364487);d=hh(d,a,b,c,k[12],11,-421815835);c=hh(c,d,a,b,k[15],16,530742520);b=hh(b,c,d,a,k[2],23,-995338651);a=ii(a,b,c,d,k[0],6,-198630844);d=ii(d,a,b,c,k[7],10,1126891415);c=ii(c,d,a,b,k[14],15,-1416354905);b=ii(b,c,d,a,k[5],21,-57434055);a=ii(a,b,c,d,k[12],6,1700485571);d=ii(d,a,b,c,k[3],10,-1894986606);c=ii(c,d,a,b,k[10],15,-1051523);b=ii(b,c,d,a,k[1],21,-2054922799);a=ii(a,b,c,d,k[8],6,1873313359);d=ii(d,a,b,c,k[15],10,-30611744);c=ii(c,d,a,b,k[6],15,-1560198380);b=ii(b,c,d,a,k[13],21,1309151649);a=ii(a,b,c,d,k[4],6,-145523070);d=ii(d,a,b,c,k[11],10,-1120210379);c=ii(c,d,a,b,k[2],15,718787259);b=ii(b,c,d,a,k[9],21,-343485551);x[0]=add32(a,x[0]);x[1]=add32(b,x[1]);x[2]=add32(c,x[2]);x[3]=add32(d,x[3])};var cmn=function(q,a,b,x,s,t){a=add32(add32(a,q),add32(x,t));return add32(a<<s|a>>>32-s,b)};var ff=function(a,b,c,d,x,s,t){return cmn(b&c|~b&d,a,b,x,s,t)};var gg=function(a,b,c,d,x,s,t){return cmn(b&d|c&~d,a,b,x,s,t)};var hh=function(a,b,c,d,x,s,t){return cmn(b^c^d,a,b,x,s,t)};var ii=function(a,b,c,d,x,s,t){return cmn(c^(b|~d),a,b,x,s,t)};var md51=function(s){var txt="",n=s.length,state=[1732584193,-271733879,-1732584194,271733878],i;for(i=64;i<=s.length;i+=64){md5cycle(state,md5blk(s.substring(i-64,i)))}s=s.substring(i-64);var tail=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(i=0;i<s.length;i++)tail[i>>2]|=s.charCodeAt(i)<<(i%4<<3);tail[i>>2]|=128<<(i%4<<3);if(i>55){md5cycle(state,tail);for(i=0;i<16;i++)tail[i]=0}tail[14]=n*8;md5cycle(state,tail);return state};var md5blk=function(s){var md5blks=[],i;for(i=0;i<64;i+=4){md5blks[i>>2]=s.charCodeAt(i)+(s.charCodeAt(i+1)<<8)+(s.charCodeAt(i+2)<<16)+(s.charCodeAt(i+3)<<24)}return md5blks};var hex_chr="0123456789abcdef".split("");var rhex=function(n){var s="",j=0;for(;j<4;j++)s+=hex_chr[n>>j*8+4&15]+hex_chr[n>>j*8&15];return s};var hex=function(x){for(var i=0;i<x.length;i++)x[i]=rhex(x[i]);return x.join("")};var md5_=function(s){return hex(md51(s))};var add32=function(a,b){return a+b&4294967295};if(md5_("hello")!="5d41402abc4b2a76b9719d911017c592"){var add32=function(x,y){var lsw=(x&65535)+(y&65535),msw=(x>>16)+(y>>16)+(lsw>>16);return msw<<16|lsw&65535}}return md5_(str)},
|
2738
2740
|
|
2739
2741
|
|
2740
|
-
// ######## Cookies: https://github.com/ttodua/useful-javascript/blob/master/cookies-library.js ######## //
|
2741
|
-
Cookies : {
|
2742
|
-
get(a,b) { return this.cookies_instance().get(a,b); },
|
2743
|
-
set(a,b,c) { return this.cookies_instance().set(a,b); },
|
2744
|
-
remove(a, b) {return this.cookies_instance().remove(a,b); },
|
2745
|
-
append(name, value, attributes) {return this.cookies_instance().set((this.get(name) || '') + value, attributes); },
|
2746
|
-
isset(cookiename) {return this.get(cookiename)!="";}, // document.cookie.indexOf('; '+cookiename+'=');
|
2747
|
-
// WORKING WITH ARRAY/OBJECTS
|
2748
|
-
getOption(cookieName, key, defaultValue)
|
2749
|
-
{
|
2750
|
-
var existingValue = this.get(cookieName);
|
2751
|
-
if(existingValue)
|
2752
|
-
{
|
2753
|
-
var parsed = JSON.parse(existingValue);
|
2754
|
-
if(key in parsed)
|
2755
|
-
return parsed[key];
|
2756
|
-
}
|
2757
|
-
return defaultValue;
|
2758
|
-
},
|
2759
|
-
setOption(cookieName, key, value, attributes)
|
2760
|
-
{
|
2761
|
-
var cookie = this.get(cookieName);
|
2762
|
-
var parsed = {};
|
2763
|
-
if(cookie) parsed = JSON.parse(cookie);
|
2764
|
-
parsed[key] = value;
|
2765
|
-
var attributes = attributes || { expires: 99999 };
|
2766
|
-
this.set(cookieName, JSON.stringify(parsed), attributes);
|
2767
|
-
return parsed;
|
2768
|
-
},
|
2769
|
-
removeOption(cookieName, key, attributes)
|
2770
|
-
{
|
2771
|
-
var cookie = this.get(cookieName);
|
2772
|
-
var parsed = {};
|
2773
|
-
if(cookie) parsed = JSON.parse(cookie);
|
2774
|
-
if(key in parsed) delete parsed[key];
|
2775
|
-
var attributes = attributes || { expires: 99999 };
|
2776
|
-
this.set(cookieName, JSON.stringify(parsed), attributes);
|
2777
|
-
return parsed;
|
2778
|
-
},
|
2779
|
-
//sub-array
|
2780
|
-
getOptionObject(cookieName, key){
|
2781
|
-
return JSON.parse( this.getOption(cookieName, key, "{}") );
|
2782
|
-
},
|
2783
|
-
setOptionObject(cookieName, key, subKey, subValue){
|
2784
|
-
var existing = JSON.parse( this.getOption(cookieName, key, "{}") );
|
2785
|
-
if (subValue==null) delete existing[subKey];
|
2786
|
-
else existing[subKey]=subValue;
|
2787
|
-
this.setOption(cookieName, key, JSON.stringify(existing));
|
2788
|
-
},
|
2789
|
-
setOptionArray(cookieName, key, subValue, Add_or_remove)
|
2790
|
-
{
|
2791
|
-
var existing = JSON.parse( this.getOption(cookieName, key, "[]") );
|
2792
|
-
if (Add_or_remove && !existing.includes(subValue) )
|
2793
|
-
{
|
2794
|
-
existing.push(subValue);
|
2795
|
-
}
|
2796
|
-
else if(!Add_or_remove && existing.includes(subValue) )
|
2797
|
-
{
|
2798
|
-
existing = this.removeItem(existing, subValue);
|
2799
|
-
}
|
2800
|
-
this.setOption(cookieName, key, JSON.stringify(existing));
|
2801
|
-
},
|
2802
|
-
//
|
2803
|
-
cookies_instance(){ if (!this.cookies_inited) this.cookies_inited=this.cookies(); return this.cookies_inited; } ,
|
2804
|
-
cookies_inited: null,
|
2805
|
-
// https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js
|
2806
|
-
cookies : function(){"use strict";function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var t={read:function(e){return e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};return function n(r,o){function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),n=r.write(n,t);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n+c}}return Object.create({set:i,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var c=n[i].split("="),u=c.slice(1).join("=");'"'===u[0]&&(u=u.slice(1,-1));try{var f=t.read(c[0]);if(o[f]=r.read(u,f),e===f)break}catch(e){}}return e?o[e]:o}},remove:function(t,n){i(t,"",e({},n,{expires:-1}))},withAttributes:function(t){return n(this.converter,e({},this.attributes,t))},withConverter:function(t){return n(e({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(r)}})}(t,{path:"/"})}
|
2807
|
-
},
|
2808
|
-
|
2809
2742
|
|
2810
2743
|
|
2811
2744
|
jsonConcat(o1, o2) {
|
@@ -2880,62 +2813,174 @@ const puvox_library =
|
|
2880
2813
|
return this.privateAppName__;
|
2881
2814
|
},
|
2882
2815
|
|
2816
|
+
|
2817
|
+
// ######## Cookies: https://github.com/ttodua/useful-javascript/blob/master/cookies-library.js ######## //
|
2818
|
+
Cookies : {
|
2819
|
+
get(a,b) { return this.cookies_instance().get(a,b); },
|
2820
|
+
set(a,b,c) { return this.cookies_instance().set(a,b); },
|
2821
|
+
remove(a, b) {return this.cookies_instance().remove(a,b); },
|
2822
|
+
append(name, value, attributes) {return this.cookies_instance().set((this.get(name) || '') + value, attributes); },
|
2823
|
+
isset(cookiename) {return this.get(cookiename)!="";}, // document.cookie.indexOf('; '+cookiename+'=');
|
2824
|
+
// WORKING WITH ARRAY/OBJECTS
|
2825
|
+
getOption(cookieName, key, defaultValue)
|
2826
|
+
{
|
2827
|
+
var existingValue = this.get(cookieName);
|
2828
|
+
if(existingValue)
|
2829
|
+
{
|
2830
|
+
var parsed = JSON.parse(existingValue);
|
2831
|
+
if(key in parsed)
|
2832
|
+
return parsed[key];
|
2833
|
+
}
|
2834
|
+
return defaultValue;
|
2835
|
+
},
|
2836
|
+
setOption(cookieName, key, value, attributes)
|
2837
|
+
{
|
2838
|
+
var cookie = this.get(cookieName);
|
2839
|
+
var parsed = {};
|
2840
|
+
if(cookie) parsed = JSON.parse(cookie);
|
2841
|
+
parsed[key] = value;
|
2842
|
+
var attributes = attributes || { expires: 99999 };
|
2843
|
+
this.set(cookieName, JSON.stringify(parsed), attributes);
|
2844
|
+
return parsed;
|
2845
|
+
},
|
2846
|
+
removeOption(cookieName, key, attributes)
|
2847
|
+
{
|
2848
|
+
var cookie = this.get(cookieName);
|
2849
|
+
var parsed = {};
|
2850
|
+
if(cookie) parsed = JSON.parse(cookie);
|
2851
|
+
if(key in parsed) delete parsed[key];
|
2852
|
+
var attributes = attributes || { expires: 99999 };
|
2853
|
+
this.set(cookieName, JSON.stringify(parsed), attributes);
|
2854
|
+
return parsed;
|
2855
|
+
},
|
2856
|
+
//sub-array
|
2857
|
+
getOptionObject(cookieName, key){
|
2858
|
+
return JSON.parse( this.getOption(cookieName, key, "{}") );
|
2859
|
+
},
|
2860
|
+
setOptionObject(cookieName, key, subKey, subValue){
|
2861
|
+
var existing = JSON.parse( this.getOption(cookieName, key, "{}") );
|
2862
|
+
if (subValue==null) delete existing[subKey];
|
2863
|
+
else existing[subKey]=subValue;
|
2864
|
+
this.setOption(cookieName, key, JSON.stringify(existing));
|
2865
|
+
},
|
2866
|
+
setOptionArray(cookieName, key, subValue, Add_or_remove)
|
2867
|
+
{
|
2868
|
+
var existing = JSON.parse( this.getOption(cookieName, key, "[]") );
|
2869
|
+
if (Add_or_remove && !existing.includes(subValue) )
|
2870
|
+
{
|
2871
|
+
existing.push(subValue);
|
2872
|
+
}
|
2873
|
+
else if(!Add_or_remove && existing.includes(subValue) )
|
2874
|
+
{
|
2875
|
+
existing = puvox_library.removeItem(existing, subValue);
|
2876
|
+
}
|
2877
|
+
this.setOption(cookieName, key, JSON.stringify(existing));
|
2878
|
+
},
|
2879
|
+
//
|
2880
|
+
cookies_instance(){ if (!this.cookies_inited) this.cookies_inited=this.cookies(); return this.cookies_inited; } ,
|
2881
|
+
cookies_inited: null,
|
2882
|
+
// https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js
|
2883
|
+
cookies : function(){"use strict";function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var t={read:function(e){return e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};return function n(r,o){function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),n=r.write(n,t);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n+c}}return Object.create({set:i,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var c=n[i].split("="),u=c.slice(1).join("=");'"'===u[0]&&(u=u.slice(1,-1));try{var f=t.read(c[0]);if(o[f]=r.read(u,f),e===f)break}catch(e){}}return e?o[e]:o}},remove:function(t,n){i(t,"",e({},n,{expires:-1}))},withAttributes:function(t){return n(this.converter,e({},this.attributes,t))},withConverter:function(t){return n(e({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(r)}})}(t,{path:"/"})}
|
2884
|
+
},
|
2885
|
+
|
2886
|
+
|
2883
2887
|
cache: {
|
2884
|
-
|
2885
|
-
|
2886
|
-
|
2887
|
-
|
2888
|
-
|
2889
|
-
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2888
|
+
helper_read(groupName, storageType, expireSeconds = 0){
|
2889
|
+
const appName = puvox_library.getAppName();
|
2890
|
+
if (storageType === 'file'){
|
2891
|
+
const filepath = puvox_library.file.tempDir() + appName + '_' + groupName + '.json';
|
2892
|
+
// todo: add expiration
|
2893
|
+
return puvox_library.file.read(filepath);
|
2894
|
+
} else if (storageType === 'localStorage') {
|
2895
|
+
const storage = window.localStorage;
|
2896
|
+
let val = storage.getItem(appName + '_' + groupName);
|
2897
|
+
let expireVal = parseInt(storage.getItem(appName + '_' + groupName + '_t'));
|
2898
|
+
// if it's expired, then return null
|
2899
|
+
if (expireSeconds !== 0 && (new Date()).getTime() - expireVal > expireSeconds*1000){
|
2900
|
+
this.storage.removeItem(appName + '_' + groupName);
|
2901
|
+
this.storage.removeItem(appName + '_' + groupName + '_t');
|
2902
|
+
return null;
|
2893
2903
|
} else {
|
2894
|
-
|
2895
|
-
return val;
|
2896
|
-
} else {
|
2897
|
-
let now = (new Date()).getTime();
|
2898
|
-
if (now - expireVal > expireSeconds*1000){
|
2899
|
-
this.storage.removeItem(appName + '_' + name);
|
2900
|
-
this.storage.removeItem(appName + '_createtime_' + name);
|
2901
|
-
return defaultValue;
|
2902
|
-
}
|
2903
|
-
}
|
2904
|
+
return val;
|
2904
2905
|
}
|
2905
|
-
}
|
2906
|
-
|
2906
|
+
} else {
|
2907
|
+
alert(`storageType ${storageType} not supported`);
|
2908
|
+
throw new Error(`storageType ${storageType} not supported`);
|
2909
|
+
}
|
2910
|
+
},
|
2911
|
+
helper_write(groupName, content, storageType){
|
2912
|
+
const appName = puvox_library.getAppName();
|
2913
|
+
if (storageType == 'file'){
|
2914
|
+
const filepath = puvox_library.file.tempDir() + appName + '_' + groupName + '.json';
|
2915
|
+
// todo: add expiration
|
2916
|
+
puvox_library.file.write(filepath, content);
|
2917
|
+
return true;
|
2918
|
+
} else if (storageType === 'localStorage') {
|
2907
2919
|
try{
|
2908
|
-
const
|
2909
|
-
|
2910
|
-
|
2920
|
+
const storage = window.localStorage;
|
2921
|
+
storage.setItem(appName + '_' + groupName, content);
|
2922
|
+
storage.setItem(appName + '_' + groupName + '_t', (new Date()).getTime());
|
2911
2923
|
return true;
|
2912
2924
|
}
|
2913
|
-
catch(ex){ alert("Cache storage quote exceeded. can't save value. err598"
|
2914
|
-
}
|
2915
|
-
|
2916
|
-
|
2917
|
-
this.storage.removeItem(appName + '_' + name);
|
2918
|
-
this.storage.removeItem(appName + '_createtime_' + name);
|
2919
|
-
},
|
2920
|
-
getItem(name, subItemName, defaultValue){
|
2921
|
-
let val = this.get(name, '{}');
|
2922
|
-
let parsed = JSON.parse(val);
|
2923
|
-
return (subItemName in parsed ? parsed[subItemName] : defaultValue);
|
2924
|
-
},
|
2925
|
-
setItem(name, subItemName, value){
|
2926
|
-
let curr = this.get(name, '{}' );
|
2927
|
-
let parsed = JSON.parse(curr);
|
2928
|
-
parsed[subItemName] = value;
|
2929
|
-
return this.set(name, JSON.stringify(parsed) );
|
2930
|
-
},
|
2931
|
-
removeItem(name, subItemName, value){
|
2932
|
-
let curr = this.get(name, '{}' );
|
2933
|
-
let parsed = JSON.parse(curr);
|
2934
|
-
if (subItemName in parsed)
|
2935
|
-
delete parsed[subItemName];
|
2936
|
-
return this.set(name, JSON.stringify(parsed) );
|
2925
|
+
catch(ex){ alert("Cache storage quote exceeded. can't save value. err598 |" + ex.message); }
|
2926
|
+
} else {
|
2927
|
+
alert(`storageType ${storageType} not supported`);
|
2928
|
+
throw new Error(`storageType ${storageType} not supported`);
|
2937
2929
|
}
|
2938
2930
|
},
|
2931
|
+
helper_delete(groupName, storageType){
|
2932
|
+
const appName = puvox_library.getAppName();
|
2933
|
+
if (storageType == 'file'){
|
2934
|
+
const filepath = puvox_library.file.tempDir() + appName + '_' + groupName + '.json';
|
2935
|
+
// todo: better delete
|
2936
|
+
puvox_library.file.delete(filepath);
|
2937
|
+
return true;
|
2938
|
+
} else if (storageType === 'localStorage') {
|
2939
|
+
try{
|
2940
|
+
const storage = window.localStorage;
|
2941
|
+
storage.setItem(appName + '_' + groupName, content);
|
2942
|
+
storage.setItem(appName + '_' + groupName + '_t', (new Date()).getTime());
|
2943
|
+
return true;
|
2944
|
+
}
|
2945
|
+
catch(ex){ alert("Cache storage quote exceeded. can't save value. err598 |" + ex.message); }
|
2946
|
+
} else {
|
2947
|
+
alert(`storageType ${storageType} not supported`);
|
2948
|
+
throw new Error(`storageType ${storageType} not supported`);
|
2949
|
+
}
|
2950
|
+
},
|
2951
|
+
|
2952
|
+
get(groupName, defaultVal = null, storageType = 'localStorage', expireSeconds = 0){
|
2953
|
+
const content = this.helper_read(groupName, storageType, expireSeconds);
|
2954
|
+
return (content !== null && content !== '') ? content : defaultVal;
|
2955
|
+
},
|
2956
|
+
set(groupName, content, storageType = 'localStorage'){
|
2957
|
+
this.helper_write(groupName, content, storageType);
|
2958
|
+
},
|
2959
|
+
delete(groupName, storageType = 'localStorage'){
|
2960
|
+
this.helper_delete(groupName, storageType);
|
2961
|
+
},
|
2962
|
+
getChild(groupName, optName, defaultVal = null, storageType = 'localStorage', expireSeconds = 0){
|
2963
|
+
// todo: individual sub-item expiration
|
2964
|
+
const content = this.get(groupName, '{}', storageType, expireSeconds);
|
2965
|
+
const json = JSON.parse(content);
|
2966
|
+
return (optName in json) ? json[optName] : defaultVal;
|
2967
|
+
},
|
2968
|
+
setChild(groupName, optName, val, storageType = 'localStorage'){
|
2969
|
+
const content = this.get(groupName, '{}', storageType, expireSeconds);
|
2970
|
+
const json = JSON.parse(content);
|
2971
|
+
json[optName] = val;
|
2972
|
+
this.set(groupName, JSON.stringify(json), storageType);
|
2973
|
+
},
|
2974
|
+
deleteChild(groupName, optName, storageType = 'localStorage'){
|
2975
|
+
const content = this.get(groupName, '{}', storageType, expireSeconds);
|
2976
|
+
// if it's empty, no need to do anything
|
2977
|
+
if (content === '{}') return;
|
2978
|
+
const json = JSON.parse(content);
|
2979
|
+
delete json[optName];
|
2980
|
+
this.set(groupName, JSON.stringify(json), storageType);
|
2981
|
+
},
|
2982
|
+
|
2983
|
+
|
2939
2984
|
file: {
|
2940
2985
|
// ########## CACHE DIRS (server-side JS) ##########
|
2941
2986
|
customCacheDir:null,
|
@@ -3005,6 +3050,10 @@ const puvox_library =
|
|
3005
3050
|
return parent.file.write(filePath, contentFinal);
|
3006
3051
|
},
|
3007
3052
|
|
3053
|
+
|
3054
|
+
|
3055
|
+
|
3056
|
+
|
3008
3057
|
//
|
3009
3058
|
// writeFileAppendJson(filePath, jsonContent, callback){
|
3010
3059
|
// try{
|
@@ -3056,7 +3105,9 @@ const puvox_library =
|
|
3056
3105
|
}
|
3057
3106
|
return false;
|
3058
3107
|
},
|
3059
|
-
}
|
3108
|
+
},
|
3109
|
+
|
3110
|
+
|
3060
3111
|
},
|
3061
3112
|
|
3062
3113
|
// ################################################
|
@@ -3074,7 +3125,7 @@ const puvox_library =
|
|
3074
3125
|
fs() {return require('fs');}, //puvox_library.modules('fs')
|
3075
3126
|
os() {return require('os');},
|
3076
3127
|
path() {return require('path');},
|
3077
|
-
//
|
3128
|
+
// ends with slash
|
3078
3129
|
tempDir(){ return puvox_library.trailingSlash(this.os().tmpdir()); },
|
3079
3130
|
|
3080
3131
|
exists(filePath){
|
@@ -3087,6 +3138,9 @@ const puvox_library =
|
|
3087
3138
|
return null;
|
3088
3139
|
}
|
3089
3140
|
},
|
3141
|
+
delete(filePath){
|
3142
|
+
return (this.unlink(filePath));
|
3143
|
+
},
|
3090
3144
|
unlink(filePath){
|
3091
3145
|
return (this.fs().unlinkSync(filePath));
|
3092
3146
|
},
|
@@ -3132,12 +3186,6 @@ const puvox_library =
|
|
3132
3186
|
|
3133
3187
|
|
3134
3188
|
|
3135
|
-
|
3136
|
-
|
3137
|
-
|
3138
|
-
|
3139
|
-
|
3140
|
-
|
3141
3189
|
|
3142
3190
|
// region: ####### from CCXT ##########
|
3143
3191
|
// generic
|
package/package.json
CHANGED
File without changes
|