*Ensure object is an array to handle both arrays and objects

This commit is contained in:
Derrick Hammer 2022-07-31 23:11:22 -04:00
parent 1174999864
commit 681d3f4b9f
1 changed files with 6 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import { isArray } from "util";
function isBuffer(obj: any): boolean { function isBuffer(obj: any): boolean {
return ( return (
obj && obj &&
@ -20,7 +22,10 @@ export function flatten(target: any, opts: any = {}): any[] {
function step(object: any, prev?: any, currentDepth?: any) { function step(object: any, prev?: any, currentDepth?: any) {
currentDepth = currentDepth || 1; 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 value = object[key];
const isarray = opts.safe && Array.isArray(value); const isarray = opts.safe && Array.isArray(value);
const type = Object.prototype.toString.call(value); const type = Object.prototype.toString.call(value);