applesauce-content 0.0.0-next-20241112141526 → 0.0.0-next-20241114194041

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/README.md CHANGED
@@ -5,13 +5,13 @@ applesauce package for parsing text note content
5
5
  ## Example
6
6
 
7
7
  ```ts
8
- import { getParsedTextContent } from "applesauce-content/text";
8
+ import { getParsedContent } from "applesauce-content/text";
9
9
 
10
10
  const stringContent = `
11
11
  hello nostr!
12
12
  nostr:npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6
13
13
  `;
14
- const ats = getParsedTextContent(stringContent);
14
+ const ats = getParsedContent(stringContent);
15
15
 
16
16
  console.log(ats);
17
17
  /*
@@ -2,8 +2,8 @@ import { Transformer } from "unified";
2
2
  import { EventTemplate, NostrEvent } from "nostr-tools";
3
3
  import { Root } from "../nast/types.js";
4
4
  import { galleries } from "./gallery.js";
5
- export declare const ParsedTextContentSymbol: unique symbol;
6
- export declare const defaultTransformers: (typeof galleries)[];
5
+ export declare const TextNoteContentSymbol: unique symbol;
6
+ export declare const textNoteTransformers: (typeof galleries)[];
7
7
  /** Parsed and process a note with custom transformers */
8
- export declare function getParsedTextContent(event: NostrEvent | EventTemplate | string, content?: string, transformers?: (() => Transformer<Root>)[]): Root;
8
+ export declare function getParsedContent(event: NostrEvent | EventTemplate | string, content?: string, transformers?: (() => Transformer<Root>)[], cacheKey?: symbol | null | undefined): Root;
9
9
  export declare function removeParsedTextContent(event: NostrEvent | EventTemplate): void;
@@ -9,9 +9,9 @@ import { galleries } from "./gallery.js";
9
9
  import { lightningInvoices } from "./lightning.js";
10
10
  import { eolMetadata } from "../nast/eol-metadata.js";
11
11
  import { links } from "./links.js";
12
- export const ParsedTextContentSymbol = Symbol.for("parsed-text-content");
12
+ export const TextNoteContentSymbol = Symbol.for("text-note-content");
13
13
  // default kind 1 transformers
14
- export const defaultTransformers = [
14
+ export const textNoteTransformers = [
15
15
  links,
16
16
  nostrMentions,
17
17
  galleries,
@@ -22,7 +22,7 @@ export const defaultTransformers = [
22
22
  eolMetadata,
23
23
  ];
24
24
  /** Parsed and process a note with custom transformers */
25
- export function getParsedTextContent(event, content, transformers = defaultTransformers) {
25
+ export function getParsedContent(event, content, transformers = textNoteTransformers, cacheKey = TextNoteContentSymbol) {
26
26
  // process strings
27
27
  if (typeof event === "string") {
28
28
  const processor = unified();
@@ -31,7 +31,15 @@ export function getParsedTextContent(event, content, transformers = defaultTrans
31
31
  }
32
32
  return processor.runSync(createTextNoteATS(event, content));
33
33
  }
34
- return getOrComputeCachedValue(event, ParsedTextContentSymbol, () => {
34
+ // no caching
35
+ if (!cacheKey) {
36
+ const processor = unified();
37
+ for (const transformer of transformers) {
38
+ processor.use(transformer);
39
+ }
40
+ return processor.runSync(createTextNoteATS(event, content));
41
+ }
42
+ return getOrComputeCachedValue(event, cacheKey, () => {
35
43
  const processor = unified();
36
44
  for (const transformer of transformers) {
37
45
  processor.use(transformer);
@@ -41,5 +49,5 @@ export function getParsedTextContent(event, content, transformers = defaultTrans
41
49
  }
42
50
  export function removeParsedTextContent(event) {
43
51
  // @ts-expect-error
44
- delete event[ParsedTextContentSymbol];
52
+ delete event[TextNoteContentSymbol];
45
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-content",
3
- "version": "0.0.0-next-20241112141526",
3
+ "version": "0.0.0-next-20241114194041",
4
4
  "description": "Unified plugins for processing event content",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -40,7 +40,7 @@
40
40
  "@types/hast": "^3.0.4",
41
41
  "@types/mdast": "^4.0.4",
42
42
  "@types/unist": "^3.0.3",
43
- "applesauce-core": "0.0.0-next-20241112141526",
43
+ "applesauce-core": "0.0.0-next-20241114194041",
44
44
  "mdast-util-find-and-replace": "^3.0.1",
45
45
  "nostr-tools": "^2.10.1",
46
46
  "remark": "^15.0.1",
@@ -52,7 +52,8 @@
52
52
  "@jest/globals": "^29.7.0",
53
53
  "@types/jest": "^29.5.13",
54
54
  "jest": "^29.7.0",
55
- "jest-extended": "^4.0.2"
55
+ "jest-extended": "^4.0.2",
56
+ "typescript": "^5.6.3"
56
57
  },
57
58
  "jest": {
58
59
  "roots": [
@@ -62,6 +63,10 @@
62
63
  "jest-extended/all"
63
64
  ]
64
65
  },
66
+ "funding": {
67
+ "type": "lightning",
68
+ "url": "lightning:nostrudel@geyser.fund"
69
+ },
65
70
  "scripts": {
66
71
  "build": "tsc",
67
72
  "watch:build": "tsc --watch > /dev/null",
@@ -1,3 +0,0 @@
1
- import { Transformer } from "unified";
2
- import { Root } from "../nast/types.js";
3
- export declare function links(): Transformer<Root>;
package/dist/text/link.js DELETED
@@ -1,22 +0,0 @@
1
- import Expressions from "../helpers/regexp.js";
2
- import { findAndReplace } from "../nast/find-and-replace.js";
3
- export function links() {
4
- return (tree) => {
5
- findAndReplace(tree, [
6
- [
7
- Expressions.link,
8
- (_) => {
9
- try {
10
- return {
11
- type: "link",
12
- href: new URL(_).toString(),
13
- value: _,
14
- };
15
- }
16
- catch (error) { }
17
- return false;
18
- },
19
- ],
20
- ]);
21
- };
22
- }