puvox-library 1.0.26 → 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.
- package/library_standard.js +36 -21
- package/package.json +1 -1
package/library_standard.js
CHANGED
@@ -229,7 +229,7 @@ const puvox_library =
|
|
229
229
|
);
|
230
230
|
},
|
231
231
|
|
232
|
-
move_to_top_in_parent
|
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
|
-
|
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) {
|
@@ -2711,17 +2711,24 @@ const puvox_library =
|
|
2711
2711
|
},
|
2712
2712
|
// if(setHashInAddress) { window.location.hash = id_or_Name; }
|
2713
2713
|
|
2714
|
-
|
2715
|
-
|
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
|
+
},
|
2716
2723
|
|
2717
2724
|
// ######## CACHE ITEMS (client-side JS) ########
|
2718
|
-
|
2719
|
-
setAppName (name){ this.
|
2725
|
+
privateAppName__ : null, //override with anything you want
|
2726
|
+
setAppName (name){ this.privateAppName__ = name; },
|
2720
2727
|
getAppName(){
|
2721
|
-
if (!this.
|
2728
|
+
if (!this.privateAppName__){
|
2722
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');
|
2723
2730
|
}
|
2724
|
-
return this.
|
2731
|
+
return this.privateAppName__;
|
2725
2732
|
},
|
2726
2733
|
|
2727
2734
|
cache: {
|
@@ -2783,18 +2790,28 @@ const puvox_library =
|
|
2783
2790
|
file: {
|
2784
2791
|
// ########## CACHE DIRS (server-side JS) ##########
|
2785
2792
|
customCacheDir:null,
|
2786
|
-
|
2793
|
+
get_dir(){
|
2787
2794
|
if (!this.customCacheDir){
|
2788
|
-
this.customCacheDir = puvox_library.file.
|
2795
|
+
this.customCacheDir = puvox_library.file.tempDir();
|
2789
2796
|
}
|
2790
|
-
let finaldir = this.customCacheDir + '_cache_' + puvox_library.getAppName()
|
2797
|
+
let finaldir = puvox_library.trailingSlash(this.customCacheDir + '_cache_' + puvox_library.getAppName());
|
2791
2798
|
return finaldir;
|
2792
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
|
+
},
|
2793
2810
|
filePath(uniqFileName){
|
2794
2811
|
const parent = puvox_library;
|
2795
2812
|
uniqFileName = parent.isString(uniqFileName) || parent.isNumeric(uniqFileName) ? uniqFileName : JSON.stringify(uniqFileName);
|
2796
2813
|
uniqFileName = parent.sanitize_key_dashed(parent.getCharsFromStart(uniqFileName, 15)) + "_"+ parent.md5(uniqFileName);
|
2797
|
-
filePath= this.
|
2814
|
+
filePath= this.get_dir() + uniqFileName + "_tmp"; //"/".
|
2798
2815
|
return filePath;
|
2799
2816
|
},
|
2800
2817
|
//
|
@@ -2802,8 +2819,6 @@ const puvox_library =
|
|
2802
2819
|
{
|
2803
2820
|
const parent = puvox_library;
|
2804
2821
|
let filePath = this.filePath(uniqFileName);
|
2805
|
-
if ( filePath.length < 3) return "too tiny filename";
|
2806
|
-
|
2807
2822
|
if ( parent.file.exists(filePath) ){
|
2808
2823
|
if ( parent.file.mtime(filePath) + expire_seconds *1000 < (new Date()).getTime() ){
|
2809
2824
|
parent.file.unlink(filePath);
|
@@ -2871,14 +2886,14 @@ const puvox_library =
|
|
2871
2886
|
},
|
2872
2887
|
getIds(containerSlug) {
|
2873
2888
|
if (! (containerSlug in this.tempIds)) {
|
2874
|
-
const content = puvox_library.file.read(this.
|
2889
|
+
const content = puvox_library.file.read(this.get_dir() + this.containerDefaultPrefix + containerSlug, '{}');
|
2875
2890
|
this.tempIds[containerSlug] = JSON.parse(content);
|
2876
2891
|
}
|
2877
2892
|
return this.tempIds[containerSlug];
|
2878
2893
|
},
|
2879
2894
|
setIds(containerSlug, idsDict) {
|
2880
2895
|
this.tempIds[containerSlug] = idsDict;
|
2881
|
-
return puvox_library.file.write(this.
|
2896
|
+
return puvox_library.file.write(this.get_dir() + this.containerDefaultPrefix + containerSlug, JSON.stringify(this.tempIds[containerSlug]));
|
2882
2897
|
},
|
2883
2898
|
addId(containerSlug, id){
|
2884
2899
|
const ids = this.getIds(containerSlug);
|
@@ -2907,12 +2922,11 @@ const puvox_library =
|
|
2907
2922
|
// }
|
2908
2923
|
// },
|
2909
2924
|
file: {
|
2910
|
-
parent() {return puvox_library;},
|
2911
2925
|
fs() {return require('fs');}, //puvox_library.modules('fs')
|
2912
2926
|
os() {return require('os');},
|
2913
2927
|
path() {return require('path');},
|
2914
2928
|
//
|
2915
|
-
|
2929
|
+
tempDir(){ return puvox_library.trailingSlash(this.os().tmpdir()); },
|
2916
2930
|
|
2917
2931
|
exists(filePath){
|
2918
2932
|
return this.fs().existsSync(filePath);
|
@@ -2927,10 +2941,11 @@ const puvox_library =
|
|
2927
2941
|
unlink(filePath){
|
2928
2942
|
return (this.fs().unlinkSync(filePath));
|
2929
2943
|
},
|
2930
|
-
createDirectory(dirPath
|
2931
|
-
if (!this.exists(dirPath)
|
2932
|
-
this.fs().mkdirSync(dirPath, { recursive: true });
|
2944
|
+
createDirectory(dirPath){
|
2945
|
+
if (!this.exists(dirPath)){
|
2946
|
+
return this.fs().mkdirSync(dirPath, { recursive: true });
|
2933
2947
|
}
|
2948
|
+
return true;
|
2934
2949
|
},
|
2935
2950
|
read(filePath, defaultContent = ''){
|
2936
2951
|
if (!this.exists(filePath)){
|