puvox-library 1.0.85 → 1.0.87
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.d.ts +3 -17
- package/library_standard.d.ts.map +1 -1
- package/library_standard.js +20 -16
- package/package.json +1 -1
package/library_standard.d.ts
CHANGED
@@ -1,20 +1,4 @@
|
|
1
1
|
export = PuvoxLibrary;
|
2
|
-
/**
|
3
|
-
*
|
4
|
-
* ############################################################################
|
5
|
-
* ############################# Our JS Library ############################
|
6
|
-
* ### Here we collect frequently used methods across our JS applications. ###
|
7
|
-
* ### (Some of them are generic javascript functions, some are for NodeJS) ###
|
8
|
-
* ############################################################################
|
9
|
-
*
|
10
|
-
* ########## Example usage: ##########
|
11
|
-
* const helpers = new PuvoxLibrary();
|
12
|
-
* console.log ( helpers.get_last_child_of_array(array) );
|
13
|
-
* console.log ( helpers.get_visitor_ip() );
|
14
|
-
* console.log ( helpers.telegramMessage("hello world", "1234567890", "BOTKEY123:456789") );
|
15
|
-
* ... etc
|
16
|
-
*
|
17
|
-
*/
|
18
2
|
declare class PuvoxLibrary {
|
19
3
|
constructor(appName: any);
|
20
4
|
selfMain: PuvoxLibrary;
|
@@ -221,7 +205,8 @@ declare class PuvoxLibrary {
|
|
221
205
|
splitByNotInside2(str: any, splitChar: any, notInsideCharStart: any, notInsideCharEnd: any): void;
|
222
206
|
getFromX_tillY_ExcudingQuotes(content: any, from: any, till: any, regex_index: any): string;
|
223
207
|
preg_quote(str: any, delimiter: any): string;
|
224
|
-
|
208
|
+
escapeRegex(string: any): any;
|
209
|
+
escapeRegExp2(string: any): any;
|
225
210
|
splitStringIntoChars(str: any): any;
|
226
211
|
empty(MyVar: any): boolean;
|
227
212
|
is_empty_or_undefined(MyVar: any): boolean;
|
@@ -353,6 +338,7 @@ declare class PuvoxLibrary {
|
|
353
338
|
IsMobileDevice(simpleORfull: any): any;
|
354
339
|
backToTopBind(el: any): void;
|
355
340
|
enable_jquery_errors(): void;
|
341
|
+
encode_chars(str: any, chars?: any[]): any;
|
356
342
|
telegramMessage(textOriginal: any, chat_id: any, bot_key: any, extra_opts?: {}): Promise<any>;
|
357
343
|
telegram_interval_ms: number;
|
358
344
|
telegram_last_sent_time: number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"library_standard.d.ts","sourceRoot":"","sources":["library_standard.js"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"library_standard.d.ts","sourceRoot":"","sources":["library_standard.js"],"names":[],"mappings":";AAmBA;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;IAigGE,+BAA4B;IA//F/B,2BAA2C;IAC3C,2BAAqE;IACrE,2BAA+H;IAC/H,+BAAiG;IACjG,0BAA+E;IA8/F5E,0BAA8C;IA5/FjD,0BAAkQ;IA6/F/P,0BAAgE;IA3/FnE,iCAGC;IAq/FE,6BAAuB;IAl/F1B,wCAA8E;IAC9E,kDAAyI;IACzI,yCAAgF;IAChF,mDAAmH;IAEnH,sCAMC;IACD,yBAEC;IACD,g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CHANGED
@@ -15,6 +15,8 @@
|
|
15
15
|
*
|
16
16
|
*/
|
17
17
|
|
18
|
+
const { response } = require("express");
|
19
|
+
|
18
20
|
class PuvoxLibrary {
|
19
21
|
selfMain = this;
|
20
22
|
|
@@ -1337,7 +1339,10 @@ class PuvoxLibrary {
|
|
1337
1339
|
preg_quote(str, delimiter) {
|
1338
1340
|
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&');
|
1339
1341
|
}
|
1340
|
-
|
1342
|
+
escapeRegex(string) {
|
1343
|
+
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
|
1344
|
+
}
|
1345
|
+
escapeRegExp2(string) {
|
1341
1346
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
1342
1347
|
}
|
1343
1348
|
|
@@ -2689,11 +2694,14 @@ class PuvoxLibrary {
|
|
2689
2694
|
}
|
2690
2695
|
}
|
2691
2696
|
|
2697
|
+
encode_chars(str, chars = []){
|
2698
|
+
chars.map(char => str = str.replace(new RegExp(this.escapeRegex(char), 'g'), encodeURIComponent(char)));
|
2699
|
+
return str;
|
2700
|
+
}
|
2692
2701
|
|
2693
2702
|
// region ### TELEGRAM FUNCTIONS ###
|
2694
2703
|
async telegramMessage(textOriginal, chat_id, bot_key, extra_opts={}){
|
2695
2704
|
if (!extra_opts) extra_opts = {};
|
2696
|
-
const is_repeated_call = 'is_repeated_call' in extra_opts;
|
2697
2705
|
if (! ('parse_mode' in extra_opts)){
|
2698
2706
|
extra_opts['parse_mode'] = 'html';
|
2699
2707
|
}
|
@@ -2707,17 +2715,11 @@ class PuvoxLibrary {
|
|
2707
2715
|
text = this.br2nl(text);
|
2708
2716
|
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
|
2709
2717
|
text = text.substring(0, 4095); //max telegram message length 4096
|
2718
|
+
//
|
2719
|
+
const is_repeated_call = ('is_repeated_call' in extra_opts);
|
2720
|
+
delete extra_opts['is_repeated_call'];
|
2710
2721
|
const requestOpts = Object.assign({'chat_id':chat_id, 'text':text}, extra_opts);
|
2711
|
-
|
2712
|
-
delete requestOpts['is_repeated_call'];
|
2713
|
-
let responseText = undefined;
|
2714
|
-
try {
|
2715
|
-
responseText = await this.getRemoteData('https://api.telegram.org/bot'+ bot_key +'/sendMessage', requestOpts); // pastebin_com/u0J1Cph3 //'sendMessage?'.http_build_query(opts, '');
|
2716
|
-
} catch (ex) {
|
2717
|
-
// todo: if html entities issue
|
2718
|
-
requestOpts.text = this.encode_html_entities(requestOpts.text);
|
2719
|
-
responseText = await this.getRemoteData('https://api.telegram.org/bot'+ bot_key +'/sendMessage', requestOpts);
|
2720
|
-
}
|
2722
|
+
let responseText = await this.getRemoteData('https://api.telegram.org/bot'+ bot_key +'/sendMessage', requestOpts); // pastebin_com/u0J1Cph3 //'sendMessage?'.http_build_query(opts, '');
|
2721
2723
|
try {
|
2722
2724
|
const responseJson = JSON.parse(responseText);
|
2723
2725
|
if (responseJson.ok){
|
@@ -2726,12 +2728,14 @@ class PuvoxLibrary {
|
|
2726
2728
|
// for some reason, if still unsupported format submitted, resubmit the plain format
|
2727
2729
|
//i.e. {"ok":false,"error_code":400,"description":"Bad Request: can't parse entities: Unsupported start tag \"br/\" at byte offset 43"}
|
2728
2730
|
else {
|
2731
|
+
if (!responseJson.description) {
|
2732
|
+
throw new Error('No description in response');
|
2733
|
+
}
|
2729
2734
|
if( responseJson.description.indexOf ('Bad Request: can\'t parse entities')> -1 ){
|
2730
2735
|
if ( ! is_repeated_call ){
|
2731
|
-
|
2732
|
-
|
2733
|
-
|
2734
|
-
return this.telegram_message(text, chat_id, bot_key, extraOpts2);
|
2736
|
+
text = "[SecondSend with stipped tags] \r\n" + this.encode_html_entities (this.stripTags(text));
|
2737
|
+
extra_opts['is_repeated_call'] = true;
|
2738
|
+
return await this.telegram_message(text, chat_id, bot_key, extra_opts);
|
2735
2739
|
}
|
2736
2740
|
}
|
2737
2741
|
return responseJson;
|