puvox-library 1.0.29 → 1.0.31
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/README.md +6 -3
- package/library_standard.js +23 -8
- package/package.json +1 -1
package/README.md
CHANGED
@@ -10,7 +10,10 @@ Include `<script src="https://unpkg.com/puvox-library"></script>` in your front-
|
|
10
10
|
|
11
11
|
## Examples
|
12
12
|
```
|
13
|
-
|
14
|
-
|
15
|
-
//
|
13
|
+
PuvoxLibrary.arrayValue ( {a:11, b:22, c:33}, 'c' ); // 33
|
14
|
+
PuvoxLibrary.arrayRemoveValue ( ["k", "z", "g"] , "z" ); // ["k", "g"]
|
15
|
+
PuvoxLibrary.randomNumber (length); // 29873433
|
16
|
+
PuvoxLibrary.removeKeys ( {a:11, b:22, c:33}, ['c'] ); // {a:11, b:22}
|
17
|
+
PuvoxLibrary.stringToArray ( {a:11, b:22, c:33}, ['c'] ); // {a:11, b:22}
|
18
|
+
// etc, numerous useful methods...
|
16
19
|
```
|
package/library_standard.js
CHANGED
@@ -442,9 +442,9 @@ const puvox_library =
|
|
442
442
|
}
|
443
443
|
return obj;
|
444
444
|
},
|
445
|
-
renameSubKey (obj, keyFrom, keyTo) {
|
445
|
+
renameSubKey (obj, keyFrom, keyTo, strict = false) {
|
446
446
|
for (const key of Object.keys(obj)) {
|
447
|
-
obj[key][keyTo] = obj[key][keyFrom];
|
447
|
+
obj[key][keyTo] = strict ? obj[key][keyFrom] : (obj[key][keyFrom] || null);
|
448
448
|
delete obj[key][keyFrom];
|
449
449
|
}
|
450
450
|
return obj;
|
@@ -1664,7 +1664,7 @@ const puvox_library =
|
|
1664
1664
|
// ============================= get basename of url ============================
|
1665
1665
|
basename(path) { return path.split('/').reverse()[0]; },
|
1666
1666
|
|
1667
|
-
|
1667
|
+
|
1668
1668
|
// ======== simple POPUP ======== https://github.com/ttodua/useful-javascript/ ==============
|
1669
1669
|
show_my_popup(TEXTorID, AdditionalStyles ){
|
1670
1670
|
TEXTorID=TEXTorID.trim(); var FirstChar= TEXTorID.charAt(0); var eName = TEXTorID.substr(1); if ('#'==FirstChar || '.'==FirstChar){ if('#'==FirstChar){var x=document.getElementById(eName);} else{var x=document.getElementsByClassName(eName)[0];}} else { var x=document.createElement('div');x.innerHTML=TEXTorID;} var randm_id=Math.floor((Math.random()*100000000));
|
@@ -2369,6 +2369,12 @@ const puvox_library =
|
|
2369
2369
|
RemoveHashString(str){ var hash=str.split("#")[1]; return str.replace("#"+hash,''); },
|
2370
2370
|
// ===================================================================//
|
2371
2371
|
|
2372
|
+
arrayRemoveValue(array, value) {
|
2373
|
+
const newArray = [...array];
|
2374
|
+
const index = newArray.indexOf(value);
|
2375
|
+
newArray.splice(index, 1);
|
2376
|
+
return newArray;
|
2377
|
+
},
|
2372
2378
|
|
2373
2379
|
getCharsFromStart(str, amount){
|
2374
2380
|
return str.substring(0, amount);
|
@@ -2467,9 +2473,10 @@ const puvox_library =
|
|
2467
2473
|
// random NUMBER or STRINGS
|
2468
2474
|
RandomNum(maxNum) { return Math.floor((Math.random() * maxNum) + 1); },
|
2469
2475
|
|
2470
|
-
random_number(
|
2476
|
+
random_number(Length) { var length= length || 5; return Math.floor((Math.random() * Math.pow(10, length)) + 1);},
|
2477
|
+
randomNumber(Length) {return this.random_number(length);},
|
2471
2478
|
random_number_minmax(min, max) { var min= min || 1; var max= max || 9999999999; return Math.floor(Math.random() * (max - min + 1)) + min;},
|
2472
|
-
randomString(
|
2479
|
+
randomString(Length) { var length= length || 5; return Math.random().toString(36).substr(2, length);},
|
2473
2480
|
//getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); },
|
2474
2481
|
|
2475
2482
|
shuffle_Word(word){
|
@@ -2722,9 +2729,6 @@ const puvox_library =
|
|
2722
2729
|
|
2723
2730
|
|
2724
2731
|
|
2725
|
-
|
2726
|
-
|
2727
|
-
|
2728
2732
|
async fetch(url, postOptions = null, opts = {}){
|
2729
2733
|
return await this.getRemoteData(url, postOptions, opts);
|
2730
2734
|
},
|
@@ -2749,6 +2753,17 @@ const puvox_library =
|
|
2749
2753
|
},
|
2750
2754
|
// if(setHashInAddress) { window.location.hash = id_or_Name; }
|
2751
2755
|
|
2756
|
+
|
2757
|
+
async downloadFile(url, path){
|
2758
|
+
const res = await this.fetch(url);
|
2759
|
+
const fileStream = this.file.fs().createWriteStream(path);
|
2760
|
+
await new Promise((resolve, reject) => {
|
2761
|
+
res.body.pipe(fileStream);
|
2762
|
+
res.body.on("error", reject);
|
2763
|
+
fileStream.on("finish", resolve);
|
2764
|
+
});
|
2765
|
+
},
|
2766
|
+
|
2752
2767
|
unTrailingSlash(str){
|
2753
2768
|
while (str.endsWith('/') || str.endsWith('\\')) {
|
2754
2769
|
str = str.slice(0, -1);
|