puvox-library 1.0.54 → 1.0.56
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 +72 -44
- package/package.json +1 -1
package/library_standard.js
CHANGED
@@ -148,6 +148,9 @@ const puvox_library =
|
|
148
148
|
}
|
149
149
|
return out
|
150
150
|
},
|
151
|
+
sortByValuesIntoArray(obj, ascending = true){
|
152
|
+
return Object.entries(obj).sort((a, b) => ascending ? a[1] - b[1] : b[1] - a[1]);
|
153
|
+
},
|
151
154
|
stringArrayToNumeric(arr){
|
152
155
|
let newArr = [];
|
153
156
|
for(let i=0; i<arr.length; i++){
|
@@ -941,6 +944,27 @@ const puvox_library =
|
|
941
944
|
} else {
|
942
945
|
return [1900 + dt.getYear(), dt.getMonth()+1, dt.getDate(), dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMilliseconds()];
|
943
946
|
}
|
947
|
+
},
|
948
|
+
getYMDHISFfromDateWithZeros(dt, utc=true){
|
949
|
+
let y, M, d, h, m, s, f;
|
950
|
+
if (utc) {
|
951
|
+
y = dt.getUTCFullYear();
|
952
|
+
M = dt.getUTCMonth()+1;
|
953
|
+
d = dt.getUTCDate();
|
954
|
+
h = dt.getUTCHours();
|
955
|
+
m = dt.getUTCMinutes();
|
956
|
+
s = dt.getUTCSeconds();
|
957
|
+
f = dt.getUTCMilliseconds();
|
958
|
+
} else {
|
959
|
+
y = 1900 + dt.getYear();
|
960
|
+
M = dt.getMonth()+1;
|
961
|
+
d = dt.getDate();
|
962
|
+
h = dt.getHours();
|
963
|
+
m = dt.getMinutes();
|
964
|
+
s = dt.getSeconds();
|
965
|
+
f = dt.getMilliseconds();
|
966
|
+
}
|
967
|
+
return [y.toString(), (M<10?'0':'')+M.toString(), (d<10?'0':'')+d.toString(), (h<10?'0':'')+h.toString(), (m<10?'0':'')+m.toString(), (s<10?'0':'')+s.toString(), (f<10?'00':(f<100?'0':''))+f.toString()];
|
944
968
|
},
|
945
969
|
prefixWithZero(num, digits){
|
946
970
|
return (digits===1 ? num : (digits===2 ? (num < 10 ? "0"+num : num ) : (digits===3 ? (num < 10 ? "00"+num : (num < 100 ? "0"+num : num ) ) : num ) ) ).toString();
|
@@ -3204,9 +3228,9 @@ const puvox_library =
|
|
3204
3228
|
extend(...args) { return Object.assign ({}, ...args) ;}, // NB: side-effect free
|
3205
3229
|
clone(x){ return (this.isArray (x) ? Array.from (x) : this.extend (x)) ;},
|
3206
3230
|
index(x) { return new Set (this.values (x));},
|
3207
|
-
ordered
|
3231
|
+
ordered(x) { return x;}, // a stub to keep assoc keys in order (in JS it does nothing, it's mostly for Python)
|
3208
3232
|
unique(x) { return Array.from (this.index (x));},
|
3209
|
-
arrayConcat
|
3233
|
+
arrayConcat (a, b) { return a.concat (b);},
|
3210
3234
|
inArray (needle, haystack) {
|
3211
3235
|
return haystack.includes (needle);
|
3212
3236
|
},
|
@@ -3255,32 +3279,35 @@ const puvox_library =
|
|
3255
3279
|
}
|
3256
3280
|
return out;
|
3257
3281
|
},
|
3258
|
-
sortBy
|
3259
|
-
|
3260
|
-
|
3261
|
-
|
3262
|
-
|
3263
|
-
|
3264
|
-
|
3265
|
-
|
3266
|
-
|
3267
|
-
|
3268
|
-
|
3269
|
-
|
3270
|
-
|
3271
|
-
|
3272
|
-
|
3273
|
-
|
3274
|
-
|
3275
|
-
|
3276
|
-
|
3277
|
-
|
3278
|
-
|
3279
|
-
|
3280
|
-
|
3281
|
-
|
3282
|
-
|
3283
|
-
|
3282
|
+
sortBy (array, key, descending = false, direction = descending ? -1 : 1) {
|
3283
|
+
return array.sort ((a, b) => {
|
3284
|
+
if (a[key] < b[key]) {
|
3285
|
+
return -direction;
|
3286
|
+
} else if (a[key] > b[key]) {
|
3287
|
+
return direction;
|
3288
|
+
} else {
|
3289
|
+
return 0;
|
3290
|
+
}
|
3291
|
+
});
|
3292
|
+
},
|
3293
|
+
sortBy2 (array, key1, key2, descending = false, direction = descending ? -1 : 1) {
|
3294
|
+
return array.sort ((a, b) => {
|
3295
|
+
if (a[key1] < b[key1]) {
|
3296
|
+
return -direction;
|
3297
|
+
} else if (a[key1] > b[key1]) {
|
3298
|
+
return direction;
|
3299
|
+
} else {
|
3300
|
+
if (a[key2] < b[key2]) {
|
3301
|
+
return -direction;
|
3302
|
+
} else if (a[key2] > b[key2]) {
|
3303
|
+
return direction;
|
3304
|
+
} else {
|
3305
|
+
return 0;
|
3306
|
+
}
|
3307
|
+
}
|
3308
|
+
});
|
3309
|
+
},
|
3310
|
+
flatten (x, out = []) {
|
3284
3311
|
for (const v of x) {
|
3285
3312
|
if (this.isArray (v)) {
|
3286
3313
|
this.flatten (v, out);
|
@@ -3288,7 +3315,6 @@ const puvox_library =
|
|
3288
3315
|
out.push (v);
|
3289
3316
|
}
|
3290
3317
|
}
|
3291
|
-
|
3292
3318
|
return out;
|
3293
3319
|
},
|
3294
3320
|
pluck(x, k) { return this.values (x).filter ((v) => k in v).map ((v) => v[k]);},
|
@@ -3332,10 +3358,10 @@ const puvox_library =
|
|
3332
3358
|
isNumber: Number.isFinite,
|
3333
3359
|
isInteger: Number.isInteger,
|
3334
3360
|
isArray: Array.isArray,
|
3335
|
-
hasProps
|
3336
|
-
isString
|
3337
|
-
isObject
|
3338
|
-
isRegExp
|
3361
|
+
hasProps (o){ return ((o !== undefined) && (o !== null));},
|
3362
|
+
isString (s){ return (typeof s === 'string');},
|
3363
|
+
isObject (o){ return ((o !== null) && (typeof o === 'object'));},
|
3364
|
+
isRegExp (o){ return (o instanceof RegExp);},
|
3339
3365
|
isDictionary(o ){return (this.isObject (o) && (Object.getPrototypeOf (o) === Object.prototype) && !this.isArray (o) && !this.isRegExp (o));},
|
3340
3366
|
isStringCoercible(x){ return ((this.hasProps (x) && x.toString) || this.isNumber (x));},
|
3341
3367
|
prop (o, k) { return (this.isObject (o) && o[k] !== '' && o[k] !== null ? o[k] : undefined);},
|
@@ -3372,12 +3398,14 @@ const puvox_library =
|
|
3372
3398
|
const offset = timestamp % ms
|
3373
3399
|
return timestamp - offset + ((direction === ROUND_UP) ? ms : 0);
|
3374
3400
|
},
|
3375
|
-
json
|
3376
|
-
isJsonEncodedObject
|
3377
|
-
|
3378
|
-
|
3379
|
-
|
3380
|
-
|
3401
|
+
json(data, params = undefined) { return JSON.stringify (data); },
|
3402
|
+
isJsonEncodedObject (object) {
|
3403
|
+
return (
|
3404
|
+
(typeof object === 'string') &&
|
3405
|
+
(object.length >= 2) &&
|
3406
|
+
((object[0] === '{') || (object[0] === '['))
|
3407
|
+
);
|
3408
|
+
},
|
3381
3409
|
//htmlentities
|
3382
3410
|
encode_html_entities (content) {
|
3383
3411
|
return content.replace(/[\u00A0-\u9999<>\&]/g, function(i) {
|
@@ -3400,13 +3428,13 @@ const puvox_library =
|
|
3400
3428
|
isNode: !(this.isBrowser || this.isWebWorker),
|
3401
3429
|
defaultFetch: fetch,
|
3402
3430
|
//string
|
3403
|
-
uuid
|
3404
|
-
capitalize
|
3405
|
-
strip
|
3431
|
+
uuid (a) { return a ? (a ^ Math.random () * 16 >> a / 4).toString (16) : ([1e7]+-1e3+-4e3+-8e3+-1e11).replace (/[018]/g, uuid);},
|
3432
|
+
capitalize (s) {return s.length ? (s.charAt (0).toUpperCase () + s.slice (1)) : s;},
|
3433
|
+
strip (s) { return s.replace(/^\s+|\s+$/g, '');},
|
3406
3434
|
// time
|
3407
|
-
now: Date.now,
|
3435
|
+
now : Date.now,
|
3408
3436
|
milliseconds: Date.now, // milliseconds(){ return (new Date().getTime()); },
|
3409
|
-
seconds
|
3437
|
+
seconds() { return Math.floor (Date.now () / 1000);},
|
3410
3438
|
// endregion: ####### from CCXT ##########
|
3411
3439
|
|
3412
3440
|
|