Skip to content

briver0825/data-to-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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' }

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published