0.2.1 • Published 4 years ago

deducer v0.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Deducer

This project is aimed at providing a simple but effective solution for deducing/transforming/reshaping data.

A deduction is described as the following signature { source: Path, desstination?: Path, reducers?: Function[]], The deduce function will take an input object and an array of deductions, each deduction will be responsible for cosuming parts of the input in order to produce a new value in the output.

Under Development

This library is currently under development as is not consisdered stable, if you are interested in supporting this project there are several key areas that require work before a stable version is available

  • Finalisation of the API
  • Improved typescript support
  • Documentation
  • Richer and more diverse tests suite.

Install

npm install --save deducer

Simple Example:

import { deduce, Deduction } from "deducer"

const input = { columnA: 'valueB' };
const deductions: Deduction[] = [
    { source: 'columnA', destination: 'columnB' }
]
const result = deduce(input, deductions)
// { columbB: 'valueB' }

Array Example:

import { deduce, Deduction } from "deducer"

const input = ['some', 'values'];
const deductions: Deduction[] = [
    { source: 0, destination: 'zero' }
    { source: 1, destination: 'one' }
]
const result = deduce(input, deductions)
// { zero: 'some', one: 'values' }

Deductions Example:

import { deduce, Deduction } from "deducer"

const input = { title: "Mr", firstName: "John", lastName: "Doe" };
const deductions: Deduction[] = [
    {
        source: 'title',
        destination: 'user.title'
    },
    {
        source: 'firstName',
        destination: 'user.firstName'
    },
    {
        source: 'lastName',
        destination: 'user.lastName'
    },
    {
        source: ["title", "firstName", "lastName"],
        destination: 'user.fullName',
        reducers: [
            ([title, firstName, lastName]) => `${title} ${firstName} ${lastName}`
        ]
    },
]
const result = deduce(input, deductions)
// { user: { title: "Mr", firstName: "John", lastName: "Doe", fullName: "Mr John Doe"  } }

NPM scripts

  • npm t: Run test suite
  • npm start: Run npm run build in watch mode
  • npm run test:watch: Run test suite in interactive watch mode
  • npm run test:prod: Run linting and generate coverage
  • npm run build: Generate bundles and typings, create docs
  • npm run lint: Lints code
  • npm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)
0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago