@mycroblog/mybot 0.0.0-placeholder.0
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 +269 -0
- package/dist/bot.d.ts +199 -0
- package/dist/bot.js +760 -0
- package/dist/budget.d.ts +45 -0
- package/dist/budget.js +141 -0
- package/dist/context.d.ts +158 -0
- package/dist/context.js +255 -0
- package/dist/dispatch.d.ts +60 -0
- package/dist/dispatch.js +168 -0
- package/dist/every.d.ts +55 -0
- package/dist/every.js +22 -0
- package/dist/filestore.d.ts +17 -0
- package/dist/filestore.js +95 -0
- package/dist/handler.d.ts +42 -0
- package/dist/handler.js +93 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +14 -0
- package/dist/logger.d.ts +12 -0
- package/dist/logger.js +18 -0
- package/dist/schedule.d.ts +36 -0
- package/dist/schedule.js +187 -0
- package/dist/store.d.ts +72 -0
- package/dist/store.js +115 -0
- package/dist/testing/clock.d.ts +32 -0
- package/dist/testing/clock.js +104 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/server.d.ts +156 -0
- package/dist/testing/server.js +512 -0
- package/dist/text.d.ts +6 -0
- package/dist/text.js +75 -0
- package/package.json +48 -0
package/dist/text.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/** The named character references that the server's sanitized HTML uses, and those common in text. */
|
|
3
|
+
const namedReferences = {
|
|
4
|
+
amp: "&",
|
|
5
|
+
lt: "<",
|
|
6
|
+
gt: ">",
|
|
7
|
+
quot: '"',
|
|
8
|
+
apos: "'",
|
|
9
|
+
nbsp: " ",
|
|
10
|
+
};
|
|
11
|
+
/** Decodes the character references of HTML text: numeric ones, and the named ones of namedReferences. */
|
|
12
|
+
function unescape(text) {
|
|
13
|
+
return text.replaceAll(/&(#[xX][0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (whole, ref) => {
|
|
14
|
+
if (ref.startsWith("#")) {
|
|
15
|
+
const code = ref[1] === "x" || ref[1] === "X" ? Number.parseInt(ref.slice(2), 16) : Number.parseInt(ref.slice(1), 10);
|
|
16
|
+
return code > 0 && code <= 0x10ffff && !(code >= 0xd800 && code <= 0xdfff) ? String.fromCodePoint(code) : "�";
|
|
17
|
+
}
|
|
18
|
+
return namedReferences[ref] ?? whole;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** Whether c, after a '<', starts a tag, a closing tag, a comment, or a declaration. */
|
|
22
|
+
function opensTag(c) {
|
|
23
|
+
return c !== undefined && /^[/!?a-zA-Z]$/.test(c);
|
|
24
|
+
}
|
|
25
|
+
/** The lowercase name of an opening tag from what is between its < and >, "" for a closing tag, a comment, or a declaration. */
|
|
26
|
+
function tagName(tag) {
|
|
27
|
+
if (!/^\p{L}/u.test(tag))
|
|
28
|
+
return "";
|
|
29
|
+
const end = tag.search(/[\s/]/);
|
|
30
|
+
return (end >= 0 ? tag.slice(0, end) : tag).toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Turns the HTML content of a post into plain text: the text of every element, mentions and links as they read
|
|
34
|
+
* (`@alice`, `https://example.com/`), line breaks for <br> and between paragraphs, and character references decoded.
|
|
35
|
+
* It is for reading a post, not for showing it: nothing of the markup survives.
|
|
36
|
+
*/
|
|
37
|
+
export function plainText(content) {
|
|
38
|
+
let out = "";
|
|
39
|
+
let paragraphs = 0;
|
|
40
|
+
let rest = content;
|
|
41
|
+
while (rest !== "") {
|
|
42
|
+
const i = rest.indexOf("<");
|
|
43
|
+
if (i < 0) {
|
|
44
|
+
out += unescape(rest);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
out += unescape(rest.slice(0, i));
|
|
48
|
+
rest = rest.slice(i);
|
|
49
|
+
if (rest.length < 2 || !opensTag(rest[1])) {
|
|
50
|
+
// A '<' that opens no tag, such as in "1 < 2", is text.
|
|
51
|
+
out += "<";
|
|
52
|
+
rest = rest.slice(1);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const end = rest.indexOf(">");
|
|
56
|
+
if (end < 0) {
|
|
57
|
+
out += unescape(rest);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
switch (tagName(rest.slice(1, end))) {
|
|
61
|
+
case "br":
|
|
62
|
+
out += "\n";
|
|
63
|
+
break;
|
|
64
|
+
case "p":
|
|
65
|
+
if (paragraphs > 0)
|
|
66
|
+
out += "\n\n";
|
|
67
|
+
paragraphs++;
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
rest = rest.slice(end + 1);
|
|
73
|
+
}
|
|
74
|
+
return out.trim();
|
|
75
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mycroblog/mybot",
|
|
3
|
+
"version": "0.0.0-placeholder.0",
|
|
4
|
+
"description": "Build bots for mycroblog/my on @mycroblog/mykit: event handlers, commands, catch-up without duplicates, and polite defaults",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/mycroblog/my.git",
|
|
9
|
+
"directory": "pkg/mybot/ts"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"@mycroblog/source": "./src/index.ts",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./testing": {
|
|
20
|
+
"@mycroblog/source": "./src/testing/index.ts",
|
|
21
|
+
"types": "./dist/testing/index.d.ts",
|
|
22
|
+
"default": "./dist/testing/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"typecheck": "tsc -p tsconfig.lib.json --incremental --tsBuildInfoFile node_modules/.cache/tsc/tsconfig.lib.tsbuildinfo && tsc -p tsconfig.test.json --incremental --tsBuildInfoFile node_modules/.cache/tsc/tsconfig.test.tsbuildinfo && tsc -p tsconfig.examples.json --incremental --tsBuildInfoFile node_modules/.cache/tsc/tsconfig.examples.tsbuildinfo",
|
|
33
|
+
"lint": "oxlint",
|
|
34
|
+
"test": "bun test --conditions=@mycroblog/source",
|
|
35
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@mycroblog/mykit": "0.0.0-placeholder.0",
|
|
39
|
+
"croner": "10.0.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/bun": "1.4.2",
|
|
43
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
44
|
+
"oxlint": "1.87.0",
|
|
45
|
+
"oxlint-tsgolint": "7.0.2003",
|
|
46
|
+
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
47
|
+
}
|
|
48
|
+
}
|