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
Event relays
addSeenRelayAdds a relay to the list of relay the event was seen ongetSeenRelaysGet the list of relays this event was seen on
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
getDeleteEventPointersGets a list of referenced event idsgetDeleteAddressPointersGet the list of replaceable event coordinates the event is referencing
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 asigner
Filters
isFilterEqualCheck if two filters are equal
Time
unixNowReturns the current unix timestamp
Feature helpers
Helpers for specific event kinds live in applesauce-common (and a few in applesauce-core) and are documented on the feature pages that use them, such as Profiles, Mailboxes & Outbox, Comments, and Zaps. Emoji helpers are covered in Content.
Factory Helpers
The applesauce-core 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