JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 52
  • Score
    100M100P100Q113124F
  • License MIT

Mutate the value when set some data

Package Exports

  • @trojs/mutator
  • @trojs/mutator/src/default.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@trojs/mutator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Mutate the value when set some data

NPM version Coveralls Status

With this package you can define some setters that are optional. So it change the value for the defined setters, but if you don't pass the key, it doesnt set the key.

Installation

npm install @trojs/objects or yarn add @trojs/objects

Test the package

npm run test or yarn test

Example usage

import DefaultMutator from '@trojs/mutator'

class ExampleMutator extends DefaultMutator {
  setSkuAttribute (sku) {
    return `*${sku}*`
  }
}

const result = ExampleMutator.create({ sku: '42', test: 'ok' })
{
    sku: '*42*',
    test: 'ok'
}

const result = ExampleMutator.create({ sku: '42' })
{
    sku: '*42*'
}

const result = ExampleMutator.create({ test: 'ok' })
{
    test: 'ok'
}

You can also hydrate the object with new data

const result = ExampleMutator.create({ test: 'ok', test2: 'also ok' })
{
    test: 'ok',
    test2: 'also ok'
}

result.hydrate({ sku: 43})
{
    test: 'ok',
    test2: 'also ok',
    sku: '*43*'
}

result.hydrate({ test: 'another text'})
{
    test: 'another text',
    test2: 'also ok',
    sku: '*43*'
}