yaschema
    Preparing search index...

    Interface SchemaFunctions<ValueT>

    interface SchemaFunctions<ValueT> {
        allowNull: () => Schema<null | ValueT>;
        cloneValue: SyncCloner<ValueT>;
        cloneValueAsync: AsyncCloner<ValueT>;
        deserialize: SyncDeserializer<ValueT>;
        deserializeAsync: AsyncDeserializer<ValueT>;
        not: <ExcludeT>(
            notSchema: Schema<ExcludeT>,
            options?: { expectedTypeName?: string },
        ) => Schema<Exclude<ValueT, ExcludeT>>;
        optional: () => Schema<undefined | ValueT>;
        parse: SyncParser<ValueT>;
        parseAsync: AsyncParser<ValueT>;
        serialize: SyncSerializer<ValueT>;
        serializeAsync: AsyncSerializer<ValueT>;
        setDescription: (description?: string) => this;
        setExample: (example?: string) => this;
        setPreferredValidationMode: (
            validationMode: SchemaPreferredValidationMode,
        ) => this;
        stringify: SyncStringifier<ValueT>;
        stringifyAsync: AsyncStringifier<ValueT>;
        toString: () => string;
        validate: SyncValidator;
        validateAsync: AsyncValidator;
    }

    Type Parameters

    • ValueT
    Index

    Properties

    allowNull: () => Schema<null | ValueT>

    Returns a new schema that requires that either this schema is satisfied or that the value is null.

    cloneValue: SyncCloner<ValueT>

    Deeply clones a value

    if the schema requires async cloning

    cloneValueAsync: AsyncCloner<ValueT>

    Deeply clones a value

    deserialize: SyncDeserializer<ValueT>

    Deserialize (and validate) a value

    if the schema requires async deserialization

    deserializeAsync: AsyncDeserializer<ValueT>

    Deserialize (and validate) a value

    not: <ExcludeT>(
        notSchema: Schema<ExcludeT>,
        options?: { expectedTypeName?: string },
    ) => Schema<Exclude<ValueT, ExcludeT>>

    Returns a new schema that requires that this schema is satisfied but that the specified schema cannot be satisfied.

    optional: () => Schema<undefined | ValueT>

    Returns a new schema that requires that either this schema is satisfied or that the value is undefined.

    Parse and deserialize a value from a JSON string

    with a DeserializationResult<T> & { error: string } if parsing fails

    if the schema requires async deserialization

    parseAsync: AsyncParser<ValueT>

    Parse and deserialize a value from a JSON string

    with a DeserializationResult<T> & { error: string } if parsing fails

    Serialize (and validate) a value

    if the schema requires async serialization

    serializeAsync: AsyncSerializer<ValueT>

    Serialize (and validate) a value

    setDescription: (description?: string) => this

    Sets (replaces) the description metadata for this schema and returns the same schema

    setExample: (example?: string) => this

    Sets (replaces) the example metadata for this schema and returns the same schema

    setPreferredValidationMode: (
        validationMode: SchemaPreferredValidationMode,
    ) => this

    Sets (replaces) the preferred validation mode for this schema and returns the same schema.

    The lesser level of the preferred validation mode, which will be applied recursively depending on the depth parameter / unless further re-specified, and the specified validation mode, will be used, where the order is none < soft < hard.

    Type declaration

      • (validationMode: SchemaPreferredValidationMode): this
      • Parameters

        • validationMode: SchemaPreferredValidationMode

          The preferred validation mode for this schema Special Values:

          • "initial" - use the initially specified validation mode for the current operation (ex. the validation field of the options parameter to deserialize).
          • "inherit" - use the closet applicable mode from an ancestor schema level.

        Returns this

    Serialize (and validate) and stringify a value

    with a SerializationResult<T> & { error: string } if stringification fails

    if the schema requires async serialization

    stringifyAsync: AsyncStringifier<ValueT>

    Serialize (and validate) and stringify a value

    with a SerializationResult<T> & { error: string } if stringification fails

    toString: () => string

    Makes a string representation of this schema, mostly for debugging

    validate: SyncValidator

    Validate a value. This throws if the schema requires async validation.

    validateAsync: AsyncValidator

    Validate a value