Skip to content

hckrnews/normalizer

Repository files navigation

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 rawData = [
    {
        pim_sku: '123',
        pim_productgroupname: 'Bike'
    }
]

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

const normalizer = new Normalizer({ data: rawData, mapping })

normalizer.normalizedData

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