diff --git a/README.md b/README.md index dcff29d..375d44d 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,8 @@ Loading and parsing data from a common file formats like: CSV, JSON, TSV either - [**pivot**](https://www.datapipe-js.com/docs/datapipe-js-array#pivot) (array, rowFields, columnField, dataField, aggFunction?, columnValues?) - Returns a reshaped (pivoted) array based on unique column values. - [**transpose**](https://www.datapipe-js.com/docs/datapipe-js-array#transpose) (array) - Transpose rows to columns in an array - [**sort**](https://www.datapipe-js.com/docs/datapipe-js-array#sort) ([fieldName(s)]) - Sort array of elements according to a field and direction specified. e.g. sort(array, 'name ASC', 'age DESC') + - [**flattenObject**](https://www.datapipe-js.com/docs/datapipe-js-array#flattenObject) (Object) - flattens complex nested object into simple object. e.g. flattenObject(obj) + - [**unflattenObject**](https://www.datapipe-js.com/docs/datapipe-js-array#unflattenObject) (Object) - unflattens simple object into complex nested object. e.g. unflattenObject(obj) ### Joining data arrays diff --git a/src/array/transform.ts b/src/array/transform.ts index 3bd946c..039e9f0 100644 --- a/src/array/transform.ts +++ b/src/array/transform.ts @@ -60,11 +60,6 @@ export function unflattenObject(data: any): any { function setProperty(data: any, pName: string, value: any): any { const pNames = pName.split('.') let parent: any = data - /** - data['p1'] = {} - parent = data.p1 - parent['p2'] = 123 - */ for (let i = 0; i < pNames.length - 1; i++) { if (pNames[i] in parent) { diff --git a/src/data-pipe.ts b/src/data-pipe.ts index b07a414..462a41c 100644 --- a/src/data-pipe.ts +++ b/src/data-pipe.ts @@ -309,7 +309,7 @@ export class DataPipe { return unflattenObject(this.data); } - flattern(): any { + flatten(): any { return flatten(this.data); } diff --git a/src/tests/array.spec.ts b/src/tests/array.spec.ts index 342951a..5f4dc5b 100644 --- a/src/tests/array.spec.ts +++ b/src/tests/array.spec.ts @@ -114,7 +114,7 @@ describe('Test array methods', () => { expect(groups.length).toBe(3); }); - it('flattern', () => { + it('flatten', () => { const testArray = [1, 4, [2, [5, 5, [9, 7]], 11], 0, [], []]; const flatten = pipeFuncs.flatten(testArray); expect(flatten.length).toBe(9);