puvox-library 1.1.0 → 1.1.1

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.
@@ -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
- helper_read(groupName: any, storageType: any, expireSeconds?: number): any;
398
- helper_write(groupName: any, content: any, storageType: any): true | undefined;
399
- helper_delete(groupName: any, storageType: any): true | undefined;
400
- get(groupName: any, defaultVal?: null, storageType?: string, expireSeconds?: number): any;
401
- set(groupName: any, content: any, storageType?: string): void;
402
- delete(groupName: any, storageType?: string): void;
403
- getChild(groupName: any, optName: any, defaultVal?: null, storageType?: string, expireSeconds?: number): any;
404
- setChild(groupName: any, optName: any, val: any, storageType?: string): void;
405
- deleteChild(groupName: any, optName: any, storageType?: string): void;
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
- get_dir(): any;
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, defaultContent?: string): any;
442
- write(filePath: any, content: any): void;
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;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ASC;IACD,2BAA+E;IAC/E,kCAeC;IACD,uBAGC;IACD,8BAeC;IAEJ,uCAA0B;IAGvB,0BAA0D;IAG1D,0BAA4C;IAC5C,8BAA4I;IAC5I,+BAAuF;IAC1F,0BAA6F;IAC7F,sDAA8G;IAC9G,wBAA4G;IAC5G,0BAAqH;IAUrH,uCAaC;IACD,wEAKC;IACD,4CAAgE;IAChE,0CAMC;IAEE,wCAIC;IAEJ,sCAGC;IACD,4BAEC;IAED,mBAAwC;IACxC,oBAA0I;IAC1I,qBAA6F;IAC7F,mBAA0E;IAE1E,gBAA4H;IAC5H,2BAAmB;IAEnB,kBAAgI;IAChI,wBAAmF;IAChF,mBAAgD;IAEnD,kBAAe;IACf,2BAAsB;IACtB,kBAAoD;CAEpD"}
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;IAqgGE,+BAA4B;IAngG/B,2B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,4CAAgE;IAChE,0CAMC;IAEE,wCAIC;IAEJ,sCAGC;IACD,4BAEC;IAED,mBAAwC;IACxC,oBAA0I;IAC1I,qBAA6F;IAC7F,mBAA0E;IAE1E,gBAA4H;IAC5H,2BAAmB;IAEnB,kBAAgI;IAChI,wBAAmF;IAChF,mBAAgD;IAEnD,kBAAe;IACf,2BAAsB;IACtB,kBAAoD;CAEpD"}
@@ -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,78 @@ 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
- helper_read(groupName, storageType, expireSeconds = 0){
2987
- const appName = this.mainClass().getAppName();
2988
- if (storageType === 'file'){
2989
- const dir = this.mainClass().file.tempDir() + appName + '/';
2990
- const filepath = dir + groupName + '.json';
2991
- // todo: add expiration
2992
- return this.mainClass().file.read(filepath);
2993
- } else if (storageType === 'localStorage') {
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
- let val = storage.getItem(appName + '_' + groupName);
2996
- let expireVal = parseInt(storage.getItem(appName + '_' + groupName + '_t'));
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
- this.storage.removeItem(appName + '_' + groupName);
3000
- this.storage.removeItem(appName + '_' + groupName + '_t');
3001
- return null;
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
- } else {
3006
- if (typeof alert !== 'undefined') alert(`storageType ${storageType} not supported`);
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{
3042
3040
  const storage = window.localStorage;
3043
- storage.setItem(appName + '_' + groupName, content);
3044
- storage.setItem(appName + '_' + groupName + '_t', (new Date()).getTime());
3041
+ const finalContent = this.mainClass().stringifyForWrite(content);
3042
+ storage.setItem(appName + '_' + optName, finalContent);
3043
+ storage.setItem(appName + '_' + optName + '_t', (new Date()).getTime());
3045
3044
  return true;
3046
3045
  }
3047
- catch(ex){ alert("Cache storage quote exceeded. can't save value. err598 |" + ex.message); }
3048
- } else {
3049
- alert(`storageType ${storageType} not supported`);
3050
- throw new Error(`storageType ${storageType} not supported`);
3046
+ catch(ex){ alert("Can't save value. Might be exceeding cache size. err598 |" + ex.message); }
3051
3047
  }
3052
- }
3053
-
3054
- get(groupName, defaultVal = null, storageType = 'localStorage', expireSeconds = 0){
3055
- const content = this.helper_read(groupName, storageType, expireSeconds);
3056
- return (content !== null && content !== '') ? content : defaultVal;
3057
- }
3058
- set(groupName, content, storageType = 'localStorage'){
3059
- this.helper_write(groupName, content, storageType);
3060
- }
3061
- delete(groupName, storageType = 'localStorage'){
3062
- this.helper_delete(groupName, storageType);
3063
- }
3064
- getChild(groupName, optName, defaultVal = null, storageType = 'localStorage', expireSeconds = 0){
3065
- // todo: individual sub-item expiration
3066
- const content = this.get(groupName, '{}', storageType, expireSeconds);
3067
- const json = JSON.parse(content);
3068
- return (optName in json) ? json[optName] : defaultVal;
3069
- }
3070
- setChild(groupName, optName, val, storageType = 'localStorage'){
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
-
3048
+ delete(optName){
3049
+ const storage = window.localStorage;
3050
+ storage.removeItem(appName + '_' + optName);
3051
+ storage.removeItem(appName + '_' + optName + '_t');
3052
+ return true;
3053
+ }
3054
+ // ################ child methods ################## //
3055
+ get_child(optName, subKeyName, defaultVal = null, expireSeconds = 0){
3056
+ return this.parentClass.helper_get_child(this, optName, subKeyName, defaultVal, expireSeconds);
3057
+ }
3058
+ set_child(optName, subKeyName, val){
3059
+ return this.parentClass.helper_set_child(this, optName, subKeyName, val);
3060
+ }
3061
+ delete_child(optName, subKeyName){
3062
+ return this.parentClass.helper_delete_child(this, optName, subKeyName);
3063
+ }
3064
+ // ########################################### //
3065
+ })(this);
3085
3066
 
