applesauce-content 0.0.0-next-20250723224513 → 0.0.0-next-20250726160247
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/package.json +3 -3
- package/dist/__tests__/exports.test.d.ts +0 -1
- package/dist/__tests__/exports.test.js +0 -14
- package/dist/__tests__/fake-user.d.ts +0 -9
- package/dist/__tests__/fake-user.js +0 -23
- package/dist/helpers/__test__/exports.test.d.ts +0 -1
- package/dist/helpers/__test__/exports.test.js +0 -13
- package/dist/helpers/__test__/regexp.test.d.ts +0 -1
- package/dist/helpers/__test__/regexp.test.js +0 -244
- package/dist/markdown/__tests__/exports.test.d.ts +0 -1
- package/dist/markdown/__tests__/exports.test.js +0 -11
- package/dist/nast/__tests__/exports.test.d.ts +0 -1
- package/dist/nast/__tests__/exports.test.js +0 -13
- package/dist/text/__tests__/exports.test.d.ts +0 -1
- package/dist/text/__tests__/exports.test.js +0 -22
- package/dist/text/__tests__/gallery.test.d.ts +0 -1
- package/dist/text/__tests__/gallery.test.js +0 -38
- package/dist/text/__tests__/hashtag.test.d.ts +0 -1
- package/dist/text/__tests__/hashtag.test.js +0 -48
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-content",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250726160247",
|
|
4
4
|
"description": "Unified plugins for processing event content",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@types/hast": "^3.0.4",
|
|
53
53
|
"@types/mdast": "^4.0.4",
|
|
54
54
|
"@types/unist": "^3.0.3",
|
|
55
|
-
"applesauce-core": "0.0.0-next-
|
|
55
|
+
"applesauce-core": "0.0.0-next-20250726160247",
|
|
56
56
|
"mdast-util-find-and-replace": "^3.0.2",
|
|
57
57
|
"nostr-tools": "^2.13",
|
|
58
58
|
"remark": "^15.0.1",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"typescript": "^5.8.3",
|
|
65
|
-
"applesauce-signers": "0.0.0-next-
|
|
65
|
+
"applesauce-signers": "0.0.0-next-20250726160247",
|
|
66
66
|
"vitest": "^3.2.3"
|
|
67
67
|
},
|
|
68
68
|
"funding": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import * as exports from "../index.js";
|
|
3
|
-
describe("exports", () => {
|
|
4
|
-
it("should export the expected functions", () => {
|
|
5
|
-
expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
|
|
6
|
-
[
|
|
7
|
-
"Helpers",
|
|
8
|
-
"Markdown",
|
|
9
|
-
"Nast",
|
|
10
|
-
"Text",
|
|
11
|
-
]
|
|
12
|
-
`);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SimpleSigner } from "applesauce-signers/signers/simple-signer";
|
|
2
|
-
import type { EventTemplate, NostrEvent } from "nostr-tools";
|
|
3
|
-
export declare class FakeUser extends SimpleSigner {
|
|
4
|
-
pubkey: string;
|
|
5
|
-
event(data?: Partial<EventTemplate>): NostrEvent;
|
|
6
|
-
note(content?: string, extra?: Partial<EventTemplate>): import("nostr-tools").Event;
|
|
7
|
-
profile(profile: any, extra?: Partial<EventTemplate>): import("nostr-tools").Event;
|
|
8
|
-
contacts(pubkeys?: string[]): import("nostr-tools").Event;
|
|
9
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { unixNow } from "applesauce-core/helpers";
|
|
2
|
-
import { SimpleSigner } from "applesauce-signers/signers/simple-signer";
|
|
3
|
-
import { finalizeEvent, getPublicKey, kinds } from "nostr-tools";
|
|
4
|
-
export class FakeUser extends SimpleSigner {
|
|
5
|
-
pubkey = getPublicKey(this.key);
|
|
6
|
-
event(data) {
|
|
7
|
-
return finalizeEvent({
|
|
8
|
-
kind: data?.kind ?? kinds.ShortTextNote,
|
|
9
|
-
content: data?.content || "",
|
|
10
|
-
created_at: data?.created_at ?? unixNow(),
|
|
11
|
-
tags: data?.tags || [],
|
|
12
|
-
}, this.key);
|
|
13
|
-
}
|
|
14
|
-
note(content = "Hello World", extra) {
|
|
15
|
-
return this.event({ kind: kinds.ShortTextNote, content, ...extra });
|
|
16
|
-
}
|
|
17
|
-
profile(profile, extra) {
|
|
18
|
-
return this.event({ kind: kinds.Metadata, content: JSON.stringify({ ...profile }), ...extra });
|
|
19
|
-
}
|
|
20
|
-
contacts(pubkeys = []) {
|
|
21
|
-
return this.event({ kind: kinds.Contacts, tags: pubkeys.map((p) => ["p", p]) });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import * as exports from "../index.js";
|
|
3
|
-
describe("exports", () => {
|
|
4
|
-
it("should export the expected functions", () => {
|
|
5
|
-
expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
|
|
6
|
-
[
|
|
7
|
-
"Expressions",
|
|
8
|
-
"Tokens",
|
|
9
|
-
"getMediaAttachmentURLsFromContent",
|
|
10
|
-
]
|
|
11
|
-
`);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { Expressions, Tokens } from "../regexp.js";
|
|
3
|
-
describe("Regular Expressions", () => {
|
|
4
|
-
describe("Expressions.link", () => {
|
|
5
|
-
it("should match valid HTTP URLs", () => {
|
|
6
|
-
const text = "Check out https://example.com";
|
|
7
|
-
const matches = Array.from(text.matchAll(Expressions.link));
|
|
8
|
-
expect(matches).toHaveLength(1);
|
|
9
|
-
expect(matches[0][0]).toBe("https://example.com");
|
|
10
|
-
});
|
|
11
|
-
it("should match valid HTTPS URLs with paths and query parameters", () => {
|
|
12
|
-
const text = "Visit https://example.com/path?query=value#fragment";
|
|
13
|
-
const matches = Array.from(text.matchAll(Expressions.link));
|
|
14
|
-
expect(matches).toHaveLength(1);
|
|
15
|
-
expect(matches[0][0]).toBe("https://example.com/path?query=value#fragment");
|
|
16
|
-
});
|
|
17
|
-
it("should match URLs with ports", () => {
|
|
18
|
-
const text = "Server at http://example.com:3000/api";
|
|
19
|
-
const matches = Array.from(text.matchAll(Expressions.link));
|
|
20
|
-
expect(matches).toHaveLength(1);
|
|
21
|
-
expect(matches[0][0]).toBe("http://example.com:3000/api");
|
|
22
|
-
});
|
|
23
|
-
it("should match multiple URLs in text", () => {
|
|
24
|
-
const text = "First https://example.com and second https://test.org/path";
|
|
25
|
-
const matches = Array.from(text.matchAll(Expressions.link));
|
|
26
|
-
expect(matches).toHaveLength(2);
|
|
27
|
-
expect(matches[0][0]).toBe("https://example.com");
|
|
28
|
-
expect(matches[1][0]).toBe("https://test.org/path");
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
describe("Expressions.cashu", () => {
|
|
32
|
-
const cashuA = "cashuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHBzOi8vdGVzdG51dC5jYXNodS5zcGFjZSIsInByb29mcyI6W3sic2VjcmV0IjoiMTFhYmQxZjY1OWI1MzE5MjhjYTEwMmEyYjgxYzQ2MTQxYzY3NTg1MjU2ZmZmZGNlNzRiMWY4NWFmZWRkM2M2NiIsIkMiOiIwM2FmYjZiMzE5YjAyYzkyODc3ZjkxY2VjMjM4NmNiZjcwMzVhZDRkMWFiNWUzNmRjY2VkNDdjZWY4NDRjYzNiMWUiLCJhbW91bnQiOjgsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSJ9XX1dLCJ1bml0Ijoic2F0In0";
|
|
33
|
-
const cashuB = "cashuBo2FteBtodHRwczovL3Rlc3RudXQuY2FzaHUuc3BhY2VhdWNzYXRhdIGiYWlIAJofKTJT5B5hcIOkYWEQYXN4QDQ4ZjIwNmM5ODI2NWQ2YjlmYTU1Zjc0ZjQ5ZDU0NjI1NTE4MDBjMDc4NjE1OWQ0YzE4ZDNmMWZiYzE0Nzc3MzhhY1ghA8xqu_uJfIZ-m5UdaauOX1owIFwXeNQ0zQlnLTFsdVaOYWSjYWVYINcRIASTRc17HjOzj-s66ftGh78y4jdvYG4Hx3yh1pDIYXNYILteFXHFo9vo-NEZF2W3ofEvIY63AZxp8MgueyMJuBRYYXJYIBl_RnxlsZMsh4tmgd5K4XsIhgxDM9w5NyhD6F3UEAJSo2FhBGFzeEAxODgzYTc4MmNhMTgzMDNlMmFhMmIyMzRhYjUyMTFhY2Y1NTNjMWVlYWQ3ZWQ1YjBhMzdhYjFlZjcwZWRhMmEyYWNYIQNU8wZs14BtQPHbdOs5Rb3wSh0KXx9AdBigW1mgJwZo4KNhYQFhc3hAMDA1MDMzY2EzNDBjNjE3Njc3OGQxNWYwMTVkOTMyZDEwZjA0YWE1ZTA3ZDQyOTg0ZTUyNWYwMjk1MjM1YWIzNWFjWCECXRsBpeSyn5gUQ7_gvsljKBNCUy0VPvkrTS5HD5BCko0";
|
|
34
|
-
it("should match valid cashu tokens", () => {
|
|
35
|
-
const text = `Here is a token: ${cashuA}`;
|
|
36
|
-
const matches = Array.from(text.matchAll(Expressions.cashu));
|
|
37
|
-
expect(matches).toHaveLength(1);
|
|
38
|
-
expect(matches[0][1]).toBe(cashuA);
|
|
39
|
-
});
|
|
40
|
-
it("should match cashuB tokens", () => {
|
|
41
|
-
const text = `Here is a token: ${cashuB}`;
|
|
42
|
-
const matches = Array.from(text.matchAll(Expressions.cashu));
|
|
43
|
-
expect(matches).toHaveLength(1);
|
|
44
|
-
expect(matches[0][1]).toBe(cashuB);
|
|
45
|
-
});
|
|
46
|
-
it("should match cashu tokens with prefix", () => {
|
|
47
|
-
const text = `Here is a token cashu:${cashuA}`;
|
|
48
|
-
const matches = Array.from(text.matchAll(Expressions.cashu));
|
|
49
|
-
expect(matches).toHaveLength(1);
|
|
50
|
-
expect(matches[0][1]).toBe(cashuA);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe("Expressions.nostrLink", () => {
|
|
54
|
-
it("should match npub links", () => {
|
|
55
|
-
const npub = "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6";
|
|
56
|
-
const text = `Check out ${npub}`;
|
|
57
|
-
const matches = Array.from(text.matchAll(Expressions.nostrLink));
|
|
58
|
-
expect(matches).toHaveLength(1);
|
|
59
|
-
expect(matches[0][1]).toBe(npub);
|
|
60
|
-
});
|
|
61
|
-
it("should match note links", () => {
|
|
62
|
-
const note = "note1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqsrjtey";
|
|
63
|
-
const text = `Check out ${note}`;
|
|
64
|
-
const matches = Array.from(text.matchAll(Expressions.nostrLink));
|
|
65
|
-
expect(matches).toHaveLength(1);
|
|
66
|
-
expect(matches[0][1]).toBe(note);
|
|
67
|
-
});
|
|
68
|
-
it("should match nprofile links", () => {
|
|
69
|
-
const nprofile = "nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdakp7qgzwaehxw309aex2mrp0yhxummnw3ezuamfdejsygrwv3jx2mtedfhk6tcpzamhxue69uhkummnw3ezuamfdejsygrwv3jx2mtedfhk6tcpzamhxue69uhkzemp9qy";
|
|
70
|
-
const text = `Check out ${nprofile}`;
|
|
71
|
-
const matches = Array.from(text.matchAll(Expressions.nostrLink));
|
|
72
|
-
expect(matches).toHaveLength(1);
|
|
73
|
-
expect(matches[0][1]).toBe(nprofile);
|
|
74
|
-
});
|
|
75
|
-
it("should match nevent links", () => {
|
|
76
|
-
const nevent = "nevent1qvzqqqqqqypzqwlsccluhy6xxsr6l9a9uhhxf75g85g8a709tprjcn4e42h053vaqyd8wumn8ghj7urewfsk66ty9enxjct5dfskvtnrdakj7qgmwaehxw309aex2mrp0yh8wetnw3jhymnzw33jucm0d5hsqgqqqrzq4vghcurgc2p3k70xka03m0wsvhwh244gh2f8tnk6dl49vgx9mgmd";
|
|
77
|
-
const text = `Check out ${nevent}`;
|
|
78
|
-
const matches = Array.from(text.matchAll(Expressions.nostrLink));
|
|
79
|
-
expect(matches).toHaveLength(1);
|
|
80
|
-
expect(matches[0][1]).toBe(nevent);
|
|
81
|
-
});
|
|
82
|
-
it("should match naddr links", () => {
|
|
83
|
-
const naddr = "naddr1qqjx2wtzx93rycmz94nrqvf3956rqep3943xgvec956xxvnxxucxze33v93rvq3qeaz6dwsnvwkha5sn5puwwyxjgy26uusundrm684lg3vw4ma5c2jsxpqqqpmxw6td7rf";
|
|
84
|
-
const text = `Check out ${naddr}`;
|
|
85
|
-
const matches = Array.from(text.matchAll(Expressions.nostrLink));
|
|
86
|
-
expect(matches).toHaveLength(1);
|
|
87
|
-
expect(matches[0][1]).toBe(naddr);
|
|
88
|
-
});
|
|
89
|
-
it("should match nostr: prefixed links", () => {
|
|
90
|
-
const text = "Check out nostr:npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6";
|
|
91
|
-
const matches = Array.from(text.matchAll(Expressions.nostrLink));
|
|
92
|
-
expect(matches).toHaveLength(1);
|
|
93
|
-
expect(matches[0][1]).toBe("npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6");
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
describe("Expressions.emoji", () => {
|
|
97
|
-
it("should match emoji shortcodes", () => {
|
|
98
|
-
const text = "Hello :smile: world :thumbsup:";
|
|
99
|
-
const matches = Array.from(text.matchAll(Expressions.emoji));
|
|
100
|
-
expect(matches).toHaveLength(2);
|
|
101
|
-
expect(matches[0][1]).toBe("smile");
|
|
102
|
-
expect(matches[1][1]).toBe("thumbsup");
|
|
103
|
-
});
|
|
104
|
-
it("should match emoji shortcodes with underscores and hyphens", () => {
|
|
105
|
-
const text = "Hello :smiling_face: and :thumbs-up:";
|
|
106
|
-
const matches = Array.from(text.matchAll(Expressions.emoji));
|
|
107
|
-
expect(matches).toHaveLength(2);
|
|
108
|
-
expect(matches[0][1]).toBe("smiling_face");
|
|
109
|
-
expect(matches[1][1]).toBe("thumbs-up");
|
|
110
|
-
});
|
|
111
|
-
it("should match emoji shortcodes with numbers", () => {
|
|
112
|
-
const text = "Hello :smile123: world :thumbs2up:";
|
|
113
|
-
const matches = Array.from(text.matchAll(Expressions.emoji));
|
|
114
|
-
expect(matches).toHaveLength(2);
|
|
115
|
-
expect(matches[0][1]).toBe("smile123");
|
|
116
|
-
expect(matches[1][1]).toBe("thumbs2up");
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
describe("Expressions.hashtag", () => {
|
|
120
|
-
it("should match simple hashtags", () => {
|
|
121
|
-
const text = "Hello #world and #nostr";
|
|
122
|
-
const matches = Array.from(text.matchAll(Expressions.hashtag));
|
|
123
|
-
expect(matches).toHaveLength(2);
|
|
124
|
-
expect(matches[0][1]).toBe("world");
|
|
125
|
-
expect(matches[1][1]).toBe("nostr");
|
|
126
|
-
});
|
|
127
|
-
it("should match hashtags with numbers", () => {
|
|
128
|
-
const text = "Hello #world2023 and #nostr42";
|
|
129
|
-
const matches = Array.from(text.matchAll(Expressions.hashtag));
|
|
130
|
-
expect(matches).toHaveLength(2);
|
|
131
|
-
expect(matches[0][1]).toBe("world2023");
|
|
132
|
-
expect(matches[1][1]).toBe("nostr42");
|
|
133
|
-
});
|
|
134
|
-
it("should match hashtags at the beginning of text", () => {
|
|
135
|
-
const text = "#hello world";
|
|
136
|
-
const matches = Array.from(text.matchAll(Expressions.hashtag));
|
|
137
|
-
expect(matches).toHaveLength(1);
|
|
138
|
-
expect(matches[0][1]).toBe("hello");
|
|
139
|
-
});
|
|
140
|
-
it("should not match hashtags within words", () => {
|
|
141
|
-
const text = "word#hashtag is not a hashtag";
|
|
142
|
-
const matches = Array.from(text.matchAll(Expressions.hashtag));
|
|
143
|
-
expect(matches).toHaveLength(0);
|
|
144
|
-
});
|
|
145
|
-
it("should match non-Latin hashtags", () => {
|
|
146
|
-
const text = "Hello #世界 and #привет";
|
|
147
|
-
const matches = Array.from(text.matchAll(Expressions.hashtag));
|
|
148
|
-
expect(matches).toHaveLength(2);
|
|
149
|
-
expect(matches[0][1]).toBe("世界");
|
|
150
|
-
expect(matches[1][1]).toBe("привет");
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
describe("Expressions.lightning", () => {
|
|
154
|
-
it("should match lightning invoices", () => {
|
|
155
|
-
const invoice = "lnbc100n1p5pjxjk9qypqqqdqqxqrrsssp54ttukd5xxy2nmdzf864yjereuf9v3pyzl66hpqgxa0e8fvlzf6aspp5z6twjtwde82ec7wfcqw2m63v48r6fyw78753wxh7zjlvuru7tapsp6c9lq6m4d55u9jkxuqpepdknnzznfu05wl73swyn52z3pnkzyxrlkqf3t5jkw2hq7ukasuh5wgazvfwkkzrf0aqk4k0zluzu4rx8wqq8sut0l";
|
|
156
|
-
const text = `Pay with ${invoice}`;
|
|
157
|
-
const matches = Array.from(text.matchAll(Expressions.lightning));
|
|
158
|
-
expect(matches).toHaveLength(1);
|
|
159
|
-
expect(matches[0][1]).toBe(invoice);
|
|
160
|
-
});
|
|
161
|
-
it("should match lightning: prefixed invoices", () => {
|
|
162
|
-
const invoice = "lnbc100n1p5pjxjk9qypqqqdqqxqrrsssp54ttukd5xxy2nmdzf864yjereuf9v3pyzl66hpqgxa0e8fvlzf6aspp5z6twjtwde82ec7wfcqw2m63v48r6fyw78753wxh7zjlvuru7tapsp6c9lq6m4d55u9jkxuqpepdknnzznfu05wl73swyn52z3pnkzyxrlkqf3t5jkw2hq7ukasuh5wgazvfwkkzrf0aqk4k0zluzu4rx8wqq8sut0l";
|
|
163
|
-
const text = `Pay with lightning:${invoice}`;
|
|
164
|
-
const matches = Array.from(text.matchAll(Expressions.lightning));
|
|
165
|
-
expect(matches).toHaveLength(1);
|
|
166
|
-
expect(matches[0][1]).toBe(invoice);
|
|
167
|
-
});
|
|
168
|
-
it("should be case insensitive", () => {
|
|
169
|
-
const invoice = "lnbc100n1p5pjxjk9qypqqqdqqxqrrsssp54ttukd5xxy2nmdzf864yjereuf9v3pyzl66hpqgxa0e8fvlzf6aspp5z6twjtwde82ec7wfcqw2m63v48r6fyw78753wxh7zjlvuru7tapsp6c9lq6m4d55u9jkxuqpepdknnzznfu05wl73swyn52z3pnkzyxrlkqf3t5jkw2hq7ukasuh5wgazvfwkkzrf0aqk4k0zluzu4rx8wqq8sut0l".toUpperCase();
|
|
170
|
-
const text = `Pay with ${invoice}`;
|
|
171
|
-
const matches = Array.from(text.matchAll(Expressions.lightning));
|
|
172
|
-
expect(matches).toHaveLength(1);
|
|
173
|
-
expect(matches[0][1].toUpperCase()).toBe(invoice.toUpperCase());
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
describe("Token Regular Expressions", () => {
|
|
178
|
-
describe("Tokens.link", () => {
|
|
179
|
-
it("should match links surrounded by whitespace", () => {
|
|
180
|
-
const text = "Check out https://example.com and https://test.org";
|
|
181
|
-
const matches = Array.from(text.matchAll(Tokens.link));
|
|
182
|
-
expect(matches).toHaveLength(2);
|
|
183
|
-
expect(matches[0][0].trim()).toBe("https://example.com");
|
|
184
|
-
expect(matches[1][0].trim()).toBe("https://test.org");
|
|
185
|
-
});
|
|
186
|
-
it("should match links at the beginning of text", () => {
|
|
187
|
-
const text = "https://example.com is a website";
|
|
188
|
-
const matches = Array.from(text.matchAll(Tokens.link));
|
|
189
|
-
expect(matches).toHaveLength(1);
|
|
190
|
-
expect(matches[0][0].trim()).toBe("https://example.com");
|
|
191
|
-
});
|
|
192
|
-
it("should match links at the end of text", () => {
|
|
193
|
-
const text = "Visit https://example.com";
|
|
194
|
-
const matches = Array.from(text.matchAll(Tokens.link));
|
|
195
|
-
expect(matches).toHaveLength(1);
|
|
196
|
-
expect(matches[0][0].trim()).toBe("https://example.com");
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
describe("Tokens.cashu", () => {
|
|
200
|
-
it("should match cashu tokens surrounded by whitespace", () => {
|
|
201
|
-
const token = "cashuAeyJ0b2tlbiI6W3sicHJvb2ZzIjpbeyJpZCI6IjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJzZWNyZXQiOiIwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJDIjoiMDMwZGQwMTQxMGY2ZTIwZjk4YzRkZTlhMDhkOTM5ZDQyMjRkYjUxMzIzZWM1YWM2MThhMzA3NjRjNzJiMDFiMDg2In1dLCJtaW50IjoiaHR0cHM6Ly9leGFtcGxlLmNvbSIsInZhbHVlIjoxfV19";
|
|
202
|
-
const text = `Here is a token: ${token} end`;
|
|
203
|
-
const matches = Array.from(text.matchAll(Tokens.cashu));
|
|
204
|
-
expect(matches).toHaveLength(1);
|
|
205
|
-
expect(matches[0][0].trim()).toBe(token);
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
describe("Tokens.nostrLink", () => {
|
|
209
|
-
it("should match nostr links surrounded by whitespace", () => {
|
|
210
|
-
const npub = "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6";
|
|
211
|
-
const text = `Check out ${npub} and more`;
|
|
212
|
-
const matches = Array.from(text.matchAll(Tokens.nostrLink));
|
|
213
|
-
expect(matches).toHaveLength(1);
|
|
214
|
-
expect(matches[0][0].trim()).toBe(npub);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
describe("Tokens.emoji", () => {
|
|
218
|
-
it("should match emoji shortcodes surrounded by whitespace", () => {
|
|
219
|
-
const text = "Hello :smile: world :thumbsup: end";
|
|
220
|
-
const matches = Array.from(text.matchAll(Tokens.emoji));
|
|
221
|
-
expect(matches).toHaveLength(2);
|
|
222
|
-
expect(matches[0][0].trim()).toBe(":smile:");
|
|
223
|
-
expect(matches[1][0].trim()).toBe(":thumbsup:");
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
describe("Tokens.hashtag", () => {
|
|
227
|
-
it("should match hashtags surrounded by whitespace", () => {
|
|
228
|
-
const text = "Hello #world and #nostr end";
|
|
229
|
-
const matches = Array.from(text.matchAll(Tokens.hashtag));
|
|
230
|
-
expect(matches).toHaveLength(2);
|
|
231
|
-
expect(matches[0][0].trim()).toBe("#world");
|
|
232
|
-
expect(matches[1][0].trim()).toBe("#nostr");
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
describe("Tokens.lightning", () => {
|
|
236
|
-
it("should match lightning invoices surrounded by whitespace", () => {
|
|
237
|
-
const invoice = "LNBC1500N1PJQJJ5SPP5FSP3ZZAR0GZPJ9YHKQVSD7CQPGWG4XSULZP4TCG6VYVK63KM5USDQQCQZPGXQYZ5VQSP5USYC4LK9CHSFP53KH0DUDVH0GWDWLWLVJRSZGQTW8QF99XWCPS9QYYSSQJCEWM5CJWZ4A6RFJX77C490YCED6PEMK0UPKXHY89CMM7SCT66K8GNEANWYKZGDRWRFJE69H9U5U0W57RRCSYSAS7GADWMZXC8C6GQPVXHNRC";
|
|
238
|
-
const text = `Pay with ${invoice} now`;
|
|
239
|
-
const matches = Array.from(text.matchAll(Tokens.lightning));
|
|
240
|
-
expect(matches).toHaveLength(1);
|
|
241
|
-
expect(matches[0][0].trim()).toBe(invoice);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import * as exports from "../index.js";
|
|
3
|
-
describe("exports", () => {
|
|
4
|
-
it("should export the expected functions", () => {
|
|
5
|
-
expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
|
|
6
|
-
[
|
|
7
|
-
"remarkNostrMentions",
|
|
8
|
-
]
|
|
9
|
-
`);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import * as exports from "../index.js";
|
|
3
|
-
describe("exports", () => {
|
|
4
|
-
it("should export the expected functions", () => {
|
|
5
|
-
expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
|
|
6
|
-
[
|
|
7
|
-
"eolMetadata",
|
|
8
|
-
"findAndReplace",
|
|
9
|
-
"truncateContent",
|
|
10
|
-
]
|
|
11
|
-
`);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import * as exports from "../index.js";
|
|
3
|
-
describe("exports", () => {
|
|
4
|
-
it("should export the expected functions", () => {
|
|
5
|
-
expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
|
|
6
|
-
[
|
|
7
|
-
"TextNoteContentSymbol",
|
|
8
|
-
"cashuTokens",
|
|
9
|
-
"createTextNoteATS",
|
|
10
|
-
"emojis",
|
|
11
|
-
"galleries",
|
|
12
|
-
"getParsedContent",
|
|
13
|
-
"hashtags",
|
|
14
|
-
"lightningInvoices",
|
|
15
|
-
"links",
|
|
16
|
-
"nostrMentions",
|
|
17
|
-
"removeParsedTextContent",
|
|
18
|
-
"textNoteTransformers",
|
|
19
|
-
]
|
|
20
|
-
`);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { getParsedContent } from "../content.js";
|
|
3
|
-
import { galleries } from "../gallery.js";
|
|
4
|
-
import { links } from "../links.js";
|
|
5
|
-
describe("gallery", () => {
|
|
6
|
-
it("should group image urls into galleries", () => {
|
|
7
|
-
expect(getParsedContent("Hello https://example.com/image.png https://example.com/image2.png", undefined, [
|
|
8
|
-
links,
|
|
9
|
-
galleries,
|
|
10
|
-
]).children).toEqual([
|
|
11
|
-
expect.objectContaining({ type: "text" }),
|
|
12
|
-
expect.objectContaining({
|
|
13
|
-
type: "gallery",
|
|
14
|
-
links: ["https://example.com/image.png", "https://example.com/image2.png"],
|
|
15
|
-
}),
|
|
16
|
-
]);
|
|
17
|
-
});
|
|
18
|
-
it("should not match a single image link", () => {
|
|
19
|
-
expect(getParsedContent("Hello https://example.com/image.png", undefined, [links, galleries]).children).toEqual([
|
|
20
|
-
expect.objectContaining({ type: "text" }),
|
|
21
|
-
expect.objectContaining({ type: "link" }),
|
|
22
|
-
]);
|
|
23
|
-
});
|
|
24
|
-
it("should match multiple galleries", () => {
|
|
25
|
-
expect(getParsedContent("Hello https://example.com/image.png\nhttps://example.com/image2.png\n\nAnd here are the other images https://example.com/image3.png\n\nhttps://example.com/image4.png", undefined, [links, galleries]).children).toEqual([
|
|
26
|
-
expect.objectContaining({ type: "text" }),
|
|
27
|
-
expect.objectContaining({
|
|
28
|
-
type: "gallery",
|
|
29
|
-
links: ["https://example.com/image.png", "https://example.com/image2.png"],
|
|
30
|
-
}),
|
|
31
|
-
expect.objectContaining({ type: "text" }),
|
|
32
|
-
expect.objectContaining({
|
|
33
|
-
type: "gallery",
|
|
34
|
-
links: ["https://example.com/image3.png", "https://example.com/image4.png"],
|
|
35
|
-
}),
|
|
36
|
-
]);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { getParsedContent } from "../content.js";
|
|
3
|
-
import { hashtags } from "../hashtag.js";
|
|
4
|
-
import { FakeUser } from "../../__tests__/fake-user.js";
|
|
5
|
-
const user = new FakeUser();
|
|
6
|
-
describe("hashtags", () => {
|
|
7
|
-
it("should match all hashtags if event is missing", () => {
|
|
8
|
-
expect(getParsedContent("Hello #hashtag", undefined, [hashtags]).children).toMatchInlineSnapshot(`
|
|
9
|
-
[
|
|
10
|
-
{
|
|
11
|
-
"type": "text",
|
|
12
|
-
"value": "Hello ",
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"hashtag": "hashtag",
|
|
16
|
-
"name": "hashtag",
|
|
17
|
-
"tag": undefined,
|
|
18
|
-
"type": "hashtag",
|
|
19
|
-
},
|
|
20
|
-
]
|
|
21
|
-
`);
|
|
22
|
-
});
|
|
23
|
-
describe("with event", () => {
|
|
24
|
-
it("should match all hashtags", () => {
|
|
25
|
-
expect(getParsedContent(user.event({ content: "Hello #hashtag", tags: [["t", "hashtag"]] }), undefined, [hashtags])
|
|
26
|
-
.children).toMatchInlineSnapshot(`
|
|
27
|
-
[
|
|
28
|
-
{
|
|
29
|
-
"type": "text",
|
|
30
|
-
"value": "Hello ",
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"hashtag": "hashtag",
|
|
34
|
-
"name": "hashtag",
|
|
35
|
-
"tag": [
|
|
36
|
-
"t",
|
|
37
|
-
"hashtag",
|
|
38
|
-
],
|
|
39
|
-
"type": "hashtag",
|
|
40
|
-
},
|
|
41
|
-
]
|
|
42
|
-
`);
|
|
43
|
-
});
|
|
44
|
-
it("should not match hashtags with missing t tags", () => {
|
|
45
|
-
expect(getParsedContent(user.event({ content: "Hello #hashtag", tags: [] }), undefined, [hashtags]).children).not.toEqual(expect.arrayContaining([expect.objectContaining({ type: "hashtag" })]));
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|