applesauce-content 0.0.0-next-20250505205231 → 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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
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
+ });
@@ -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", () => {
@@ -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;
@@ -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
- return /(?<=^|[^\p{L}#])#([\p{L}\p{N}\p{M}]+)/gu;
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 new RegExp(`(?<=\\s|^)${Expressions.link.source}(?=\\s|$)`, "gu");
31
+ return Expressions.link;
25
32
  },
26
33
  get cashu() {
27
- return new RegExp(`(?<=\\s|^)${Expressions.cashu.source}(?=\\s|$)`, "gi");
34
+ return new RegExp(`(?<=^|\\s)${Expressions.cashu.source}`, "gi");
28
35
  },
29
36
  get nostrLink() {
30
- return new RegExp(`(?<=\\s|^)${Expressions.nostrLink.source}(?=\\s|$)`, "gi");
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(`(?<=\\s|^)${Expressions.lightning.source}(?=\\s|$)`, "gim");
46
+ return new RegExp(`(?<=^|\\s)${Expressions.lightning.source}`, "gim");
40
47
  },
41
48
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
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,6 +1,6 @@
1
- import { Transformer } from "unified";
1
+ import { DecodeResult } from "applesauce-core/helpers";
2
2
  import { Link, Nodes } from "mdast";
3
- import { DecodeResult } from "nostr-tools/nip19";
3
+ import { Transformer } from "unified";
4
4
  export interface NostrMention extends Link {
5
5
  type: "link";
6
6
  data: DecodeResult;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
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,8 +1,8 @@
1
- import { EventTemplate, NostrEvent } from "nostr-tools";
2
- import { DecodeResult } from "nostr-tools/nip19";
3
- import { Node as UnistNode, Parent } from "unist";
4
1
  import { type Token } from "@cashu/cashu-ts";
2
+ import { type DecodeResult } from "applesauce-core/helpers";
5
3
  import { type ParsedInvoice } from "applesauce-core/helpers/bolt11";
4
+ import { type EventTemplate, type NostrEvent } from "nostr-tools";
5
+ import { type Parent, type Node as UnistNode } from "unist";
6
6
  export interface CommonData {
7
7
  eol?: boolean;
8
8
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-content",
3
- "version": "0.0.0-next-20250505205231",
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,9 +52,9 @@
52
52
  "@types/hast": "^3.0.4",
53
53
  "@types/mdast": "^4.0.4",
54
54
  "@types/unist": "^3.0.3",
55
- "applesauce-core": "^1.0.0",
55
+ "applesauce-core": "0.0.0-next-20250526151506",
56
56
  "mdast-util-find-and-replace": "^3.0.2",
57
- "nostr-tools": "^2.10.4",
57
+ "nostr-tools": "^2.13",
58
58
  "remark": "^15.0.1",
59
59
  "remark-parse": "^11.0.0",
60
60
  "unified": "^11.0.5",