applesauce-content 0.0.0-next-20250522030625 → 0.0.0-next-20250526151506
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.
|
@@ -92,6 +92,17 @@ describe("Regular Expressions", () => {
|
|
|
92
92
|
expect(matches).toHaveLength(1);
|
|
93
93
|
expect(matches[0][1]).toBe("npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6");
|
|
94
94
|
});
|
|
95
|
+
it("should match nostr links in URLs", () => {
|
|
96
|
+
const text = "https://npub1wyuh3scfgzqmxn709a2fzuemps389rxnk7nfgege6s847zze3tuqfl87ez.nsite.lol/n/nevent1qvzqqqqqqypzp022u0n8u2vkf4y5zu3xrhz989wgna4a9em5vshrvcf8zuwlhq04qyghwumn8ghj7mn0wd68ytnhd9hx2tcppemhxue69uhkummn9ekx7mp0qqsz7ck33xzlpcf2338ufrarks2cxqzk2rp925qe38wvlevhxv9pg6syy7gc7";
|
|
97
|
+
const matches = Array.from(text.matchAll(Expressions.nostrLink));
|
|
98
|
+
expect(matches).toHaveLength(2);
|
|
99
|
+
expect(matches).toEqual([
|
|
100
|
+
expect.arrayContaining(["npub1wyuh3scfgzqmxn709a2fzuemps389rxnk7nfgege6s847zze3tuqfl87ez"]),
|
|
101
|
+
expect.arrayContaining([
|
|
102
|
+
"nevent1qvzqqqqqqypzp022u0n8u2vkf4y5zu3xrhz989wgna4a9em5vshrvcf8zuwlhq04qyghwumn8ghj7mn0wd68ytnhd9hx2tcppemhxue69uhkummn9ekx7mp0qqsz7ck33xzlpcf2338ufrarks2cxqzk2rp925qe38wvlevhxv9pg6syy7gc7",
|
|
103
|
+
]),
|
|
104
|
+
]);
|
|
105
|
+
});
|
|
95
106
|
});
|
|
96
107
|
describe("Expressions.emoji", () => {
|
|
97
108
|
it("should match emoji shortcodes", () => {
|
|
@@ -149,6 +160,11 @@ describe("Regular Expressions", () => {
|
|
|
149
160
|
expect(matches[0][1]).toBe("世界");
|
|
150
161
|
expect(matches[1][1]).toBe("привет");
|
|
151
162
|
});
|
|
163
|
+
it("should not match hashtags in URLs", () => {
|
|
164
|
+
const text = "testing urls wss://relay.damus.io ircs://irc.zeronode.net:6697/#nostr https://github.com/hzrd149/applesauce?tab=readme-ov-file#running-tests";
|
|
165
|
+
const matches = Array.from(text.matchAll(Expressions.hashtag));
|
|
166
|
+
expect(matches).toHaveLength(0);
|
|
167
|
+
});
|
|
152
168
|
});
|
|
153
169
|
describe("Expressions.lightning", () => {
|
|
154
170
|
it("should match lightning invoices", () => {
|
|
@@ -213,6 +229,11 @@ describe("Token Regular Expressions", () => {
|
|
|
213
229
|
expect(matches).toHaveLength(1);
|
|
214
230
|
expect(matches[0][0].trim()).toBe(npub);
|
|
215
231
|
});
|
|
232
|
+
it("should not match links in URLs", async () => {
|
|
233
|
+
const text = "Checkout my app https://zap.stream/naddr1qqjx2wtzx93rycmz94nrqvf3956rqep3943xgvec956xxvnxxucxze33v93rvq3qeaz6dwsnvwkha5sn5puwwyxjgy26uusundrm684lg3vw4ma5c2jsxpqqqpmxw6td7rf";
|
|
234
|
+
const matches = Array.from(text.matchAll(Tokens.nostrLink));
|
|
235
|
+
expect(matches).toHaveLength(0);
|
|
236
|
+
});
|
|
216
237
|
});
|
|
217
238
|
describe("Tokens.emoji", () => {
|
|
218
239
|
it("should match emoji shortcodes surrounded by whitespace", () => {
|
package/dist/helpers/regexp.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const Expressions: {
|
|
2
|
+
readonly url: RegExp;
|
|
2
3
|
readonly link: RegExp;
|
|
3
4
|
readonly cashu: RegExp;
|
|
4
5
|
readonly nostrLink: RegExp;
|
|
@@ -8,6 +9,7 @@ export declare const Expressions: {
|
|
|
8
9
|
};
|
|
9
10
|
/** A list of Regular Expressions that match tokens surrounded by whitespace to avoid matching in URLs */
|
|
10
11
|
export declare const Tokens: {
|
|
12
|
+
readonly url: RegExp;
|
|
11
13
|
readonly link: RegExp;
|
|
12
14
|
readonly cashu: RegExp;
|
|
13
15
|
readonly nostrLink: RegExp;
|
package/dist/helpers/regexp.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export const Expressions = {
|
|
2
|
+
get url() {
|
|
3
|
+
return /(?:https?|wss?|ircs?|s?ftp):\/\/([a-zA-Z0-9\.\-]+\.[a-zA-Z]+(?::\d+)?)([\/\?#][\p{L}\p{N}\p{M}&\.-\/\?=#\-@%\+_,:!~*]*)?/gu;
|
|
4
|
+
},
|
|
2
5
|
get link() {
|
|
3
6
|
return /https?:\/\/([a-zA-Z0-9\.\-]+\.[a-zA-Z]+(?::\d+)?)([\/\?#][\p{L}\p{N}\p{M}&\.-\/\?=#\-@%\+_,:!~*]*)?/gu;
|
|
4
7
|
},
|
|
@@ -12,7 +15,8 @@ export const Expressions = {
|
|
|
12
15
|
return /:([a-zA-Z0-9_-]+):/gi;
|
|
13
16
|
},
|
|
14
17
|
get hashtag() {
|
|
15
|
-
|
|
18
|
+
// NOTE: cant use \b here because it uses \w which only matches latin letters
|
|
19
|
+
return /(?<=^|[^\p{L}#\/])#([\p{L}\p{N}\p{M}]+)(?=\p{Z}|$|\s)/gu;
|
|
16
20
|
},
|
|
17
21
|
get lightning() {
|
|
18
22
|
return /(?:lightning:)?(LNBC[A-Za-z0-9]+)/gim;
|
|
@@ -20,14 +24,17 @@ export const Expressions = {
|
|
|
20
24
|
};
|
|
21
25
|
/** A list of Regular Expressions that match tokens surrounded by whitespace to avoid matching in URLs */
|
|
22
26
|
export const Tokens = {
|
|
27
|
+
get url() {
|
|
28
|
+
return Expressions.url;
|
|
29
|
+
},
|
|
23
30
|
get link() {
|
|
24
|
-
return
|
|
31
|
+
return Expressions.link;
|
|
25
32
|
},
|
|
26
33
|
get cashu() {
|
|
27
|
-
return new RegExp(
|
|
34
|
+
return new RegExp(`(?<=^|\\s)${Expressions.cashu.source}`, "gi");
|
|
28
35
|
},
|
|
29
36
|
get nostrLink() {
|
|
30
|
-
return new RegExp(
|
|
37
|
+
return new RegExp(`(?<=^|\\s)${Expressions.nostrLink.source}`, "gi");
|
|
31
38
|
},
|
|
32
39
|
get emoji() {
|
|
33
40
|
return Expressions.emoji;
|
|
@@ -36,6 +43,6 @@ export const Tokens = {
|
|
|
36
43
|
return Expressions.hashtag;
|
|
37
44
|
},
|
|
38
45
|
get lightning() {
|
|
39
|
-
return new RegExp(
|
|
46
|
+
return new RegExp(`(?<=^|\\s)${Expressions.lightning.source}`, "gim");
|
|
40
47
|
},
|
|
41
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-20250526151506",
|
|
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-20250526151506",
|
|
56
56
|
"mdast-util-find-and-replace": "^3.0.2",
|
|
57
57
|
"nostr-tools": "^2.13",
|
|
58
58
|
"remark": "^15.0.1",
|