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...
- matcher :
Object
- transformer :
Object
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 |
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. |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
map | function |
executes the transformer and returns a new transformed object |