From 681d3f4b9f1eaddbe13a3f55601966b1b9b8d77e Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 31 Jul 2022 23:11:22 -0400 Subject: [PATCH] *Ensure object is an array to handle both arrays and objects --- src/util.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index 4a10b97..a524ded 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,3 +1,5 @@ +import { isArray } from "util"; + function isBuffer(obj: any): boolean { return ( obj && @@ -20,7 +22,10 @@ export function flatten(target: any, opts: any = {}): any[] { function step(object: any, prev?: any, currentDepth?: any) { currentDepth = currentDepth || 1; - Object.keys(object).forEach(function (key) { + if (!Array.isArray(object)) { + object = Object.keys(object); + } + object.forEach(function (key: any) { const value = object[key]; const isarray = opts.safe && Array.isArray(value); const type = Object.prototype.toString.call(value);