Skip to content

Latest commit

 

History

History
88 lines (65 loc) · 2.56 KB

README.md

File metadata and controls

88 lines (65 loc) · 2.56 KB

transformer-js

npm version codecov CircleCI

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

transformerFactory(transformerConfig)transformer

Typedefs

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

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