@konemono/nostr-content-parser
Version: 
Parse Nostr content into tokens
83 lines (82 loc) • 2.76 kB
TypeScript
export declare const TokenType: {
    readonly TEXT: "text";
    readonly NIP19: "nip19";
    readonly RELAY: "relay";
    readonly URL: "url";
    readonly CUSTOM_EMOJI: "custom_emoji";
    readonly HASHTAG: "hashtag";
    readonly LN_ADDRESS: "ln_address";
    readonly LN_URL: "ln_url";
    readonly LNBC: "lnbc";
    readonly EMAIL: "email";
    readonly CASHU_TOKEN: "cashu_token";
    readonly BITCOIN_ADDRESS: "bitcoin_address";
    readonly NIP_IDENTIFIER: "nip_identifier";
    readonly LEGACY_REFERENCE: "legacy_reference";
};
export type TokenType = (typeof TokenType)[keyof typeof TokenType];
export declare const NIP19SubType: {
    readonly NPUB: "npub";
    readonly NPROFILE: "nprofile";
    readonly NOTE: "note";
    readonly NEVENT: "nevent";
    readonly NADDR: "naddr";
    readonly NSEC: "nsec";
};
export type NIP19SubType = (typeof NIP19SubType)[keyof typeof NIP19SubType];
export declare const NIP19_TYPE_MAP: Record<string, NIP19SubType>;
export interface Token {
    type: TokenType;
    content: string;
    start: number;
    end: number;
    metadata?: Record<string, unknown>;
}
export declare const LN_ADDRESS_PATTERN: RegExp;
export declare function isLightningAddress(emailLike: string): boolean;
export declare function findCustomEmojiMetadata(emojiName: string, tags: string[][]): {
    url: string;
} | null;
export declare const NIP19_PATTERNS: {
    readonly npub: RegExp;
    readonly nprofile: RegExp;
    readonly note: RegExp;
    readonly nevent: RegExp;
    readonly naddr: RegExp;
    readonly nsec: RegExp;
};
export declare const NIP19_PLAIN_PATTERNS: {
    npub: RegExp;
    nprofile: RegExp;
    note: RegExp;
    nevent: RegExp;
    naddr: RegExp;
    nsec: RegExp;
};
export declare const URL_PATTERN: RegExp;
export declare const LN_URL_PATTERN: RegExp;
export declare const LNBC_PATTERN: RegExp;
export declare const CASHU_TOKEN_PATTERN: RegExp;
export declare const EMAIL_PATTERN: RegExp;
export declare const CUSTOM_EMOJI_PATTERN: RegExp;
export declare const HASHTAG_PATTERN: RegExp;
export declare const RELAY_URL_PATTERN: RegExp;
export declare const LEGACY_REFERENCE_PATTERN: RegExp;
export declare const BITCOIN_ADDRESS_PATTERNS: {
    readonly legacy: RegExp;
    readonly script: RegExp;
    readonly bech32: RegExp;
};
export declare const NIP_IDENTIFIER_PATTERN: RegExp;
export declare function parseNipIdentifier(nipId: string): {
    number: string;
    hasAlpha: boolean;
    hasDigit: boolean;
};
export declare const cleanUrlEnd: (url: string) => string;
export declare function findLegacyReferenceMetadata(referenceMatch: string, tags: string[][]): {
    tagIndex: number;
    tagType?: string;
    referenceId?: string;
    referenceType?: "npub" | "note" | "naddr" | "unknown";
} | null;