Global Feed Post Login
Replying to Avatar bitcoinplebdev

To illustrate how bad kind0 is sometimes below is a real function I wrote (unfortunately) like 2 years ago to get users fields from their profile:

export const findKind0Fields = async kind0 => {

let fields = {};

const usernameProperties = ['name', 'displayName', 'display_name', 'username', 'handle', 'alias'];

const pubkeyProperties = ['pubkey', 'npub', '_pubkey'];

const findTruthyPropertyValue = (object, properties) => {

for (const property of properties) {

if (object?.[property]) {

return object[property];

}

}

return null;

};

const username = findTruthyPropertyValue(kind0, usernameProperties);

if (username) {

fields.username = username;

}

const avatar = findTruthyPropertyValue(kind0, [

'picture',

'avatar',

'profilePicture',

'profile_picture',

'image',

]);

if (avatar) {

fields.avatar = avatar;

}

const pubkey = findTruthyPropertyValue(kind0, pubkeyProperties);

if (pubkey) {

fields.pubkey = pubkey;

}

const lud16 = findTruthyPropertyValue(kind0, ['lud16', 'lightning', 'lnurl', 'lnurlp', 'lnurlw']);

if (lud16) {

fields.lud16 = lud16;

}

const nip05 = findTruthyPropertyValue(kind0, ['nip05']);

if (nip05) {

fields.nip05 = nip05;

}

return fields;

};

https://github.com/AustinKelsay/plebdevs/blob/d8bba02a2f6c02b4661007b4847a9472498d6f2d/src/utils/nostr.js

nostr:nevent1qqstjcgxmljvngnjktq6f2h0tranepj6akv2atx4e8zx8x7t99txrxgpzemhxue69uhhv6t5daezumn0wd68yvfwvdhk67ac8zg

Avatar
Vitor Pamplona 3w ago

Yes, lol

Reply to this note

Please Login to reply.

Discussion

No replies yet.