applesauce-content 0.10.0 → 0.12.0

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.
@@ -1 +1,2 @@
1
1
  export * from "./regexp.js";
2
+ export * from "./media.js";
@@ -1 +1,2 @@
1
1
  export * from "./regexp.js";
2
+ export * from "./media.js";
@@ -0,0 +1,3 @@
1
+ import { MediaAttachment } from "applesauce-core/helpers/file-metadata";
2
+ /** Returns all URLs in a content string that contain a sha256 hash */
3
+ export declare function getMediaAttachmentURLsFromContent(content: string): MediaAttachment[];
@@ -0,0 +1,15 @@
1
+ import { getSha256FromURL } from "applesauce-core/helpers/file-metadata";
2
+ import Expressions from "./regexp.js";
3
+ /** Returns all URLs in a content string that contain a sha256 hash */
4
+ export function getMediaAttachmentURLsFromContent(content) {
5
+ return (Array.from(content.matchAll(Expressions.link))
6
+ .map((match) => match[0])
7
+ // filter out invalid URLs
8
+ .filter((str) => URL.canParse(str))
9
+ // convert to URLs
10
+ .map((url) => new URL(url))
11
+ // only keep urls with sha256 hashes in the
12
+ .filter((url) => !!getSha256FromURL(url))
13
+ // convert to media attachments
14
+ .map((url) => ({ url: url.toString(), sha256: getSha256FromURL(url) })));
15
+ }
package/package.json CHANGED
@@ -1,37 +1,49 @@
1
1
  {
2
2
  "name": "applesauce-content",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Unified plugins for processing event content",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "keywords": [
9
- "nostr"
9
+ "nostr",
10
+ "applesauce"
10
11
  ],
11
12
  "author": "hzrd149",
12
13
  "license": "MIT",
13
14
  "files": [
14
- "dist"
15
+ "dist",
16
+ "applesauce"
15
17
  ],
16
18
  "exports": {
17
19
  ".": {
18
20
  "import": "./dist/index.js",
21
+ "require": "./dist/index.js",
19
22
  "types": "./dist/index.d.ts"
20
23
  },
21
24
  "./helpers": {
22
25
  "import": "./dist/helpers/index.js",
26
+ "require": "./dist/helpers/index.js",
23
27
  "types": "./dist/helpers/index.d.ts"
24
28
  },
29
+ "./helpers/*": {
30
+ "import": "./dist/helpers/*.js",
31
+ "require": "./dist/helpers/*.js",
32
+ "types": "./dist/helpers/*.d.ts"
33
+ },
25
34
  "./nast": {
26
35
  "import": "./dist/nast/index.js",
36
+ "require": "./dist/nast/index.js",
27
37
  "types": "./dist/nast/index.d.ts"
28
38
  },
29
39
  "./markdown": {
30
40
  "import": "./dist/markdown/index.js",
41
+ "require": "./dist/markdown/index.js",
31
42
  "types": "./dist/markdown/index.d.ts"
32
43
  },
33
44
  "./text": {
34
45
  "import": "./dist/text/index.js",
46
+ "require": "./dist/text/index.js",
35
47
  "types": "./dist/text/index.d.ts"
36
48
  }
37
49
  },
@@ -40,17 +52,17 @@
40
52
  "@types/hast": "^3.0.4",
41
53
  "@types/mdast": "^4.0.4",
42
54
  "@types/unist": "^3.0.3",
43
- "applesauce-core": "^0.10.0",
44
- "mdast-util-find-and-replace": "^3.0.1",
45
- "nostr-tools": "^2.10.3",
55
+ "applesauce-core": "^0.12.0",
56
+ "mdast-util-find-and-replace": "^3.0.2",
57
+ "nostr-tools": "^2.10.4",
46
58
  "remark": "^15.0.1",
47
59
  "remark-parse": "^11.0.0",
48
60
  "unified": "^11.0.5",
49
61
  "unist-util-visit-parents": "^6.0.1"
50
62
  },
51
63
  "devDependencies": {
52
- "typescript": "^5.6.3",
53
- "vitest": "^2.1.8"
64
+ "typescript": "^5.7.3",
65
+ "vitest": "^3.0.5"
54
66
  },
55
67
  "funding": {
56
68
  "type": "lightning",