Skip to content

Instantly share code, notes, and snippets.

@sankemax
Last active April 20, 2020 23:51
Show Gist options
  • Save sankemax/c138465a41013084bab07986f626ddee to your computer and use it in GitHub Desktop.
Save sankemax/c138465a41013084bab07986f626ddee to your computer and use it in GitHub Desktop.
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