Bumpover exposes the following API:
import {
Bumpover,
JSONBumpover,
XMLBumpover
} from 'bumpover'
new Bumpover(rules: Array, options: Object) => bumper
The Bumpover
class receives rules
validating and converting data, and optional options
to customize bumping behaviors.
const Rule = struct({
match: 'function',
update: 'function',
struct: 'function?',
childKey: 'string?'
})
const Rules = struct([Rule])
Each rule should provide its match
and update
props, with an optional struct
.
(node: Node) => shouldUpdate: boolean
Decide if a rule should be applied to current node. For each node, only the first rule matching it can be applied. So it makes sense putting the "universal" rules back in the rules array as fallback.
(node: Node) => Promise<{ node: NewNode, action?: 'next'|'stop' }>
Update the selected node into new shape inside promise, resolve your new node in the node
field, with an optional action
specifying whether continue traversing children of current node. If not, children of current node will be preserved by default.
Function
Optional struct validating NewNode
.
string
Optional key string referencing children of a node matched by the rule. This will overwrite options.childKey
.
const Options = struct({
defaultValue: 'any',
ignoreUnknown: 'boolean',
childKey: 'string',
beforeMatch: 'function',
onUnmatch: 'function',
serializer: 'function',
deserializer: 'function'
})
Following options are supported for bumping data.
Default value when bumper.bump
resolves void data, null
by default.
Decide if current node should be ignored when no rule is matched, false
by default.
Key string referencing children of a node. 'children'
by default.
Called before matching rules for current node. This handler does not affect subsequent traversing. (node) => {}
by default.
Called when no rule is found for current node and ignoreKnown === false
. This handler does not affect subsequent traversing. (node) => {}
by default.
Providing wrong
childKey
may result in weird data shape.
Function serializing JSON data into your data structure. (a) => a
by default.
Function parsing your data structure into JSON. (a) => a
by default.
Object
Instance of Bumpover
class.
(input: any) => Promise<output: any>
Bump input
data into output
.
(input: any, expected: any) => Promise
Compare whether input
can be bumped into expected
.
(input: any) => Promise
Test if input
can be bumped without rejection.
Conform to same API as Bumpover
, with its bump
method receives and yields XML string.
Conform to same API as Bumpover
, with deserializer
and serializer
replaced into JSON.parse
and JSON.stringify
.