web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

wasm.ts (840B)


      1 import init_wasm, { type InitOutput } from "@radroots/events-codec-wasm";
      2 import type { NostrEventTags } from "../types/lib.js";
      3 
      4 let codec_wasm_init_promise: Promise<InitOutput> | null = null;
      5 
      6 export const ensure_codec_wasm = async (): Promise<void> => {
      7     if (!codec_wasm_init_promise) codec_wasm_init_promise = init_wasm();
      8     await codec_wasm_init_promise;
      9 };
     10 
     11 const is_string_array = (value: unknown): value is string[] =>
     12     Array.isArray(value) && value.every((item) => typeof item === "string");
     13 
     14 const is_tag_list = (value: unknown): value is NostrEventTags =>
     15     Array.isArray(value) && value.every(is_string_array);
     16 
     17 export const parse_tags_json = (value: string): NostrEventTags => {
     18     const parsed: unknown = JSON.parse(value);
     19     if (!is_tag_list(parsed)) throw new Error("invalid nostr tags");
     20     return parsed;
     21 };