Last active
April 20, 2020 23:51
-
-
Save sankemax/c138465a41013084bab07986f626ddee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Transform } from '@intelligo.ai/object-to-schema/dist/utils/types'; | |
import response from './response.json'; | |
import { mapObject } from '@intelligo.ai/object-to-schema'; | |
const transformations: Transform[] = [ | |
{ | |
source: 'Title', | |
target: { | |
path: 'title' | |
} | |
}, | |
{ | |
source: 'Year', | |
target: { | |
path: 'year' | |
} | |
}, | |
{ | |
source: '', | |
target: { | |
path: 'isReleased', | |
conditionalValue: { | |
targetPathCondition: 'dates.released', | |
value: true | |
} | |
} | |
}, | |
{ | |
source: 'Actors', | |
target: { | |
path: 'actors', | |
predefinedTransformations: [ | |
{ | |
transformation: 'stringToArray', | |
transformationArgs: ', ' | |
} | |
] | |
} | |
}, | |
{ | |
source: 'DVD', | |
target: { | |
path: 'dates.dvd', | |
predefinedTransformations: [{ transformation: 'toDate' }] | |
} | |
}, | |
{ | |
source: 'ReleasedUSA', | |
target: { | |
path: 'dates.released[].usa', | |
predefinedTransformations: [{ transformation: 'toDate' }] | |
} | |
}, | |
{ | |
source: 'ReleasedIsrael', | |
target: { | |
path: 'dates.released[].israel', | |
predefinedTransformations: [{ transformation: 'toDate' }] | |
} | |
}, | |
{ | |
source: 'Ratings[].Source', | |
target: { | |
path: 'ratings[].siteName', | |
predefinedTransformations: [{ transformation: 'titleCase' }] | |
} | |
}, | |
{ | |
source: 'Ratings[].Value', | |
target: { | |
path: 'ratings[].rating' | |
} | |
} | |
] | |
const mapped = mapObject(response, transformations); | |
console.log(JSON.stringify(mapped, null, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment