Skip to content

Latest commit

 

History

History
38 lines (31 loc) · 1.18 KB

parser.md

File metadata and controls

38 lines (31 loc) · 1.18 KB

Parser

While the default parser of Decoverto is the builtin JSON object, it is possible to customize and overwrite it.

Custom parser

The parser can be specified when creating a new instance of Decoverto. Example:

import {Decoverto} from 'decoverto';
import customParser from 'custom-parser';

const decoverto = new Decoverto({
    parser: {
        parse: customParser.parse,
        toRaw: customParser.toBinary,
    },
})

Customize JSON parser

If you want to use a custom indent size, replacer, or reviver, the JsonParser class can be used. The options of JsonParser match the arguments of JSON.parse() and JSON.stringify(). All options are optional.

Example:

import {Decoverto, JsonParser} from 'decoverto';

const decoverto = new Decoverto({
    parser: new JsonParser({
        replacer: replacerFn,
        reviver: reviverFn,
        spaces: 4,
    }),
});