@exocet/value-flagger
v1.0.0
Published
ES6 Javascript value flagger
Downloads
2
Readme
@exocet/value-flagger
This package was created as an alternative to pass null
values through protobuf encoded JSON. It search for null
values and creates a boolean flag indicating that field was null
. This package doesn't use recursion so it's very fast.
Methods
encode(source[, options])
const { encode } = require('@exocet/value-flagger');
Encode a source object or array flagging the source searching for replaceValue
and flagging the object key with the flagKey
as property's prefix.
- source - object or array to encode.
- options.replaceValue - value to replace with flags, the default value is
null
. - options.flagKey - string with the prefix to be added to encoded object keys, the default value is
'__isNull_'
.
Return value: the source object or array with encoding flags.
decode(source[, options])
const { decode } = require('@exocet/value-flagger');
Decode a source object or array removing flags from the source and adding original keys as properties with replaceValue
as value.
- source - object or array to decode.
- options.replaceValue - value to replace flags, the default value is
null
. - options.flagKey - string with the prefix to be removed from decoded object keys, the default value is
'__isNull_'
.
Return value: the source object without encoding flags and keys set to original values.
isObject(value)
const { isObject } = require('@exocet/value-flagger');
Checks if a value is an object.
Return value: boolean.
Tests are done with mocha, chai and nyc for coverage. The lint preset is based on airbnb preset.