applesauce-core 0.0.0-next-20241212230350 → 0.0.0-next-20241213171848

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,3 @@
1
+ import { NostrEvent } from "nostr-tools";
2
+ /** Returns the NIP-36 content-warning for an event. returns boolean if there is no "reason" */
3
+ export declare function getContentWarning(event: NostrEvent): string | boolean;
@@ -0,0 +1,8 @@
1
+ /** Returns the NIP-36 content-warning for an event. returns boolean if there is no "reason" */
2
+ export function getContentWarning(event) {
3
+ const tag = event.tags.find((t) => t[0] === "content-warning");
4
+ if (tag)
5
+ return tag[1] || true;
6
+ else
7
+ return false;
8
+ }
@@ -1,6 +1,7 @@
1
1
  export * from "./bolt11.js";
2
2
  export * from "./cache.js";
3
3
  export * from "./comment.js";
4
+ export * from "./content.js";
4
5
  export * from "./delete.js";
5
6
  export * from "./emoji.js";
6
7
  export * from "./event.js";
@@ -1,6 +1,7 @@
1
1
  export * from "./bolt11.js";
2
2
  export * from "./cache.js";
3
3
  export * from "./comment.js";
4
+ export * from "./content.js";
4
5
  export * from "./delete.js";
5
6
  export * from "./emoji.js";
6
7
  export * from "./event.js";
@@ -29,3 +29,11 @@ export declare function getZapRequest(zap: NostrEvent): import("nostr-tools").Ev
29
29
  * DOES NOT validate LNURL address
30
30
  */
31
31
  export declare function isValidZap(zap?: NostrEvent): boolean;
32
+ export type ZapSplit = {
33
+ pubkey: string;
34
+ percent: number;
35
+ weight: number;
36
+ relay?: string;
37
+ };
38
+ /** Returns the zap splits for an event */
39
+ export declare function getZapSplits(event: NostrEvent): ZapSplit[] | undefined;
@@ -81,3 +81,15 @@ export function isValidZap(zap) {
81
81
  return false;
82
82
  }
83
83
  }
84
+ /** Returns the zap splits for an event */
85
+ export function getZapSplits(event) {
86
+ const tags = event.tags.filter((t) => t[0] === "zap" && t[1] && t[3]);
87
+ if (tags.length > 0) {
88
+ const targets = tags
89
+ .map((t) => ({ pubkey: t[1], relay: t[2], weight: parseFloat(t[3]) }))
90
+ .filter((p) => Number.isFinite(p.weight));
91
+ const total = targets.reduce((v, p) => v + p.weight, 0);
92
+ return targets.map((p) => ({ ...p, percent: p.weight / total }));
93
+ }
94
+ return undefined;
95
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20241212230350",
3
+ "version": "0.0.0-next-20241213171848",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",