Function getConfigParser

  • Creates a function to validate an user configuration object

    Type Parameters

    • T extends Record<string, any>

      type of input config

    • U extends Record<string, any> = T

      type of config after parsing

    Parameters

    • defaults: Required<U>

      the default configuration

    • Optional parsers: ConfigParsers<T, U>

      function used to parse/validate the configuration

      Optional

    Returns ConfigParser<T, U>

    Example

    type MyConfig = {
    value: number;
    label?: string;
    };

    const getConfig<MyConfig>({
    value: 1,
    label: 'Title',
    }, {
    value(value, { defValue }) {
    return value < 10 ? value : defValue;
    }
    });

    const config = getConfig({ value: 3 });

Generated using TypeDoc