applesauce-content 0.0.0-next-20241106104112 → 0.0.0-next-20241108100553

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.
@@ -3,5 +3,6 @@ export declare const Expressions: {
3
3
  readonly nostrLink: RegExp;
4
4
  readonly emoji: RegExp;
5
5
  readonly hashtag: RegExp;
6
+ readonly lightning: RegExp;
6
7
  };
7
8
  export default Expressions;
@@ -11,5 +11,8 @@ export const Expressions = {
11
11
  get hashtag() {
12
12
  return /(?<=^|[^\p{L}#])#([\p{L}\p{N}\p{M}]+)/gu;
13
13
  },
14
+ get lightning() {
15
+ return /(?:lightning:)?(LNBC[A-Za-z0-9]+)/gim;
16
+ },
14
17
  };
15
18
  export default Expressions;
@@ -2,6 +2,7 @@ import { EventTemplate, NostrEvent } from "nostr-tools";
2
2
  import { DecodeResult } from "nostr-tools/nip19";
3
3
  import { Node as UnistNode, Parent } from "unist";
4
4
  import { type Token } from "@cashu/cashu-ts";
5
+ import { type ParsedInvoice } from "applesauce-core/helpers/bolt11";
5
6
  export interface CommonData {
6
7
  eol?: boolean;
7
8
  }
@@ -34,6 +35,7 @@ export interface CashuToken extends Node {
34
35
  export interface LightningInvoice extends Node {
35
36
  type: "lightning";
36
37
  invoice: string;
38
+ parsed: ParsedInvoice;
37
39
  }
38
40
  export interface Hashtag extends Node {
39
41
  type: "hashtag";
@@ -6,9 +6,10 @@ import { emojis } from "./emoji.js";
6
6
  import { createTextNoteATS } from "./parser.js";
7
7
  import { hashtags } from "./hashtag.js";
8
8
  import { galleries } from "./gallery.js";
9
+ import { lightningInvoices } from "./lightning.js";
9
10
  export const ParsedTextContentSymbol = Symbol.for("parsed-text-content");
10
11
  // default kind 1 transformers
11
- export const defaultTransformers = [nostrMentions, galleries, emojis, hashtags, cashuTokens];
12
+ export const defaultTransformers = [nostrMentions, galleries, emojis, hashtags, lightningInvoices, cashuTokens];
12
13
  /** Parsed and process a note with custom transformers */
13
14
  export function getParsedTextContent(event, content, transformers = defaultTransformers) {
14
15
  // process strings
@@ -5,3 +5,4 @@ export * from "./emoji.js";
5
5
  export * from "./parser.js";
6
6
  export * from "./hashtag.js";
7
7
  export * from "./gallery.js";
8
+ export * from "./lightning.js";
@@ -5,3 +5,4 @@ export * from "./emoji.js";
5
5
  export * from "./parser.js";
6
6
  export * from "./hashtag.js";
7
7
  export * from "./gallery.js";
8
+ export * from "./lightning.js";
@@ -0,0 +1,3 @@
1
+ import { type Transformer } from "unified";
2
+ import { Root } from "../nast/types.js";
3
+ export declare function lightningInvoices(): Transformer<Root>;
@@ -0,0 +1,25 @@
1
+ import { parseBolt11 } from "applesauce-core/helpers/bolt11";
2
+ import Expressions from "../helpers/regexp.js";
3
+ import { findAndReplace } from "../nast/find-and-replace.js";
4
+ export function lightningInvoices() {
5
+ return (tree) => {
6
+ findAndReplace(tree, [
7
+ [
8
+ Expressions.lightning,
9
+ (_, $1) => {
10
+ try {
11
+ const invoice = $1;
12
+ const parsed = parseBolt11(invoice);
13
+ return {
14
+ type: "lightning",
15
+ invoice,
16
+ parsed,
17
+ };
18
+ }
19
+ catch (error) { }
20
+ return false;
21
+ },
22
+ ],
23
+ ]);
24
+ };
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-content",
3
- "version": "0.0.0-next-20241106104112",
3
+ "version": "0.0.0-next-20241108100553",
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-20241106104112",
43
+ "applesauce-core": "0.0.0-next-20241108100553",
44
44
  "linkifyjs": "^4.1.3",
45
45
  "mdast-util-find-and-replace": "^3.0.1",
46
46
  "nostr-tools": "^2.10.1",