is-object-empty2 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  # Simple yet robust NPM package that checks if a value is a plain empty object in `JavaScript` and `TypeScript`.
9
9
 
10
10
  - Returns `true` **only** for plain objects with no own enumerable properties (`{}` or `Object.create(null)`).
11
- - Returns `false` for arrays, `null`, `undefined`, functions, symbols, BigInt, or objects with keys.
11
+ - Returns `false` for `Arrays`, `null`, `undefined`, `functions`, `symbols`, `BigInt`, objects with keys or object with at least one own enumerable property (string or symbol)
12
12
  - Correctly handles:
13
13
  - Objects created with `Object.create(null)`
14
14
  - Frozen or sealed objects
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * is-object-empty2 - 📦 Tiny utility to check if a value is a plain empty object in JavaScript and TypeScript
3
- * @version: v1.0.3
3
+ * @version: v1.0.4
4
4
  * @link: https://github.com/tutyamxx/is-object-empty2
5
5
  * @license: MIT
6
6
  **/
@@ -20,6 +20,9 @@
20
20
  * isObjectEmpty2(null); // false
21
21
  * isObjectEmpty2(undefined); // false
22
22
  */
23
- const isObjectEmpty2 = (obj) => (obj !== null && typeof obj === 'object' && !Array.isArray(obj)) ? Object.keys(obj).length === 0 : false;
23
+ const isObjectEmpty2 = obj => (!!obj && typeof obj === 'object')
24
+ && !Array.isArray(obj)
25
+ && !(Object.keys(obj)?.length ?? 0)
26
+ && !Object.getOwnPropertySymbols(obj)?.some(s => Object.getOwnPropertyDescriptor(obj, s)?.enumerable ?? false);
24
27
 
25
28
  module.exports = isObjectEmpty2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-object-empty2",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "📦 Tiny utility to check if a value is a plain empty object in JavaScript or TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -84,4 +84,12 @@ describe('isObjectEmpty2', () => {
84
84
  Object.defineProperty(obj, 'hidden', { value: 123, enumerable: false });
85
85
  expect(isObjectEmpty2(obj)).toBe(true);
86
86
  });
87
+
88
+ test('Object with Symbol property is considered non-empty', () => {
89
+ const obj = {};
90
+ const sym = Symbol('test');
91
+
92
+ obj[sym] = 123;
93
+ expect(isObjectEmpty2(obj)).toBe(false);
94
+ });
87
95
  });