Skip to content

How to override DataParser methods?

DataParser exposes an override system that lets you add or replace instance methods or properties without forking the library.

Implementation example

Steps

  1. Extend the DataParser interface via declare module so TypeScript knows your API (parseOrThrow in the example).
  2. Define the method with dataParserInit.overrideHandler.setMethod(...) while reusing existing methods (parser.parse, parser.asyncParse, etc.).
  3. Use the plugin: once the method is registered, all your parsers (DP.*, DPE.*) share it at runtime.

See also

  • Recover – To intercept errors on the user side without a global override.

Released under the MIT license.