mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: handle array edge case
This commit is contained in:
parent
0b9f6e49e1
commit
f5dec41b34
@ -111,4 +111,8 @@ describe('flatten', () => {
|
||||
|
||||
expect(result).toStrictEqual({});
|
||||
});
|
||||
|
||||
it('should throw an error if data is an array', () => {
|
||||
expect(() => flatten([])).toThrow('Data should be an object!');
|
||||
});
|
||||
});
|
||||
|
@ -18,6 +18,10 @@ export const flatten = (
|
||||
prefix: string | undefined = undefined,
|
||||
result: object = {},
|
||||
): object => {
|
||||
if (Array.isArray(data)) {
|
||||
throw new Error('Data should be an object!');
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
const path = prefix ? `${prefix}.${key}` : key;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user