0.0.9 • Published 6 years ago

transformer-js v0.0.9

Weekly downloads
11
License
MIT
Repository
-
Last release
6 years ago

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

Typedefs

transformerFactory(transformerConfig) ⇒ transformer

Kind: global function
Returns: transformer - a transformer instance

ParamTypeDescription
transformerConfigObject
transformerConfig.transformfunctionfunction to compute new value from any value matched by the matcher. If not defined the default transform will be used.
transformerConfig.matchersArray.<matcher>array of matcher objects

matcher : Object

Kind: global typedef
Properties

NameTypeDescription
transformfunctiondefault transform that is applied to any value matched unless
keyRejex | functionused to peform matching on keys.
valueRejex | functionused to perform matching on values.

transformer : Object

Kind: global typedef
Properties

NameTypeDescription
mapfunctionexecutes the transformer and returns a new transformed object
0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago