applesauce-core 0.0.0-next-20241114194041 → 0.0.0-next-20241115160057
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/dist/helpers/profile.d.ts +0 -7
- package/dist/helpers/profile.js +13 -25
- package/package.json +1 -1
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { NostrEvent } from "nostr-tools";
|
|
2
2
|
export declare const ProfileContentSymbol: unique symbol;
|
|
3
|
-
declare module "nostr-tools" {
|
|
4
|
-
interface Event {
|
|
5
|
-
[ProfileContentSymbol]?: ProfileContent | Error;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
3
|
export type ProfileContent = {
|
|
9
4
|
name?: string;
|
|
10
5
|
display_name?: string;
|
|
@@ -21,5 +16,3 @@ export type ProfileContent = {
|
|
|
21
16
|
};
|
|
22
17
|
/** Returns the parsed profile content for a kind 0 event */
|
|
23
18
|
export declare function getProfileContent(event: NostrEvent): ProfileContent;
|
|
24
|
-
export declare function getProfileContent(event: NostrEvent, quite: false): ProfileContent;
|
|
25
|
-
export declare function getProfileContent(event: NostrEvent, quite: true): ProfileContent | Error;
|
package/dist/helpers/profile.js
CHANGED
|
@@ -1,28 +1,16 @@
|
|
|
1
|
+
import { getOrComputeCachedValue } from "./cache.js";
|
|
1
2
|
export const ProfileContentSymbol = Symbol.for("profile-content");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
/** Returns the parsed profile content for a kind 0 event */
|
|
4
|
+
export function getProfileContent(event) {
|
|
5
|
+
return getOrComputeCachedValue(event, ProfileContentSymbol, () => {
|
|
6
|
+
const profile = JSON.parse(event.content);
|
|
7
|
+
// ensure nip05 is a string
|
|
8
|
+
if (profile.nip05 && typeof profile.nip05 !== "string")
|
|
9
|
+
profile.nip05 = String(profile.nip05);
|
|
10
|
+
// add missing protocol to website
|
|
11
|
+
if (profile.website?.startsWith("http") === false) {
|
|
12
|
+
profile.website = "https://" + profile.website;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
cached = event[ProfileContentSymbol] = e;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (cached === undefined) {
|
|
18
|
-
throw new Error("Failed to parse profile");
|
|
19
|
-
}
|
|
20
|
-
else if (cached instanceof Error) {
|
|
21
|
-
if (!quite)
|
|
22
|
-
throw cached;
|
|
23
|
-
else
|
|
24
|
-
return cached;
|
|
25
|
-
}
|
|
26
|
-
else
|
|
27
|
-
return cached;
|
|
14
|
+
return profile;
|
|
15
|
+
});
|
|
28
16
|
}
|