Helpers
applesauce-core and other packages export helper methods for working with events.
WARNING
Some helper methods may throw errors. make sure your app can handle errors correctly.
Core helpers
The applesauce-core package contains the majority of the helper methods
Events
isEventChecks if an object is a nostr eventmarkFromCacheMarks an event as being from the cacheisFromCacheChecks if an event is marked from cachegetTagValueGets the value of the first tag matching the namegetIndexableTagsGet aSetof all indexable tags on the event
Profiles
getProfileContentReturns the parsed profile content for a kind 0 eventisValidProfileChecks if the content of the kind 0 event is valid JSON
Mailboxes
getInboxesGets the inbox relays from a10002eventgetOutboxesGets the outbox relays from a10002event
Comments
getCommentRootPointerGet the root pointer for a NIP-22 commentgetCommentReplyPointerGet the reply pointer for a NIP-22 comment
Event relays
addSeenRelayAdds a relay to the list of relay the event was seen ongetSeenRelaysGet the list of relays this event was seen on
Zaps
isValidZapChecks if an event is a valid zap and can be parsedgetZapSenderGets the senders pubkeygetZapRecipientGets the pubkey of the user who received the zapgetZapPaymentGets the parsed bolt11 invoicegetZapAddressPointerGets the address pointer of the zapgetZapEventPointerGets the event pointer of the zapgetZapRequestGets the zap request event inside the zap event
Lightning
parseBolt11Parses a bolt11 lightning invoiceparseLNURLOrAddressParses a LNURL or lightning address into a LNURLp
Pointers
getEventPointerFromETagCreates anEventPointerfrom a standard "e" taggetEventPointerFromQTagCreates anEventPointerfrom a standard "q" taggetAddressPointerFromATagCreates anAddressPointerfrom a standard "a" taggetProfilePointerFromPTagCreates anProfilePointerfrom a standard "p" taggetAddressPointerForEventReturns anAddressPointerfor a replaceable event
Delete events
getDeleteIdsGets a list of referenced event idsgetDeleteCoordinatesGet the list of replaceable event coordinates the event is referencing
Emojis
getPackNameGets the emoji pack namegetEmojisGet all emojis in an emoji packgetEmojiTagCGets an "emoji" tag that matches an emoji code
URLs
getURLFilenamereturns the filename part fo the path in a URLisAudioURLChecks if the URL ends with a audio file extensionisVideoURLChecks if the URL ends with a video file extensionisImageURLChecks if the URL ends with a image file extensionisStreamURLChecks if the URL ends with a stream file extension
Tags
isETagChecks if tag is an "e" tag and has at least one valueisATagChecks if tag is an "a" tag and has at least one valueisPTagChecks if tag is an "p" tag and has at least one valueisDTagChecks if tag is an "d" tag and has at least one valueisRTagChecks if tag is an "r" tag and has at least one valueisTTagChecks if tag is an "t" tag and has at least one value
Hidden Tags
Hidden tags are used in NIP-51 lists and NIP-60 wallets
canHaveHiddenTagsChecks if a given event kind can have hidden tagshasHiddenTagsChecks if an event has hidden tagsgetHiddenTagsReturns the hidden tags for an event if they are unlockedisHiddenTagsUnlockedChecks if the hidden tags are lockedunlockHiddenTagsUnlocks the hidden tags using asignermodifyEventTagsModifies an events public or hidden tags
Filters
isFilterEqualCheck if two filters are equal
Time
unixNowReturns the current unix timestamp
Factory Helpers
The applesauce-factory package exports some helpers for building events and tags
Some of the most useful ones are
fillAndTrimTagReplacesundefinedornullin tags with""and trims to tag down to a set length if it ends with""createQTagFromEventPointerCreates a"q"tag for from anEventPointerto tag quoted eventscreatePTagFromProfilePointerCreates a"p"tag for from aProfilePointerto tag mentioned pubkeys