map-factory
Advanced tools
Changelog
3.7.1
Fixed a bug when traversing an array of a non-existing object.
Changelog
3.7.0
The notFound
transform function for the to()
method will now supply the the type of non-value they discovered (null
or undefined
).
Fixed a bug where the set
method could not be used after the map
method.
Changelog
3.6.1
Fixed a bug with the keep method.
const source = {
"foo": {
"foo1": "bar",
"bar": "bar"
}
}
mapper.map("foo").keep(["foo1", "foo2"]);
// foo2 should not exist here
{
"foo": {
"foo1": "bar",
"foo2": undefined
}
}
Changelog
3.6.0
The to()
method now takes a optional notFound
transform that allows for basic conditional logic to be applied. For convenience, you can also supply a basic value.
const mapper = createMapper();
// These two mappings are logically equivalent
mapper
.map("amount").to("data", amount => `£${amount}`, () => "£0");
.map("amount").to("data", amount => `£${amount}`, "£0");
Changelog
3.5.0
The source field for the map()
method is now optional. If omitted, the method will get the entire source object. This is quite useful when combined with pipeline transformations.
const mapper = createMapper();
mapper
.map().to("data");
.execute({"a": "b"})
/*
{
data: {"a": "b"}
}
*/
Changelog
3.4.0
Added the keep()
pipeline transformation.
More details can found in the Pipeline Transformations section of the README.
Changelog
3.3.0
Added compact()
, first()
, and last()
Pipeline Transformations for more detailed control over arrays.
More details can found in the Pipeline Transformations section of the README.
Changelog
3.2.0
Mapping can now be conditionally based on other values in the source document using acceptIf()
and rejectIf()
.
More details can found in the Pipeline Transformations section of the README.