@nevware21/tripwire - v0.1.4
    Preparing search index...

    Interface IAssertConfigDefaults

    Export the interfaces

    interface IAssertConfigDefaults {
        addFormatter: (formatter: IFormatter) => IRemovable;
        circularMsg?: () => string;
        clone: (options?: IAssertConfig) => IAssertConfig;
        defAssertMsg?: MsgSource;
        defFatalMsg?: MsgSource;
        format?: IFormatterOptions;
        fullStack?: boolean;
        isVerbose?: boolean;
        removeFormatter: (formatter: IFormatter) => void;
        reset: () => void;
    }

    Hierarchy (View Summary)

    Index

    Properties

    addFormatter: (formatter: IFormatter) => IRemovable

    Adds a new default value formatter that will be used to for all new assertion contexts

    Type Declaration

    The returned IRemovable can be used to remove the formatter when it is no longer needed.

    circularMsg?: () => string

    Defines a custom message to display when a circular reference is detected in a value. The default is a function that returns the string "[]" in cyan color using @nevware21/chromacon.

    This is used to provide a more descriptive message for circular references in assertion errors.

    0.1.3

    const config = {
    circularMsg: () => "Circular reference detected"
    };
    clone: (options?: IAssertConfig) => IAssertConfig

    Returns the current config options in a new plain object

    Type Declaration

    defAssertMsg?: MsgSource

    Defiines the default assertion failure message to display if no message is provided.

    "assertion failed"
    
    defFatalMsg?: MsgSource

    Defines the default fatal message to display if no message is provided.

    "fatal assertion failure"
    

    This is used for fatal errors that are not assertion failures.

    Options for configuring value formatting.

    These options allow you to customize how values are formatted in assertion error messages. You can provide custom formatters to override the default formatting behavior for specific types. These formatters will be checked before the default formatters, allowing you to provide specialized formatting for certain value types.

    Additionally, you can control post-processing of the formatted output using IFormatterOptions.finalize and IFormatterOptions.finalizeFn to escape ANSI codes, wrap output, or apply other transformations.

    0.1.3

    import { assertConfig } from '@nevware21/tripwire';
    import { eFormatResult } from '@nevware21/tripwire';
    import { escapeAnsi, gray, replaceAnsi } from '@nevware21/chromacon';

    // Example 1: Custom formatters with default ANSI escaping
    assertConfig.format = {
    finalize: true, // Enable default escapeAnsi
    formatters: [
    {
    name: "stringFormatter",
    value: (ctx, value) => {
    if (typeof value === 'string') {
    return { res: eFormatResult.Ok, val: `'${value}'` };
    }
    return { res: eFormatResult.Skip };
    }
    }
    ]
    };

    // Example 2: Custom formatters with custom finalization
    assertConfig.format = {
    finalize: true,
    finalizeFn: (value) => replaceAnsi(value, (match) => gray(escapeAnsi(match))),
    formatters: [
    {
    name: "arrayFormatter",
    value: (ctx, value) => {
    if (Array.isArray(value)) {
    return { res: eFormatResult.Ok, val: `[${value.length} items]` };
    }
    return { res: eFormatResult.Skip };
    }
    }
    ]
    };
    fullStack?: boolean

    Identifies if the current context is in full-stack mode, which will include the full stack trace in the error message if an assertion fails.

    false
    
    isVerbose?: boolean

    Identifies if the current context is verbose mode, which will include additional information in the execution context and any resulting assertion failures.

    false
    
    removeFormatter: (formatter: IFormatter) => void

    Removes a value formatter from the current context options

    Type Declaration

      • (formatter: IFormatter): void
      • Parameters

        • formatter: IFormatter

          The value formatter to remove

        Returns void

    reset: () => void

    Resets the current config options to their default values removing any customizations

    This will restore all config options to their original default values as defined in package defaults.