1.1.0 • Published 3 years ago
data-shifter v1.1.0
data-shifter
This package provides a data validation and transformation pipeline. Due to the functional nature of this package, it's easy to swap the components of the pipeline to dynamically generate different transformations.
Usage
The convert
module leverages currying to build this pipeline:
const transformed = await convert(validator, fn=validate)(shifter)(data);
Where the arguments are:
validator
: A schema validator (yup is used by the provided validators)fn
(optional): the name of thevalidator
function to be called- Any promise-based validator with a
fn
that resolves with the validated data and rejects with an error can be used
shifter
: A function that performs the transformation and returns the transformed datadata
: An object to be validated and transformed
This package comes with a few predefined validators and shifters which can be obtained using the resolvers
module (example), but the real power of this library comes from the fact that the pipeline just acts as a framework that custom validators and shifters can be plugged into (example).