3067
+
3068
+ // server-side caching
3086
3069
  file = new (class {
3087
3070
  parentClass = null;
3088
3071
  constructor(parentClass){
@@ -3090,15 +3073,38 @@ class PuvoxLibrary {
3090
3073
  }
3091
3074
  mainClass() { return this.parentClass.parentClass; }
3092
3075
 
3093
- // ########## CACHE DIRS (server-side JS) ##########
3076
+ // ###################
3094
3077
  customCacheDir = null;
3095
- get_dir(){
3078
+ file_path(optName) {
3096
3079
  if (!this.customCacheDir){
3097
- this.customCacheDir = this.mainClass().file.tempDir();
3080
+ this.customCacheDir = this.mainClass().file.tempDir() + this.mainClass().getAppName() + '/';
3098
3081
  }
3099
- let finaldir = this.mainClass().trailingSlash(this.customCacheDir + this.mainClass().getAppName() + '_cache_');
3100
- return finaldir;
3082
+ return this.customCacheDir + optName + '.json';
3083
+ }
3084
+ get(optName, defaultValue = null, decode = true, expire_seconds=0)
3085
+ {
3086
+ return this.mainClass().file.readCustom(this.file_path(optName), defaultValue, decode, expire_seconds);
3087
+ }
3088
+ set(optName, content)
3089
+ {
3090
+ return this.mainClass().file.write(this.file_path(optName), content);
3091
+ }
3092
+ delete (optName) {
3093
+ return this.mainClass().file.delete(this.file_path(optName));
3101
3094
  }
3095
+ // ################ child methods ################## //
3096
+ get_child(optName, subKeyName, defaultVal = null, expireSeconds = 0){
3097
+ return this.parentClass.helper_get_child(this, optName, subKeyName, defaultVal, expireSeconds);
3098
+ }
3099
+ set_child(optName, subKeyName, val){
3100
+ return this.parentClass.helper_set_child(this, optName, subKeyName, val);
3101
+ }
3102
+ delete_child(optName, subKeyName){
3103
+ return this.parentClass.helper_delete_child(this, optName, subKeyName);
3104
+ }
3105
+ // #############################################
3106
+
3107
+ // old
3102
3108
  set_dir(dir, auto_clear_seconds=null){
3103
3109
  if(dir) this.customCacheDir = dir;
3104
3110
  const res = this.mainClass().file.createDirectory(this.customCacheDir);
@@ -3116,69 +3122,8 @@ class PuvoxLibrary {
3116
3122
  const filePath = this.get_dir() + uniqFileName + "_tmp"; //"/".
3117
3123
  return filePath;
3118
3124
  }
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
3125
 
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
- // },
3126
+ // ids
3182
3127
  containerDefaultPrefix = "_cached_ids_";
3183
3128
  tempIds = {};
3184
3129
  idForContent(slugOrContent){
@@ -3210,6 +3155,26 @@ class PuvoxLibrary {
3210
3155
  }
3211
3156
  return false;
3212
3157
  }
3158
+ //
3159
+ // writeFileAppendJson(filePath, jsonContent, callback){
3160
+ // try{
3161
+ // var callback = callback || function(){};
3162
+ // var self = this;
3163
+ // this.mainClass().modules('fs').readFile(filePath, 'utf8', function(err,data) {
3164
+ // let json = {};
3165
+ // if (typeof data !="undefined" && data!=''){
3166
+ // json=JSON.parse(data);
3167
+ // }
3168
+ // let jsonNew = self.jsonConcat(json, jsonContent);
3169
+ // let content = JSON.stringify(jsonNew);
3170
+ // this.mainClass().modules('fs').writeFile(filePath, content, 'utf8', function(callback_) {
3171
+ // });
3172
+ // });
3173
+ // }
3174
+ // catch(e){
3175
+ // console.log("writeFileAppendJson", e);
3176
+ // }
3177
+ // },
3213
3178
  })(this);
3214
3179
  })(this);
3215
3180
 
@@ -3289,16 +3254,40 @@ class PuvoxLibrary {
3289
3254
  }
3290
3255
  return true;
3291
3256
  }
