puvox-library 1.0.53 → 1.0.55
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 +52 -45
- 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++){
|
@@ -2641,8 +2644,8 @@ const puvox_library =
|
|
2641
2644
|
if (!this.startsWith(chat_id, '-100')) chat_id = '-100' + chat_id;
|
2642
2645
|
text = this.br2nl(text);
|
2643
2646
|
text = this.stripTags(text,'<b><strong><i><em><u><ins><s><strike><del><a><code><pre>'); // allowed: https://core.telegram.org/bots/api#html-style
|
2644
|
-
text = text.substring(0, 4095); //max telegram message length 4096
|
2645
2647
|
text = this.encode_html_entities(text);
|
2648
|
+
text = text.substring(0, 4095); //max telegram message length 4096
|
2646
2649
|
const requestOpts = Object.assign({'chat_id':chat_id, 'text':text}, extra_opts);
|
2647
2650
|
delete requestOpts['cache'];
|
2648
2651
|
delete requestOpts['is_repeated_call'];
|
@@ -3204,9 +3207,9 @@ const puvox_library =
|
|
3204
3207
|
extend(...args) { return Object.assign ({}, ...args) ;}, // NB: side-effect free
|
3205
3208
|
clone(x){ return (this.isArray (x) ? Array.from (x) : this.extend (x)) ;},
|
3206
3209
|
index(x) { return new Set (this.values (x));},
|
3207
|
-
ordered
|
3210
|
+
ordered(x) { return x;}, // a stub to keep assoc keys in order (in JS it does nothing, it's mostly for Python)
|
3208
3211
|
unique(x) { return Array.from (this.index (x));},
|
3209
|
-
arrayConcat
|
3212
|
+
arrayConcat (a, b) { return a.concat (b);},
|
3210
3213
|
inArray (needle, haystack) {
|
3211
3214
|
return haystack.includes (needle);
|
3212
3215
|
},
|
@@ -3255,32 +3258,35 @@ const puvox_library =
|
|
3255
3258
|
}
|
3256
3259
|
return out;
|
3257
3260
|
},
|
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
|
-
|
3261
|
+
sortBy (array, key, descending = false, direction = descending ? -1 : 1) {
|
3262
|
+
return array.sort ((a, b) => {
|
3263
|
+
if (a[key] < b[key]) {
|
3264
|
+
return -direction;
|
3265
|
+
} else if (a[key] > b[key]) {
|
3266
|
+
return direction;
|
3267
|
+
} else {
|
3268
|
+
return 0;
|
3269
|
+
}
|
3270
|
+
});
|
3271
|
+
},
|
3272
|
+
sortBy2 (array, key1, key2, descending = false, direction = descending ? -1 : 1) {
|
3273
|
+
return array.sort ((a, b) => {
|
3274
|
+
if (a[key1] < b[key1]) {
|
3275
|
+
return -direction;
|
3276
|
+
} else if (a[key1] > b[key1]) {
|
3277
|
+
return direction;
|
3278
|
+
} else {
|
3279
|
+
if (a[key2] < b[key2]) {
|
3280
|
+
return -direction;
|
3281
|
+
} else if (a[key2] > b[key2]) {
|
3282
|
+
return direction;
|
3283
|
+
} else {
|
3284
|
+
return 0;
|
3285
|
+
}
|
3286
|
+
}
|
3287
|
+
});
|
3288
|
+
},
|
3289
|
+
flatten (x, out = []) {
|
3284
3290
|
for (const v of x) {
|
3285
3291
|
if (this.isArray (v)) {
|
3286
3292
|
this.flatten (v, out);
|
@@ -3288,7 +3294,6 @@ const puvox_library =
|
|
3288
3294
|
out.push (v);
|
3289
3295
|
}
|
3290
3296
|
}
|
3291
|
-
|
3292
3297
|
return out;
|
3293
3298
|
},
|
3294
3299
|
pluck(x, k) { return this.values (x).filter ((v) => k in v).map ((v) => v[k]);},
|
@@ -3332,10 +3337,10 @@ const puvox_library =
|
|
3332
3337
|
isNumber: Number.isFinite,
|
3333
3338
|
isInteger: Number.isInteger,
|
3334
3339
|
isArray: Array.isArray,
|
3335
|
-
hasProps
|
3336
|
-
isString
|
3337
|
-
isObject
|
3338
|
-
isRegExp
|
3340
|
+
hasProps (o){ return ((o !== undefined) && (o !== null));},
|
3341
|
+
isString (s){ return (typeof s === 'string');},
|
3342
|
+
isObject (o){ return ((o !== null) && (typeof o === 'object'));},
|
3343
|
+
isRegExp (o){ return (o instanceof RegExp);},
|
3339
3344
|
isDictionary(o ){return (this.isObject (o) && (Object.getPrototypeOf (o) === Object.prototype) && !this.isArray (o) && !this.isRegExp (o));},
|
3340
3345
|
isStringCoercible(x){ return ((this.hasProps (x) && x.toString) || this.isNumber (x));},
|
3341
3346
|
prop (o, k) { return (this.isObject (o) && o[k] !== '' && o[k] !== null ? o[k] : undefined);},
|
@@ -3372,12 +3377,14 @@ const puvox_library =
|
|
3372
3377
|
const offset = timestamp % ms
|
3373
3378
|
return timestamp - offset + ((direction === ROUND_UP) ? ms : 0);
|
3374
3379
|
},
|
3375
|
-
json
|
3376
|
-
isJsonEncodedObject
|
3377
|
-
|
3378
|
-
|
3379
|
-
|
3380
|
-
|
3380
|
+
json(data, params = undefined) { return JSON.stringify (data); },
|
3381
|
+
isJsonEncodedObject (object) {
|
3382
|
+
return (
|
3383
|
+
(typeof object === 'string') &&
|
3384
|
+
(object.length >= 2) &&
|
3385
|
+
((object[0] === '{') || (object[0] === '['))
|
3386
|
+
);
|
3387
|
+
},
|
3381
3388
|
//htmlentities
|
3382
3389
|
encode_html_entities (content) {
|
3383
3390
|
return content.replace(/[\u00A0-\u9999<>\&]/g, function(i) {
|
@@ -3400,13 +3407,13 @@ const puvox_library =
|
|
3400
3407
|
isNode: !(this.isBrowser || this.isWebWorker),
|
3401
3408
|
defaultFetch: fetch,
|
3402
3409
|
//string
|
3403
|
-
uuid
|
3404
|
-
capitalize
|
3405
|
-
strip
|
3410
|
+
uuid (a) { return a ? (a ^ Math.random () * 16 >> a / 4).toString (16) : ([1e7]+-1e3+-4e3+-8e3+-1e11).replace (/[018]/g, uuid);},
|
3411
|
+
capitalize (s) {return s.length ? (s.charAt (0).toUpperCase () + s.slice (1)) : s;},
|
3412
|
+
strip (s) { return s.replace(/^\s+|\s+$/g, '');},
|
3406
3413
|
// time
|
3407
|
-
now: Date.now,
|
3414
|
+
now : Date.now,
|
3408
3415
|
milliseconds: Date.now, // milliseconds(){ return (new Date().getTime()); },
|
3409
|
-
seconds
|
3416
|
+
seconds() { return Math.floor (Date.now () / 1000);},
|
3410
3417
|
// endregion: ####### from CCXT ##########
|
3411
3418
|
|
3412
3419
|
|