Skip to content

Commit

Permalink
Prevent passing arrays (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
rocktimsaikia and sindresorhus authored Feb 28, 2022
1 parent 5047229 commit be6b28f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@ export default function mapObject(object, mapper, options) {
throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`);
}

if (Array.isArray(object)) {
throw new TypeError('Expected an object, got an array');
}

return _mapObject(object, mapper, options);
}
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ test('validates input', t => {
}, {
instanceOf: TypeError,
});

t.throws(() => {
mapObject([1, 2], (key, value) => [value, key]);
}, {
instanceOf: TypeError,
});
});

test('__proto__ keys are safely dropped', t => {
Expand Down

0 comments on commit be6b28f

Please sign in to comment.