@hckrnews/normalizer

Normalizer objects

Usage no npm install needed!

<script type="module">
  import hckrnewsNormalizer from 'https://cdn.skypack.dev/@hckrnews/normalizer';
</script>

README

Normalize objects

NPM version Bugs Code Smells Duplicated Lines (%) Maintainability Rating Reliability Rating Security Rating Technical Debt Vulnerabilities Quality Gate Status Coverage

Installation

npm install @hckrnews/normalizer or yarn add @hckrnews/normalizer

Test the package

npm run test or yarn test

Usage

import makeNormalizer from '@hckrnews/normalizer';

const schemaFrom = {
    pim_sku: String,
    pim_productgroupname: String
}
const schemaTo = {
    sku: String,
    group: {
        name: String
    }
}
const Normalizer = makeNormalizer({ schemaFrom, schemaTo })

const normalizer = new Normalizer()

const rawData = [
    {
        pim_sku: '123',
        pim_productgroupname: 'Bike'
    }
]
normalizer.data = rawData

const mapping = (data) => ({
    sku: data.pim_sku,
    group: {
        name: data.pim_productgroupname
    }
})
normalizer.mapping = mapping

normalizer.normalizedData

[
    {
        sku: '123',
        group: {
            name: 'Bike'
        }
    }
]