UNPKG

bc-node-sdk

Version:

BetterCommerce's NodeJS SDK encapsulates the base framework for all the Next.js applications.

22 lines (21 loc) 1.17 kB
/** * Class {@link TransformUtil} encapsulate utility for transforming data from one format to another. */ export default abstract class TransformUtil { /** * Groups an array of objects by the specified key. * * @template T The type of the objects in the array. * @param array The array of objects to be grouped. * @param key The key of the object by which to group the array. * @returns A record where each key is a distinct value from the specified key in the objects, and the value is an array of objects that share that key. */ static groupBy<T>(array: T[], key: keyof T): Record<string, T[]>; /** * Transforms an array of data into a two-dimensional array of rows and columns. The length of the sub-arrays will be the specified number of columns. * @param data The array of data to be transformed. * @param columns The number of columns to be created in the two-dimensional array. * @returns A two-dimensional array of rows and columns, where each sub-array is of the specified length. */ static transformArrayToColumns(data: Array<any>, columns: number): any[]; }