puvox-library 1.0.24 → 1.0.26
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 +54 -36
- package/package.json +1 -1
package/library_standard.js
CHANGED
@@ -828,30 +828,29 @@ const puvox_library =
|
|
828
828
|
let finalStr = (withT ? str.replace(' ', 'T') : str);
|
829
829
|
return withMS ? finalStr : finalStr.split('.')[0]; //2022-07-09 19:25:00.276
|
830
830
|
},
|
831
|
-
// in some langs, the date object has distinctions, so the two below needs separated methods
|
832
|
-
StringToDatetimeUtc(str, format, culture) { return new Date(str); },
|
833
|
-
StringToDatetimeLocal(str, format, culture) { return new Date(str); },
|
834
|
-
|
831
|
+
// in some langs, the date object has distinctions, so the two below needs separated methods. However, the "date" object returned from them, are same, just the representation can be local or UTC depending user.
|
832
|
+
StringToDatetimeUtc(str, format, culture) { return new Date(str); },
|
833
|
+
StringToDatetimeLocal(str, format, culture) { return new Date(str); },
|
834
|
+
DatetimeUtc() {
|
835
835
|
var now = new Date();
|
836
836
|
var utc = new Date(now.getTime()); // + now.getTimezoneOffset() * 60000 is not needed !!!!!!
|
837
837
|
return utc;
|
838
|
-
},
|
839
|
-
UtcDatetimeFrom(dt) { }, // DateTime
|
838
|
+
}, UtcDatetime() { return this.DatetimeUtc(); },
|
840
839
|
// UTC
|
841
|
-
|
840
|
+
TimestampUtc() {
|
842
841
|
return Math.floor(new Date().getTime());
|
843
|
-
},
|
842
|
+
}, UtcTimestamp() { return this.TimestampUtc(); },
|
844
843
|
//i.e. input: "2021-03-08 11:59:00" | output : 1650000000000 (milliseconds)
|
845
844
|
// [DONT CHANGE THIS FUNC, I'VE REVISED]
|
846
|
-
|
845
|
+
DatetimeToTimestampUtc(dt) {
|
847
846
|
let offset = this.getOffsetFromUtc();
|
848
847
|
return ((((new Date( dt )).getTime()) / 1000) + 14400 - offset * 60* 60) * 1000;
|
849
|
-
},
|
850
|
-
|
848
|
+
}, UtcTimestampFrom(dt) { return this.DatetimeToTimestampUtc(dt); },
|
849
|
+
TimestampUtcToDatetimeUtc(ts) {
|
851
850
|
var d = new Date(ts);
|
852
851
|
d.setHours(d.getHours());
|
853
852
|
return d;
|
854
|
-
},
|
853
|
+
}, UtcTimestampToUtcDatetime(ts) { return this.TimestampUtcToDatetimeUtc(ts); },
|
855
854
|
// shorthands
|
856
855
|
MaxDate(d1, d2, d3=null) {},
|
857
856
|
MinDate(d1, d2, d3=null) {},
|
@@ -1970,16 +1969,16 @@ const puvox_library =
|
|
1970
1969
|
parsePOST(request, callback)
|
1971
1970
|
{
|
1972
1971
|
if (request.method == 'POST') {
|
1973
|
-
let name='querystring'
|
1974
|
-
var qs = require(name);
|
1975
|
-
let stringData = '';
|
1976
|
-
request.on('data', function (data) {
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
});
|
1982
|
-
request.on('end', function(){ callback(qs.parse(stringData)); } );
|
1972
|
+
// let name='querystring';// deprecated by URLSearchParams
|
1973
|
+
// var qs = require(name);
|
1974
|
+
// let stringData = '';
|
1975
|
+
// request.on('data', function (data) {
|
1976
|
+
// stringData += data;
|
1977
|
+
// // Too much POST data, kill the connection! 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
|
1978
|
+
// if (stringData.length > 1e6)
|
1979
|
+
// request.connection.destroy();
|
1980
|
+
// });
|
1981
|
+
// request.on('end', function(){ callback(qs.parse(stringData)); } );
|
1983
1982
|
}
|
1984
1983
|
},
|
1985
1984
|
|
@@ -2407,6 +2406,26 @@ const puvox_library =
|
|
2407
2406
|
};
|
2408
2407
|
},
|
2409
2408
|
|
2409
|
+
compare(a, b, operator) {
|
2410
|
+
if(operator === '==') return a == b;
|
2411
|
+
else if (operator === '===') return a === b;
|
2412
|
+
else if (operator === '!=') return a != b;
|
2413
|
+
else if (operator === '!==') return a !== b;
|
2414
|
+
else if (operator === '>') return a > b;
|
2415
|
+
else if (operator === '>=') return a >= b;
|
2416
|
+
else if (operator === '<') return a < b;
|
2417
|
+
else if (operator === '<=') return a <= b;
|
2418
|
+
else throw "Unknown operator";
|
2419
|
+
},
|
2420
|
+
calculate(a, b, operator) {
|
2421
|
+
if(operator === '+') return a + b;
|
2422
|
+
else if (operator === '-') return a - b;
|
2423
|
+
else if (operator === '*') return a * b;
|
2424
|
+
else if (operator === '/') return a / b;
|
2425
|
+
else if (operator === '%') return a % b;
|
2426
|
+
else throw "Unknown operator";
|
2427
|
+
},
|
2428
|
+
|
2410
2429
|
// random NUMBER or STRINGS
|
2411
2430
|
RandomNum(maxNum) { return Math.floor((Math.random() * maxNum) + 1); },
|
2412
2431
|
|
@@ -2533,8 +2552,7 @@ const puvox_library =
|
|
2533
2552
|
openUrlInBrowser(url)
|
2534
2553
|
{
|
2535
2554
|
var cmd = (process.platform == 'darwin'? `open ${url}`: process.platform == 'win32'? `start ${url}`: `xdg-open ${url}`);
|
2536
|
-
|
2537
|
-
require(name).exec(cmd);
|
2555
|
+
require('child_process').exec(cmd);
|
2538
2556
|
},
|
2539
2557
|
|
2540
2558
|
stringify(obj_or_str){
|
@@ -2879,20 +2897,20 @@ const puvox_library =
|
|
2879
2897
|
|
2880
2898
|
// ################################################
|
2881
2899
|
// for node packs:_fs_instance :null,
|
2882
|
-
_required_instances : {},
|
2883
|
-
modules(name){
|
2884
|
-
|
2885
|
-
|
2886
|
-
|
2887
|
-
|
2888
|
-
|
2889
|
-
|
2890
|
-
},
|
2900
|
+
// _required_instances : {},
|
2901
|
+
// modules(name){
|
2902
|
+
// if (name in this._required_instances){
|
2903
|
+
// return this._required_instances[name];
|
2904
|
+
// } else {
|
2905
|
+
// this._required_instances[name] = require(name);
|
2906
|
+
// return this._required_instances[name];
|
2907
|
+
// }
|
2908
|
+
// },
|
2891
2909
|
file: {
|
2892
2910
|
parent() {return puvox_library;},
|
2893
|
-
fs() {return puvox_library.modules('fs')
|
2894
|
-
os() {return
|
2895
|
-
path() {return
|
2911
|
+
fs() {return require('fs');}, //puvox_library.modules('fs')
|
2912
|
+
os() {return require('os');},
|
2913
|
+
path() {return require('path');},
|
2896
2914
|
//
|
2897
2915
|
getTempDir(){ return this.os().tmpdir(); },
|
2898
2916
|
|