utilitas 2001.1.74 → 2001.1.75

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/lib/bot.mjs CHANGED
@@ -11,7 +11,7 @@ const [ // https://limits.tginfo.me/en
11
11
  BOT_SEND, provider, signals, MESSAGE_LENGTH_LIMIT, EMOJI_THINKING,
12
12
  PARSE_MODE_MD, BOT
13
13
  ] = [
14
- 'BOT_SEND', 'TELEGRAM', ['SIGINT', 'SIGTERM'], parseInt(4096 * 0.95),
14
+ 'BOT_SEND', 'TELEGRAM', ['SIGINT', 'SIGTERM'], parseInt(4096 * 0.93), // ~= 3800
15
15
  '💬', 'Markdown', '🤖',
16
16
  ];
17
17
 
@@ -20,9 +20,8 @@ const parse_mode = PARSE_MODE_MD;
20
20
  let bot;
21
21
 
22
22
  const paging = (message, options) => {
23
- options?.onProgress
24
- && (message = message?.length ? `${message} █` : EMOJI_THINKING)
25
- const [pages, page, size] = [[], [], ~~options?.size || MESSAGE_LENGTH_LIMIT];
23
+ let [pages, page, size, codeMark] =
24
+ [[], [], ~~options?.size || MESSAGE_LENGTH_LIMIT, ''];
26
25
  const submit = () => {
27
26
  const content = trim(lines(page));
28
27
  content && pages.push(content + (codeMark ? '\n```' : ''));
@@ -32,21 +31,24 @@ const paging = (message, options) => {
32
31
  codeMark = '';
33
32
  }
34
33
  };
35
- let codeMark = '';
36
34
  while ((message || '').length) {
37
- let n = message.indexOf('\n');
38
- n === -1 && (n = message.length);
39
- const cat = n > size ? '...' : '';
40
- if ((!cat && lines(page).length + n > size)) {
41
- submit();
35
+ let n = message.indexOf('\n'); // check next line break
36
+ n === -1 && (n = message.length); // a single line remaining
37
+ const cat = n > size ? '...' : ''; // the row length exceeds the limit
38
+ const cur = lines(page).length; // get current page length
39
+ if (!cat && cur + n > size) {
40
+ submit(); // line length ok, but the current + next line will exceed
42
41
  continue;
43
- }
44
- const cut = cat ? (size - cat.length) : (n + 1);
42
+ } // cut as much as possible vs cut line by line
43
+ const cut = cat ? (size - cur - cat.length) : (n + 1);
45
44
  const line = message.substring(0, cut).trimEnd() + cat;
46
45
  page.push(line);
47
46
  /^```.{0,20}$/.test(line) && (codeMark = codeMark ? '' : line);
48
- message = message.slice(cut);
49
- cat && (message = cat + message.trimStart());
47
+ message = message.slice(cut); // cut message
48
+ if (cat) {
49
+ message = cat + message.trimStart(); // tidy up
50
+ submit(); // submit if line break is needed
51
+ }
50
52
  }
51
53
  submit();
52
54
  return pages.map((p, i) => (
package/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.74",
4
+ "version": "2001.1.75",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.74",
4
+ "version": "2001.1.75",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",