1.0.2 • Published 1 year ago

data-to-data v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

data-to-data

data-to-data is a javascript data conversion tool.

When we work, it is inevitable that the data structure returned by the backend is inconsistent with what we need. Using it can be used to facilitate conversion.

Installation

With NPM:

npm install data-to-data

With Yarn:

yarn add data-to-data

With PNPM:

pnpm install data-to-data

Usage example

Basic usage example

const data = {
  a: {
    b: {
      c: 'c'
    }
  }
}

const mapping = {
  data: 'a.b.c'
}

dataToData(data, mapping) // { data: 'c' }

Array operation

const data = {
  a: {
    id: [1,2,3]
  }
}

const mapping = {
  data: ['a.id', id => `ID-${id}`]
}

dataToData(data, mapping) // { data: [ 'ID-1', 'ID-2', 'ID-3' ] }

Inject value

import { injectValue } from 'data-to-data'

const data = {
  a: 'a'
}

const mapping = {
  data: injectValue('hello')
}

dataToData(data, mapping) // { data: 'hello' }
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago