transformer-js
v0.0.9
Published
[![npm version](https://badge.fury.io/js/transformer-js.svg)](https://badge.fury.io/js/transformer-js) [![codecov](https://codecov.io/gh/peterjcaulfield/transformer-js/branch/master/graph/badge.svg)](https://codecov.io/gh/peterjcaulfield/transformer-js) [
Downloads
28
Maintainers
Readme
transformer-js
transformer-js is a library for performing transformations on objects. There are many use cases. One example is log redaction:
import transformerFactory from './transformer-js'
const config = {
transform: val => '[REDACTED]',
matchers: [{
key: /^token/
}]
}
const transform = transformerFactory(config)
const logObj = {
id: 1,
token: 'dfadf2334hjlkjkxxnqqkkq4=='
}
console.log(transform.map(logObj))
// outputs
{
id: 1,
token: '[REDACTED]'
}
Examples directory coming soon...
API
Functions
Typedefs
transformerFactory(transformerConfig) ⇒ transformer
Kind: global function
Returns: transformer - a transformer instance
| Param | Type | Description | | --- | --- | --- | | transformerConfig | Object | | | transformerConfig.transform | function | function to compute new value from any value matched by the matcher. If not defined the default transform will be used. | | transformerConfig.matchers | Array.<matcher> | array of matcher objects |
matcher : Object
Kind: global typedef
Properties
| Name | Type | Description | | --- | --- | --- | | transform | function | default transform that is applied to any value matched unless | | key | Rejex | function | used to peform matching on keys. | | value | Rejex | function | used to perform matching on values. |
transformer : Object
Kind: global typedef
Properties
| Name | Type | Description | | --- | --- | --- | | map | function | executes the transformer and returns a new transformed object |