This package has been deprecated

Author message:

WARNING: This project has been renamed to @trojs/mutator. Install using @trojs/mutator instead.

@hckrnews/mutator

0.3.7 • Public • Published

Mutate the value when set some data

NPM version Build Status Coveralls Status Scrutinizer Code Quality

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 @hckrnews/objects or yarn add @hckrnews/objects

Test the package

npm run test or yarn test

Example usage

import DefaultMutator from '@hckrnews/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*'
}

Dependencies (0)

    Dev Dependencies (21)

    Package Sidebar

    Install

    npm i @hckrnews/mutator

    Weekly Downloads

    98

    Version

    0.3.7

    License

    MIT

    Unpacked Size

    6.28 kB

    Total Files

    5

    Last publish

    Collaborators

    • epeus
    • w3news