Skip to content

cheminfo/array-of-objects-utilities

Repository files navigation

array-of-objects-utilities

NPM version npm download test coverage license

Utilities to reduce depths of objects and convert to text.

Installation

npm install array-of-objects-utilities

Usage

import { flattenToJPaths, objectArrayToText } from 'array-of-objects-utilities';

const data = [
  {
    e: 5,
  },
  {
    a: {
      b: 'aB',
      c: 'cd',
    },
  },
  {
    a: {
      b: 'c',
      d: 4,
    },
  },
  2,
];

const flattened = flattenToJPaths(data, {
  modifiers: {
    'a.b': (value) => (typeof value === 'string' ? value.toUpperCase() : value),
  },
});

const text = objectArrayToText(flattened, {
  delimiter: ';',
  headerMapping: { '': 'root', 'a.b': 'AB field' },
});

console.log(text);
/*
e;AB field;a.c;a.d;root
5;;;;
;aB;cd;;
;c;;4;
;;;;2
*/

License

MIT

About

Utilities to reduce depth of array of objects and convert to text

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •