@yaebal/split 0.0.1
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/LICENSE +21 -0
- package/README.md +13 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +57 -0
- package/lib/index.js.map +1 -0
- package/lib/index.test.d.ts +2 -0
- package/lib/index.test.d.ts.map +1 -0
- package/lib/index.test.js +26 -0
- package/lib/index.test.js.map +1 -0
- package/package.json +48 -0
- package/src/index.test.ts +32 -0
- package/src/index.ts +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 neverlane
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Context, Message, Plugin } from "@yaebal/core";
|
|
2
|
+
/** telegram's per-message text limit. */
|
|
3
|
+
export declare const MAX_MESSAGE_LENGTH = 4096;
|
|
4
|
+
/**
|
|
5
|
+
* split `text` into chunks no longer than `max`, preferring to break on newlines.
|
|
6
|
+
* a single line longer than `max` is hard-split. pure — exported for testing.
|
|
7
|
+
*/
|
|
8
|
+
export declare function split(text: string, max?: number): string[];
|
|
9
|
+
export interface SplitControl {
|
|
10
|
+
/** send `text`, automatically split into telegram-sized chunks. */
|
|
11
|
+
sendLong(text: string, extra?: Record<string, unknown>): Promise<Message[]>;
|
|
12
|
+
/** reply with `text`, automatically split. */
|
|
13
|
+
replyLong(text: string, extra?: Record<string, unknown>): Promise<Message[]>;
|
|
14
|
+
}
|
|
15
|
+
/** adds `ctx.sendLong` / `ctx.replyLong` that split overlong text across messages. */
|
|
16
|
+
export declare function splitter(max?: number): Plugin<Context, SplitControl>;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE7D,yCAAyC;AACzC,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAqB,GAAG,MAAM,EAAE,CAgCtE;AAED,MAAM,WAAW,YAAY;IAC5B,mEAAmE;IACnE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5E,8CAA8C;IAC9C,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;CAC7E;AAED,sFAAsF;AACtF,wBAAgB,QAAQ,CAAC,GAAG,SAAqB,GAAG,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,CAsBhF"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** telegram's per-message text limit. */
|
|
2
|
+
export const MAX_MESSAGE_LENGTH = 4096;
|
|
3
|
+
/**
|
|
4
|
+
* split `text` into chunks no longer than `max`, preferring to break on newlines.
|
|
5
|
+
* a single line longer than `max` is hard-split. pure — exported for testing.
|
|
6
|
+
*/
|
|
7
|
+
export function split(text, max = MAX_MESSAGE_LENGTH) {
|
|
8
|
+
if (text.length <= max)
|
|
9
|
+
return [text];
|
|
10
|
+
const chunks = [];
|
|
11
|
+
let current = "";
|
|
12
|
+
const flush = () => {
|
|
13
|
+
if (current.length > 0) {
|
|
14
|
+
chunks.push(current);
|
|
15
|
+
current = "";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
for (const line of text.split("\n")) {
|
|
19
|
+
if (line.length > max) {
|
|
20
|
+
flush();
|
|
21
|
+
for (let i = 0; i < line.length; i += max)
|
|
22
|
+
chunks.push(line.slice(i, i + max));
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const candidate = current.length > 0 ? `${current}\n${line}` : line;
|
|
26
|
+
if (candidate.length > max) {
|
|
27
|
+
flush();
|
|
28
|
+
current = line;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
current = candidate;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
flush();
|
|
35
|
+
return chunks;
|
|
36
|
+
}
|
|
37
|
+
/** adds `ctx.sendLong` / `ctx.replyLong` that split overlong text across messages. */
|
|
38
|
+
export function splitter(max = MAX_MESSAGE_LENGTH) {
|
|
39
|
+
return (composer) => composer.derive((ctx) => {
|
|
40
|
+
const control = {
|
|
41
|
+
async sendLong(text, extra) {
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const part of split(text, max))
|
|
44
|
+
out.push(await ctx.send(part, extra));
|
|
45
|
+
return out;
|
|
46
|
+
},
|
|
47
|
+
async replyLong(text, extra) {
|
|
48
|
+
const out = [];
|
|
49
|
+
for (const part of split(text, max))
|
|
50
|
+
out.push(await ctx.reply(part, extra));
|
|
51
|
+
return out;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
return control;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,yCAAyC;AACzC,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,IAAY,EAAE,GAAG,GAAG,kBAAkB;IAC3D,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,MAAM,KAAK,GAAG,GAAG,EAAE;QAClB,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO,GAAG,EAAE,CAAC;QACd,CAAC;IACF,CAAC,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACvB,KAAK,EAAE,CAAC;YACR,KAAK,IAAI,CAAC,GAAG,C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GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;gBAE5E,OAAO,GAAG,CAAC;YACZ,CAAC;SACD,CAAC;QAEF,OAAO,OAAO,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { split } from "./index.js";
|
|
4
|
+
test("short text is returned as a single chunk", () => {
|
|
5
|
+
assert.deepEqual(split("hello"), ["hello"]);
|
|
6
|
+
assert.deepEqual(split(""), [""]);
|
|
7
|
+
});
|
|
8
|
+
test("splits on newlines, each chunk within the limit", () => {
|
|
9
|
+
const lines = Array.from({ length: 10 }, (_, i) => `line ${i} ${"x".repeat(40)}`);
|
|
10
|
+
const text = lines.join("\n");
|
|
11
|
+
const chunks = split(text, 100);
|
|
12
|
+
for (const c of chunks)
|
|
13
|
+
assert.ok(c.length <= 100, `chunk len ${c.length}`);
|
|
14
|
+
// rejoining preserves content (newline-joined chunks reconstruct the text)
|
|
15
|
+
assert.equal(chunks.join("\n"), text);
|
|
16
|
+
});
|
|
17
|
+
test("a single line longer than max is hard-split", () => {
|
|
18
|
+
const line = "a".repeat(250);
|
|
19
|
+
const chunks = split(line, 100);
|
|
20
|
+
assert.deepEqual(chunks, ["a".repeat(100), "a".repeat(100), "a".repeat(50)]);
|
|
21
|
+
});
|
|
22
|
+
test("does not split when exactly at the limit", () => {
|
|
23
|
+
const text = "a".repeat(100);
|
|
24
|
+
assert.deepEqual(split(text, 100), [text]);
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"m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,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACrD,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAE7B,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AAC5C,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yaebal/split",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "yaebal split — break long messages into Telegram-sized chunks.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"import": "./lib/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"lib",
|
|
16
|
+
"src"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@yaebal/core": "0.0.1"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "latest"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"telegram",
|
|
29
|
+
"telegram-bot",
|
|
30
|
+
"yaebal",
|
|
31
|
+
"split",
|
|
32
|
+
"long-message"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/neverlane/yaebal",
|
|
38
|
+
"directory": "packages/split"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.json",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
46
|
+
"test": "node --test lib"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { split } from "./index.js";
|
|
4
|
+
|
|
5
|
+
test("short text is returned as a single chunk", () => {
|
|
6
|
+
assert.deepEqual(split("hello"), ["hello"]);
|
|
7
|
+
assert.deepEqual(split(""), [""]);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("splits on newlines, each chunk within the limit", () => {
|
|
11
|
+
const lines = Array.from({ length: 10 }, (_, i) => `line ${i} ${"x".repeat(40)}`);
|
|
12
|
+
const text = lines.join("\n");
|
|
13
|
+
const chunks = split(text, 100);
|
|
14
|
+
|
|
15
|
+
for (const c of chunks) assert.ok(c.length <= 100, `chunk len ${c.length}`);
|
|
16
|
+
|
|
17
|
+
// rejoining preserves content (newline-joined chunks reconstruct the text)
|
|
18
|
+
assert.equal(chunks.join("\n"), text);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("a single line longer than max is hard-split", () => {
|
|
22
|
+
const line = "a".repeat(250);
|
|
23
|
+
const chunks = split(line, 100);
|
|
24
|
+
|
|
25
|
+
assert.deepEqual(chunks, ["a".repeat(100), "a".repeat(100), "a".repeat(50)]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("does not split when exactly at the limit", () => {
|
|
29
|
+
const text = "a".repeat(100);
|
|
30
|
+
|
|
31
|
+
assert.deepEqual(split(text, 100), [text]);
|
|
32
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Context, Message, Plugin } from "@yaebal/core";
|
|
2
|
+
|
|
3
|
+
/** telegram's per-message text limit. */
|
|
4
|
+
export const MAX_MESSAGE_LENGTH = 4096;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* split `text` into chunks no longer than `max`, preferring to break on newlines.
|
|
8
|
+
* a single line longer than `max` is hard-split. pure — exported for testing.
|
|
9
|
+
*/
|
|
10
|
+
export function split(text: string, max = MAX_MESSAGE_LENGTH): string[] {
|
|
11
|
+
if (text.length <= max) return [text];
|
|
12
|
+
const chunks: string[] = [];
|
|
13
|
+
|
|
14
|
+
let current = "";
|
|
15
|
+
const flush = () => {
|
|
16
|
+
if (current.length > 0) {
|
|
17
|
+
chunks.push(current);
|
|
18
|
+
current = "";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
for (const line of text.split("\n")) {
|
|
23
|
+
if (line.length > max) {
|
|
24
|
+
flush();
|
|
25
|
+
for (let i = 0; i < line.length; i += max) chunks.push(line.slice(i, i + max));
|
|
26
|
+
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const candidate = current.length > 0 ? `${current}\n${line}` : line;
|
|
31
|
+
|
|
32
|
+
if (candidate.length > max) {
|
|
33
|
+
flush();
|
|
34
|
+
current = line;
|
|
35
|
+
} else {
|
|
36
|
+
current = candidate;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
flush();
|
|
41
|
+
return chunks;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SplitControl {
|
|
45
|
+
/** send `text`, automatically split into telegram-sized chunks. */
|
|
46
|
+
sendLong(text: string, extra?: Record<string, unknown>): Promise<Message[]>;
|
|
47
|
+
/** reply with `text`, automatically split. */
|
|
48
|
+
replyLong(text: string, extra?: Record<string, unknown>): Promise<Message[]>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** adds `ctx.sendLong` / `ctx.replyLong` that split overlong text across messages. */
|
|
52
|
+
export function splitter(max = MAX_MESSAGE_LENGTH): Plugin<Context, SplitControl> {
|
|
53
|
+
return (composer) =>
|
|
54
|
+
composer.derive((ctx) => {
|
|
55
|
+
const control: SplitControl = {
|
|
56
|
+
async sendLong(text, extra) {
|
|
57
|
+
const out: Message[] = [];
|
|
58
|
+
|
|
59
|
+
for (const part of split(text, max)) out.push(await ctx.send(part, extra));
|
|
60
|
+
|
|
61
|
+
return out;
|
|
62
|
+
},
|
|
63
|
+
async replyLong(text, extra) {
|
|
64
|
+
const out: Message[] = [];
|
|
65
|
+
|
|
66
|
+
for (const part of split(text, max)) out.push(await ctx.reply(part, extra));
|
|
67
|
+
|
|
68
|
+
return out;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return control;
|
|
73
|
+
});
|
|
74
|
+
}
|