@avanio/variable-util
    Preparing search index...

    Class JsonConfigParser<Out>

    Config parser to parse JSON string as object

    const objectSchema = z.object({
    foo: z.string(),
    baz: z.string(),
    secret: z.string(),
    });
    // parses '{"foo": "bar", "baz": "qux", "secret": "secret"}' string to {foo: "bar", baz: "qux", secret: "secret"}
    const fooBarJsonParser = new JsonConfigParser({
    validate: (value) => objectSchema.parse(value),
    protectedKeys: ['secret'],
    showProtectedKeys: 'prefix-suffix', // shows secret value with few characters from start and end on logging
    });

    v1.0.0

    Type Parameters

    • Out extends Record<string, unknown>

      the type of the output object

    Implements

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    name: string = 'jsonConfigParser'

    name of the parser

    Methods

    • Config parser function

      Parameters

      Returns object

      Error if parsing fails

    • Optional value validation after parsing

      Parameters

      Returns Promise<undefined | Out>

      Error if validation fails

    • Optional build readable string from value for log (can hide sensitive part from logs) else toString is used

      Parameters

      • config: Out

        value to log

      Returns string

    • Build readable string from value

      Parameters

      Returns string