Skip to content

Commit a50b1c8

Browse files
feat: update isLikeSelector for Reflect.ownKeys().length
1 parent c9a7a21 commit a50b1c8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/like-selector.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
export function isLikeSelector(selector) {
2-
const prototype = Reflect.getPrototypeOf(selector);
3-
return selector !== null
4-
&& typeof selector === 'object'
5-
&& (prototype === Object.prototype || prototype === Array.prototype)
6-
&& Reflect.ownKeys(selector).length > 0;
2+
const isArrayOrObject = selector !== null && typeof selector === 'object';
3+
4+
if (!isArrayOrObject) {
5+
return false;
6+
}
7+
8+
const isArray = Array.isArray(selector);
9+
const minimumKeysRequired = isArray ? 1 : 0;
10+
11+
return Reflect.ownKeys(selector).length > minimumKeysRequired;
712
}
813

914
export const CIRCULAR_SELECTOR = new Error('Encountered a circular selector');

0 commit comments

Comments
 (0)