Function safeParseToV2

  • Takes unknown data, and on success returns a { success: true, data: Cards.V2 }.

    On error, it instead returns a { success: false; error: ZodError }.

    If the input is a V1 card, it will be converted to V2.

    For an alternative which directly returns a Cards.V2 but throws on failure, see parseToV2

    Example

    import * as Cards from 'character-card-utils'

    Cards.safeParseToV2(validV2Card) //=> return type { success: true; data: Cards.V2 }
    Cards.safeParseToV2(validV1Card) //=> return type { success: true; data: Cards.V2 }
    Cards.safeParseToV2(invalidCard) //=> return type { success: false; error: ZodError }

    Parameters

    • data: unknown

    Returns SafeParseReturnType<{
        spec: "chara_card_v2";
        spec_version: string;
        data: {
            name: string;
            description: string;
            personality: string;
            scenario: string;
            first_mes: string;
            mes_example: string;
            creator_notes: string;
            system_prompt: string;
            post_history_instructions: string;
            alternate_greetings: string[];
            character_book?: { entries: { keys: string[]; content: string; extensions: Record<string, any>; enabled: boolean; insertion_order: number; case_sensitive?: boolean | undefined; name?: string | undefined; ... 6 more ...; position?: "before_char" | ... 1 more ... | undefined; }[]; ... 5 more ...; recursive_scanning?: boolean | undefin...;
            tags: string[];
            creator: string;
            character_version: string;
            extensions: Record<string, any>;
        };
    }, {
        spec: "chara_card_v2";
        spec_version: string;
        data: {
            name: string;
            description: string;
            personality: string;
            scenario: string;
            first_mes: string;
            mes_example: string;
            creator_notes: string;
            system_prompt: string;
            post_history_instructions: string;
            alternate_greetings: string[];
            character_book?: { entries: { keys: string[]; content: string; extensions: Record<string, any>; enabled: boolean; insertion_order: number; case_sensitive?: boolean | undefined; name?: string | undefined; ... 6 more ...; position?: "before_char" | ... 1 more ... | undefined; }[]; ... 5 more ...; recursive_scanning?: boolean | undefin...;
            tags: string[];
            creator: string;
            character_version: string;
            extensions: Record<string, any>;
        };
    }>

Generated using TypeDoc