Normalize JS objects for dynamodb insertion ✨
Dynamodb doesn't like empty string, this will recursively drill through all the props with empty strings and remove them by default or replace them with a user defined string
const { normalize } = require('@ninjakttty/dynamodb-object-normalizer');
const item = {
firstName: 'Yuri',
lastName: '',
age: 23,
job: {
title: 'developer',
eprop: '',
rank: 10,
coworkers: ['Frank', 'Gary', 'Mark'],
},
};
console.log(normalize(item));
/*
{ firstName: 'Yuri',
age: 23,
job:
{ title: 'developer',
rank: 10,
coworkers: [ 'Frank', 'Gary', 'Mark' ] } }
*/
console.log(normalize(item, { replaceWith: null }));
/*
{ firstName: 'Yuri',
lastName: null,
age: 23,
job:
{ title: 'developer',
eprop: null,
rank: 10,
coworkers: [ 'Frank', 'Gary', 'Mark' ] } }
*/
npm i @ninjakttty/dynamodb-object-normalizer
MIT © Yuri Parsons