puvox-library 1.1.0 → 1.1.2
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.d.ts +24 -14
- package/library_standard.d.ts.map +1 -1
- package/library_standard.js +149 -158
- package/package.json +1 -1
package/library_standard.d.ts
CHANGED
@@ -373,6 +373,7 @@ declare class PuvoxLibrary {
|
|
373
373
|
privateAppName__: null;
|
374
374
|
setAppName(name: any): void;
|
375
375
|
getAppName(): never;
|
376
|
+
stringifyForWrite(content: any): any;
|
376
377
|
Cookies: {
|
377
378
|
parentClass: null;
|
378
379
|
mainClass(): null;
|
@@ -394,24 +395,32 @@ declare class PuvoxLibrary {
|
|
394
395
|
cache: {
|
395
396
|
parentClass: null;
|
396
397
|
mainClass(): null;
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
398
|
+
helper_get_child(instanceClass: any, optName: any, subKeyName: any, defaultVal?: null, expireSeconds?: number): any;
|
399
|
+
helper_set_child(instanceClass: any, optName: any, subKeyName: any, val: any): void;
|
400
|
+
helper_delete_child(instanceClass: any, optName: any, subKeyName: any): void;
|
401
|
+
localstorage: {
|
402
|
+
parentClass: null;
|
403
|
+
mainClass(): any;
|
404
|
+
get(optName: any, defaultValue?: null, decode?: boolean, expireSeconds?: number): any;
|
405
|
+
set(optName: any, content: any): true | undefined;
|
406
|
+
delete(optName: any): boolean;
|
407
|
+
get_child(optName: any, subKeyName: any, defaultVal?: null, expireSeconds?: number): any;
|
408
|
+
set_child(optName: any, subKeyName: any, val: any): any;
|
409
|
+
delete_child(optName: any, subKeyName: any): any;
|
410
|
+
};
|
406
411
|
file: {
|
407
412
|
parentClass: null;
|
408
413
|
mainClass(): any;
|
409
414
|
customCacheDir: null;
|
410
|
-
|
415
|
+
file_path(optName: any): string;
|
416
|
+
get(optName: any, defaultValue?: null, decode?: boolean, expire_seconds?: number): any;
|
417
|
+
set(optName: any, content: any): any;
|
418
|
+
delete(optName: any): any;
|
419
|
+
get_child(optName: any, subKeyName: any, defaultVal?: null, expireSeconds?: number): any;
|
420
|
+
set_child(optName: any, subKeyName: any, val: any): any;
|
421
|
+
delete_child(optName: any, subKeyName: any): any;
|
411
422
|
set_dir(dir: any, auto_clear_seconds?: null): any;
|
412
423
|
filePath(uniqFileName: any): string;
|
413
|
-
get(uniqFileName: any, defaultContent?: string, expire_seconds?: number, decode?: boolean): any;
|
414
|
-
set(uniqFileName: any, content: any): any;
|
415
424
|
containerDefaultPrefix: string;
|
416
425
|
tempIds: {};
|
417
426
|
idForContent(slugOrContent: any): any;
|
@@ -438,8 +447,9 @@ declare class PuvoxLibrary {
|
|
438
447
|
delete(filePath: any): any;
|
439
448
|
unlink(filePath: any): any;
|
440
449
|
createDirectory(dirPath: any): any;
|
441
|
-
read(filePath: any,
|
442
|
-
|
450
|
+
read(filePath: any, defaultValue?: string): any;
|
451
|
+
readCustom(filePath: any, defaultValue?: string, decode?: boolean, expireSeconds?: number): any;
|
452
|
+
write(filePath: any, content: any): any;
|
443
453
|
getFilesListFromDir(dir: any): any[];
|
444
454
|
};
|
445
455
|
catchUnhandledExceptions(callback: any): void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"library_standard.d.ts","sourceRoot":"","sources":["library_standard.js"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;AAEF;IAGC,0BAEC;IAJD,uBAAgB;IAQhB,uDAEC;IACD,4DAGC;IACD,4DAGC;IACD,6CAIC;IACD,8CAIC;IAykDE,uCAGC;IA3kDJ,iDAMC;IACD,oCAEC;IACD,6DAYC;IACD,kCAA8D;IAC9D,+BAAkD;IAClD,6BAAuD;IACvD,uCAOC;IACD,6CAOC;IACD,6CAEC;IACD,kDAEC;IACD,uCAsDC;IACD,+BAKI;IACJ,0DAEC;IACD,yCAMC;IACD,2CAEC;IAED,0BAEC;IAEE,uCAEC;IAED,yCAIC;IACD,2DASC;IACJ,0EAWI;IAKJ,uEAiBC;IAKD,kCAMC;IAED,yCAKC;IAQD,qDAkBC;IACD,oDAmCC;IAED,6DAOC;IACD,8BAKC;IAED,qBAIC;IAED,qCAGC;IAGD,0DAYC;IAGD,wBAAqE;IAErE,2CAA+I;IAE/I,mCAAmF;IAEnF,sCAAkF;IAElF,iDAAyG;IAGzG,8BAA0D;IAE1D,wCAAkE;IAE/D,qEAIC;IAIJ,qJAQC;
|
1
|
+
{"version":3,"file":"library_standard.d.ts","sourceRoot":"","sources":["library_standard.js"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;AAEF;IAGC,0BAEC;IAJD,uBAAgB;IAQhB,uDAEC;IACD,4DAGC;IACD,4DAGC;IACD,6CAIC;IACD,8CAIC;IAykDE,uCAGC;IA3kDJ,iDAMC;IACD,oCAEC;IACD,6DAYC;IACD,kCAA8D;IAC9D,+BAAkD;IAClD,6BAAuD;IACvD,uCAOC;IACD,6CAOC;IACD,6CAEC;IACD,kDAEC;IACD,uCAsDC;IACD,+BAKI;IACJ,0DAEC;IACD,yCAMC;IACD,2CAEC;IAED,0BAEC;IAEE,uCAEC;IAED,yCAIC;IACD,2DASC;IACJ,0EAWI;IAKJ,uEAiBC;IAKD,kCAMC;IAED,yCAKC;IAQD,qDAkBC;IACD,oDAmCC;IAED,6DAOC;IACD,8BAKC;IAED,qBAIC;IAED,qCAGC;IAGD,0DAYC;IAGD,wBAAqE;IAErE,2CAA+I;IAE/I,mCAAmF;IAEnF,sCAAkF;IAElF,iDAAyG;IAGzG,8BAA0D;IAE1D,wCAAkE;IAE/D,qEAIC;IAIJ,qJAQC;IAugGE,+BAA4B;IArgG/B,2BAA2C;IAC3C,2BAAqE;IACrE,2BAA+H;IAC/H,+BAAiG;IACjG,0BAA+E;IAogG5E,0BAA8C;IAlgGjD,0BAAkQ;IAmgG/P,0BAAgE;IAjgGnE,iCAGC;IA2/FE,6BAAuB;IAx/F1B,wCAA8E;IAC9E,kDAAyI;IACzI,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AgD;IAEnD,kBAAe;IACf,2BAAsB;IACtB,kBAAoD;CAEpD"}
|
package/library_standard.js
CHANGED
@@ -2899,6 +2899,18 @@ class PuvoxLibrary {
|
|
2899
2899
|
return this.privateAppName__;
|
2900
2900
|
}
|
2901
2901
|
|
2902
|
+
stringifyForWrite(content) {
|
2903
|
+
if (this.isString(content)) {
|
2904
|
+
return content;
|
2905
|
+
}
|
2906
|
+
else if (this.isNumeric(content)) {
|
2907
|
+
return content.toString();
|
2908
|
+
}
|
2909
|
+
else if (this.isObject(content) || this.isArray(content)) {
|
2910
|
+
return JSON.stringify(content);
|
2911
|
+
}
|
2912
|
+
return content;
|
2913
|
+
}
|
2902
2914
|
|
2903
2915
|
// ######## Cookies: https://github.com/ttodua/useful-javascript/blob/master/cookies-library.js ######## //
|
2904
2916
|
Cookies = new (class {
|
@@ -2982,107 +2994,80 @@ class PuvoxLibrary {
|
|
2982
2994
|
this.parentClass = parentClass;
|
2983
2995
|
}
|
2984
2996
|
mainClass() { return this.parentClass; }
|
2997
|
+
|
2998
|
+
helper_get_child(instanceClass, optName, subKeyName, defaultVal = null, expireSeconds = 0){
|
2999
|
+
const json = instanceClass.get(optName, {}, true, expireSeconds);
|
3000
|
+
return (subKeyName in json) ? json[subKeyName] : defaultVal;
|
3001
|
+
}
|
3002
|
+
helper_set_child(instanceClass, optName, subKeyName, val){
|
3003
|
+
const json = instanceClass.get(optName, {}, true, 0);
|
3004
|
+
json[subKeyName] = val;
|
3005
|
+
instanceClass.set(optName, json);
|
3006
|
+
}
|
3007
|
+
helper_delete_child(instanceClass, optName, subKeyName){
|
3008
|
+
const json = instanceClass.get(optName, {}, true, 0);
|
3009
|
+
delete json[subKeyName];
|
3010
|
+
instanceClass.set(optName, json);
|
3011
|
+
}
|
2985
3012
|
|
2986
|
-
|
2987
|
-
|
2988
|
-
|
2989
|
-
|
2990
|
-
|
2991
|
-
|
2992
|
-
|
2993
|
-
|
3013
|
+
// lets localstrage be under cache class
|
3014
|
+
localstorage = new (class {
|
3015
|
+
parentClass = null;
|
3016
|
+
constructor(parentClass){
|
3017
|
+
this.parentClass = parentClass;
|
3018
|
+
}
|
3019
|
+
mainClass() { return this.parentClass.parentClass; }
|
3020
|
+
|
3021
|
+
// ###################
|
3022
|
+
get(optName, defaultValue = null, decode = true, expireSeconds = 0){
|
3023
|
+
const appName = this.mainClass().getAppName();
|
2994
3024
|
const storage = window.localStorage;
|
2995
|
-
|
2996
|
-
let expireVal = parseInt(
|
3025
|
+
const tsValue = storage.getItem(appName + '_' + optName + '_t');
|
3026
|
+
let expireVal = tsValue ? parseInt(tsValue) : 0;
|
2997
3027
|
// if it's expired, then return null
|
2998
3028
|
if (expireSeconds !== 0 && (new Date()).getTime() - expireVal > expireSeconds*1000){
|
2999
|
-
|
3000
|
-
|
3001
|
-
return
|
3029
|
+
storage.removeItem(appName + '_' + optName);
|
3030
|
+
storage.removeItem(appName + '_' + optName + '_t');
|
3031
|
+
return defaultValue;
|
3002
3032
|
} else {
|
3033
|
+
const val = storage.getItem(appName + '_' + optName);
|
3034
|
+
if (decode) { try { return JSON.parse(val) } catch(e) {} }
|
3003
3035
|
return val;
|
3004
3036
|
}
|
3005
|
-
}
|
3006
|
-
|
3007
|
-
throw new Error(`storageType ${storageType} not supported`);
|
3008
|
-
}
|
3009
|
-
}
|
3010
|
-
helper_write(groupName, content, storageType){
|
3011
|
-
content = this.mainClass().isString (content) ? content : (this.mainClass().isArray(content) || this.mainClass().isObject(content) ? JSON.stringify(content) : content);
|
3012
|
-
const appName = this.mainClass().getAppName();
|
3013
|
-
if (storageType === 'file'){
|
3014
|
-
const dir = this.mainClass().file.tempDir() + appName + '/';
|
3015
|
-
this.mainClass().file.createDirectory(dir);
|
3016
|
-
const filepath = dir + groupName + '.json';
|
3017
|
-
// todo: add expiration
|
3018
|
-
this.mainClass().file.write(filepath, content);
|
3019
|
-
return true;
|
3020
|
-
} else if (storageType === 'localStorage') {
|
3021
|
-
try{
|
3022
|
-
const storage = window.localStorage;
|
3023
|
-
storage.setItem(appName + '_' + groupName, content);
|
3024
|
-
storage.setItem(appName + '_' + groupName + '_t', (new Date()).getTime());
|
3025
|
-
return true;
|
3026
|
-
}
|
3027
|
-
catch(ex){ alert("Cache storage quote exceeded. can't save value. err598 |" + ex.message); }
|
3028
|
-
} else {
|
3029
|
-
if (typeof alert !== 'undefined') alert(`storageType ${storageType} not supported`);
|
3030
|
-
throw new Error(`storageType ${storageType} not supported`);
|
3031
|
-
}
|
3032
|
-
}
|
3033
|
-
helper_delete(groupName, storageType){
|
3034
|
-
const appName = this.mainClass().getAppName();
|
3035
|
-
if (storageType === 'file'){
|
3036
|
-
const filepath = this.mainClass().file.tempDir() + appName + '/' + groupName + '.json';
|
3037
|
-
// todo: better delete
|
3038
|
-
this.mainClass().file.delete(filepath);
|
3039
|
-
return true;
|
3040
|
-
} else if (storageType === 'localStorage') {
|
3037
|
+
}
|
3038
|
+
set(optName, content){
|
3041
3039
|
try{
|
3040
|
+
const appName = this.mainClass().getAppName();
|
3042
3041
|
const storage = window.localStorage;
|
3043
|
-
|
3044
|
-
storage.setItem(appName + '_' +
|
3042
|
+
const finalContent = this.mainClass().stringifyForWrite(content);
|
3043
|
+
storage.setItem(appName + '_' + optName, finalContent);
|
3044
|
+
storage.setItem(appName + '_' + optName + '_t', (new Date()).getTime());
|
3045
3045
|
return true;
|
3046
3046
|
}
|
3047
|
-
catch(ex){ alert("
|
3048
|
-
} else {
|
3049
|
-
alert(`storageType ${storageType} not supported`);
|
3050
|
-
throw new Error(`storageType ${storageType} not supported`);
|
3047
|
+
catch(ex){ alert("Can't save value to localstorage. err598 |" + ex.message); }
|
3051
3048
|
}
|
3052
|
-
|
3053
|
-
|
3054
|
-
|
3055
|
-
|
3056
|
-
|
3057
|
-
|
3058
|
-
|
3059
|
-
|
3060
|
-
|
3061
|
-
|
3062
|
-
|
3063
|
-
|
3064
|
-
|
3065
|
-
|
3066
|
-
|
3067
|
-
|
3068
|
-
|
3069
|
-
|
3070
|
-
|
3071
|
-
const content = this.get(groupName, '{}', storageType);
|
3072
|
-
const json = JSON.parse(content);
|
3073
|
-
json[optName] = val;
|
3074
|
-
this.set(groupName, JSON.stringify(json), storageType);
|
3075
|
-
}
|
3076
|
-
deleteChild(groupName, optName, storageType = 'localStorage'){
|
3077
|
-
const content = this.get(groupName, '{}', storageType, expireSeconds);
|
3078
|
-
// if it's empty, no need to do anything
|
3079
|
-
if (content === '{}') return;
|
3080
|
-
const json = JSON.parse(content);
|
3081
|
-
delete json[optName];
|
3082
|
-
this.set(groupName, JSON.stringify(json), storageType);
|
3083
|
-
}
|
3084
|
-
|
3049
|
+
delete(optName){
|
3050
|
+
const appName = this.mainClass().getAppName();
|
3051
|
+
const storage = window.localStorage;
|
3052
|
+
storage.removeItem(appName + '_' + optName);
|
3053
|
+
storage.removeItem(appName + '_' + optName + '_t');
|
3054
|
+
return true;
|
3055
|
+
}
|
3056
|
+
// ################ child methods ################## //
|
3057
|
+
get_child(optName, subKeyName, defaultVal = null, expireSeconds = 0){
|
3058
|
+
return this.parentClass.helper_get_child(this, optName, subKeyName, defaultVal, expireSeconds);
|
3059
|
+
}
|
3060
|
+
set_child(optName, subKeyName, val){
|
3061
|
+
return this.parentClass.helper_set_child(this, optName, subKeyName, val);
|
3062
|
+
}
|
3063
|
+
delete_child(optName, subKeyName){
|
3064
|
+
return this.parentClass.helper_delete_child(this, optName, subKeyName);
|
3065
|
+
}
|
3066
|
+
// ########################################### //
|
3067
|
+
})(this);
|
3085
3068
|
|
3069
|
+
|
3070
|
+
// server-side caching
|
3086
3071
|
file = new (class {
|
3087
3072
|
parentClass = null;
|
3088
3073
|
constructor(parentClass){
|
@@ -3090,15 +3075,38 @@ class PuvoxLibrary {
|
|
3090
3075
|
}
|
3091
3076
|
mainClass() { return this.parentClass.parentClass; }
|
3092
3077
|
|
3093
|
-
//
|
3078
|
+
// ###################
|
3094
3079
|
customCacheDir = null;
|
3095
|
-
|
3080
|
+
file_path(optName) {
|
3096
3081
|
if (!this.customCacheDir){
|
3097
|
-
this.customCacheDir = this.mainClass().file.tempDir();
|
3082
|
+
this.customCacheDir = this.mainClass().file.tempDir() + this.mainClass().getAppName() + '/';
|
3098
3083
|
}
|
3099
|
-
|
3100
|
-
|
3084
|
+
return this.customCacheDir + optName + '.json';
|
3085
|
+
}
|
3086
|
+
get(optName, defaultValue = null, decode = true, expire_seconds=0)
|
3087
|
+
{
|
3088
|
+
return this.mainClass().file.readCustom(this.file_path(optName), defaultValue, decode, expire_seconds);
|
3089
|
+
}
|
3090
|
+
set(optName, content)
|
3091
|
+
{
|
3092
|
+
return this.mainClass().file.write(this.file_path(optName), content);
|
3093
|
+
}
|
3094
|
+
delete (optName) {
|
3095
|
+
return this.mainClass().file.delete(this.file_path(optName));
|
3101
3096
|
}
|
3097
|
+
// ################ child methods ################## //
|
3098
|
+
get_child(optName, subKeyName, defaultVal = null, expireSeconds = 0){
|
3099
|
+
return this.parentClass.helper_get_child(this, optName, subKeyName, defaultVal, expireSeconds);
|
3100
|
+
}
|
3101
|
+
set_child(optName, subKeyName, val){
|
3102
|
+
return this.parentClass.helper_set_child(this, optName, subKeyName, val);
|
3103
|
+
}
|
3104
|
+
delete_child(optName, subKeyName){
|
3105
|
+
return this.parentClass.helper_delete_child(this, optName, subKeyName);
|
3106
|
+
}
|
3107
|
+
// #############################################
|
3108
|
+
|
3109
|
+
// old
|
3102
3110
|
set_dir(dir, auto_clear_seconds=null){
|
3103
3111
|
if(dir) this.customCacheDir = dir;
|
3104
3112
|
const res = this.mainClass().file.createDirectory(this.customCacheDir);
|
@@ -3116,69 +3124,8 @@ class PuvoxLibrary {
|
|
3116
3124
|
const filePath = this.get_dir() + uniqFileName + "_tmp"; //"/".
|
3117
3125
|
return filePath;
|
3118
3126
|
}
|
3119
|
-
//
|
3120
|
-
get(uniqFileName, defaultContent ='', expire_seconds=8640000, decode = true)
|
3121
|
-
{
|
3122
|
-
const parent = this.mainClass();
|
3123
|
-
let filePath = this.filePath(uniqFileName);
|
3124
|
-
if ( parent.file.exists(filePath) ){
|
3125
|
-
if ( parent.file.mtime(filePath) + expire_seconds *1000 < (new Date()).getTime() ){
|
3126
|
-
parent.file.unlink(filePath);
|
3127
|
-
return defaultContent;
|
3128
|
-
}
|
3129
|
-
else{
|
3130
|
-
const cont = parent.file.read(filePath, null);
|
3131
|
-
// if specifically array, then on empty, reckon as array
|
3132
|
-
if (cont===null)
|
3133
|
-
{
|
3134
|
-
return defaultContent;
|
3135
|
-
}
|
3136
|
-
if (decode){
|
3137
|
-
try{
|
3138
|
-
return JSON.parse(cont);
|
3139
|
-
}
|
3140
|
-
catch(ex){
|
3141
|
-
return cont;
|
3142
|
-
}
|
3143
|
-
}
|
3144
|
-
else{
|
3145
|
-
return cont;
|
3146
|
-
}
|
3147
|
-
}
|
3148
|
-
}
|
3149
|
-
else {
|
3150
|
-
return defaultContent;
|
3151
|
-
}
|
3152
|
-
}
|
3153
|
-
set(uniqFileName, content)
|
3154
|
-
{
|
3155
|
-
const parent = this.mainClass();
|
3156
|
-
let filePath= this.filePath(uniqFileName);
|
3157
|
-
let contentFinal = parent.isString(content) ? content : ((parent.isArray(content) || parent.isObject(content)) ? JSON.stringify(content) : content);
|
3158
|
-
return parent.file.write(filePath, contentFinal);
|
3159
|
-
}
|
3160
3127
|
|
3161
|
-
|
3162
|
-
//
|
3163
|
-
// writeFileAppendJson(filePath, jsonContent, callback){
|
3164
|
-
// try{
|
3165
|
-
// var callback = callback || function(){};
|
3166
|
-
// var self = this;
|
3167
|
-
// this.mainClass().modules('fs').readFile(filePath, 'utf8', function(err,data) {
|
3168
|
-
// let json = {};
|
3169
|
-
// if (typeof data !="undefined" && data!=''){
|
3170
|
-
// json=JSON.parse(data);
|
3171
|
-
// }
|
3172
|
-
// let jsonNew = self.jsonConcat(json, jsonContent);
|
3173
|
-
// let content = JSON.stringify(jsonNew);
|
3174
|
-
// this.mainClass().modules('fs').writeFile(filePath, content, 'utf8', function(callback_) {
|
3175
|
-
// });
|
3176
|
-
// });
|
3177
|
-
// }
|
3178
|
-
// catch(e){
|
3179
|
-
// console.log("writeFileAppendJson", e);
|
3180
|
-
// }
|
3181
|
-
// },
|
3128
|
+
// ids
|
3182
3129
|
containerDefaultPrefix = "_cached_ids_";
|
3183
3130
|
tempIds = {};
|
3184
3131
|
idForContent(slugOrContent){
|
@@ -3210,6 +3157,26 @@ class PuvoxLibrary {
|
|
3210
3157
|
}
|
3211
3158
|
return false;
|
3212
3159
|
}
|
3160
|
+
//
|
3161
|
+
// writeFileAppendJson(filePath, jsonContent, callback){
|
3162
|
+
// try{
|
3163
|
+
// var callback = callback || function(){};
|
3164
|
+
// var self = this;
|
3165
|
+
// this.mainClass().modules('fs').readFile(filePath, 'utf8', function(err,data) {
|
3166
|
+
// let json = {};
|
3167
|
+
// if (typeof data !="undefined" && data!=''){
|
3168
|
+
// json=JSON.parse(data);
|
3169
|
+
// }
|
3170
|
+
// let jsonNew = self.jsonConcat(json, jsonContent);
|
3171
|
+
// let content = JSON.stringify(jsonNew);
|
3172
|
+
// this.mainClass().modules('fs').writeFile(filePath, content, 'utf8', function(callback_) {
|
3173
|
+
// });
|
3174
|
+
// });
|
3175
|
+
// }
|
3176
|
+
// catch(e){
|
3177
|
+
// console.log("writeFileAppendJson", e);
|
3178
|
+
// }
|
3179
|
+
// },
|
3213
3180
|
})(this);
|
3214
3181
|
})(this);
|
3215
3182
|
|
@@ -3289,16 +3256,40 @@ class PuvoxLibrary {
|
|
3289
3256
|
}
|
3290
3257
|
return true;
|
3291
3258
|
}
|
3292
|
-
read(filePath,
|
3259
|
+
read(filePath, defaultValue = ''){
|
3293
3260
|
if (!this.exists(filePath)){
|
3294
|
-
return
|
3261
|
+
return defaultValue;
|
3295
3262
|
}
|
3296
3263
|
return this.fs().readFileSync(filePath, 'utf8');
|
3297
3264
|
}
|
3265
|
+
readCustom(filePath, defaultValue = '', decode = true, expireSeconds = 0){
|
3266
|
+
if (!this.exists(filePath)){
|
3267
|
+
return defaultValue;
|
3268
|
+
}
|
3269
|
+
else {
|
3270
|
+
if ( this.mtime(filePath) + expireSeconds*1000 < (new Date()).getTime() ){
|
3271
|
+
this.unlink(filePath);
|
3272
|
+
return defaultValue;
|
3273
|
+
}
|
3274
|
+
else{
|
3275
|
+
const cont = this.read(filePath, null);
|
3276
|
+
// if specifically array, then on empty, reckon as array
|
3277
|
+
if (cont===null) {
|
3278
|
+
return defaultValue;
|
3279
|
+
}
|
3280
|
+
if (decode){
|
3281
|
+
try { return JSON.parse(cont); }
|
3282
|
+
catch(ex){ }
|
3283
|
+
}
|
3284
|
+
return cont;
|
3285
|
+
}
|
3286
|
+
}
|
3287
|
+
}
|
3298
3288
|
write(filePath, content){
|
3299
3289
|
const dir = this.path().dirname(filePath);
|
3300
3290
|
this.createDirectory(dir);
|
3301
|
-
this.
|
3291
|
+
const finalContent = this.mainClass().stringifyForWrite(content);
|
3292
|
+
return this.fs().writeFileSync(filePath, finalContent, 'utf8', function(err){
|
3302
3293
|
if (err) throw err;
|
3303
3294
|
});
|
3304
3295
|
}
|