transformer-js

0.0.9 • Public • Published

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

Package Sidebar

Install

npm i transformer-js

Weekly Downloads

2

Version

0.0.9

License

MIT

Last publish

Collaborators

  • peterjcaulfield