1.0.2 • Published 3 years ago
data-to-data v1.0.2
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-dataWith Yarn:
yarn add data-to-dataWith PNPM:
pnpm install data-to-dataUsage 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' }