3292
- read(filePath, defaultContent = ''){
3257
+ read(filePath, defaultValue = ''){
3293
3258
  if (!this.exists(filePath)){
3294
- return defaultContent;
3259
+ return defaultValue;
3295
3260
  }
3296
3261
  return this.fs().readFileSync(filePath, 'utf8');
3297
3262
  }
3263
+ readCustom(filePath, defaultValue = '', decode = true, expireSeconds = 0){
3264
+ if (!this.exists(filePath)){
3265
+ return defaultValue;
3266
+ }
3267
+ else {
3268
+ if ( this.mtime(filePath) + expireSeconds*1000 < (new Date()).getTime() ){
3269
+ this.unlink(filePath);
3270
+ return defaultValue;
3271
+ }
3272
+ else{
3273
+ const cont = this.read(filePath, null);
3274
+ // if specifically array, then on empty, reckon as array
3275
+ if (cont===null) {
3276
+ return defaultValue;
3277
+ }
3278
+ if (decode){
3279
+ try { return JSON.parse(cont); }
3280
+ catch(ex){ }
3281
+ }
3282
+ return cont;
3283
+ }
3284
+ }
3285
+ }
3298
3286
  write(filePath, content){
3299
3287
  const dir = this.path().dirname(filePath);
3300
3288
  this.createDirectory(dir);
3301
- this.fs().writeFileSync(filePath, content, 'utf8', function(err){
3289
+ const finalContent = this.mainClass().stringifyForWrite(content);
3290
+ return this.fs().writeFileSync(filePath, finalContent, 'utf8', function(err){
3302
3291
  if (err) throw err;
3303
3292
  });
3304
3293
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puvox-library",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "library-class-javascript",
5
5
  "main": "library_standard.js",
6
6
  "scripts": {