0.5.0 • Published 3 years ago
@directdb/json-handler v0.5.0
@directdb/json-handler
JSON file handler for DirectDB.
Install
npm i @directdb/json-handler
# OR
yarn add @directdb/json-handler
Usage
The main package directdb
already includes @directdb/json-handler
.
If you want to create your own variant of DirectDB with this handler, you can compose one with @directdb/core
:
import directdb from '@directdb/core'
import jsonHandler from '@directdb/json-handler'
const db = await directdb('.', { fileHandlers: [jsonHandler] })
Options
The handler accepts the following options:
const options = {
replacer: null,
reviver: undefined,
space: 2,
}
Refer to the MDN docs for the JavaScript JSON object's replacer, reviver, and space arguments for more information.
Customize your file handler options like so:
import directdb from 'directdb'
import jsonHandler from '@directdb/json-handler'
jsonHandler.options = {
space: '\t', // use tabs instead of spaces
}
const db = await directdb({ fileHandlers: [jsonHandler] })
Options Type Definition
The package exports the TypeScript type interface of this options object. In .ts
files you can import this type as a helper for constructing the options object:
import * as JsonHandler from '@directdb/json-handler'
const options: JsonHandler.Options = {
/* options*/
}