A two-dimensional array where each inner array contains values to be mapped.
An array of strings representing the keys to assign values from each inner array.
An array of objects, each with a unique id and properties as defined by keys.
export const PERSONS = generator<{firstName: string, lastName: string, age: number}>(
[
['john', 'Doe', 30],
['Jane', 'Smith', 25],
],
['firstName', 'lastName', 'age'],
);
// Example output:
// console.log(PERSONS)
// [
// { id: 'a1B', firstName: 'John', lastName: 'Doe', age: 30 },
// { id: 'c3D', firstName: 'Jane', lastName: 'Smith', age: 25 }
// ]
const result = generator(data, keys);
Maps a two-dimensional array of values to an array of objects.
For each inner array in
itemArr, this function creates an object with:id(a 3-character alphanumeric string generated bygenerate).keysarray and whose values are taken from the inner array at corresponding indices.Important: The length of each inner array in
itemArrshould match the length of thekeysarray.