Function appendJson

Appends all provided JSON values together. undefined values will be ignored. The first value determines whether the output will be an object or an array. Any value appended to an array will work just fine, but primitives append to an object will likely behave unexpectedly. Arrays appended to arrays will be flattened (but only by one level).

import {appendJson} from '@augment-vir/common';

// `result1` will be `{a: 'q', b: 'b'}`
const result1 = appendJson({a: 'a'}, {b: 'b'}, {a: 'q'});
// `result2` will be `[{a: 'a'}, {b: 'b'}, {a: 'q'}, 'r']`
const result2 = appendJson([{a: 'a'}], {b: 'b'}, {a: 'q'}, 'r');
// `result3` will be `['a', ['b', 'c'], 'd', 'e']`
const result3 = appendJson(
['a'],
[
[
'b',
'c',
],
],
['d'],
'e',
);