/dynamodb-object-normalizer

normalize objects for dynamodb

Primary LanguageJavaScriptMIT LicenseMIT

Dynamodb object normalizer

Build Status License: MIT

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

Usage

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' ] } }
*/

Installation

npm i @ninjakttty/dynamodb-object-normalizer

License

MIT © Yuri Parsons