is-object-empty2 1.0.4 → 1.0.6

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/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.4
3
+ * @version: v1.0.6
4
4
  * @link: https://github.com/tutyamxx/is-object-empty2
5
5
  * @license: MIT
6
6
  **/
@@ -23,6 +23,6 @@
23
23
  const isObjectEmpty2 = obj => (!!obj && typeof obj === 'object')
24
24
  && !Array.isArray(obj)
25
25
  && !(Object.keys(obj)?.length ?? 0)
26
- && !Object.getOwnPropertySymbols(obj)?.some(s => Object.getOwnPropertyDescriptor(obj, s)?.enumerable ?? false);
26
+ && !(Object.getOwnPropertySymbols(obj)?.some(s => Object.getOwnPropertyDescriptor(obj, s)?.enumerable) ?? false);
27
27
 
28
28
  module.exports = isObjectEmpty2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-object-empty2",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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",
@@ -92,4 +92,62 @@ describe('isObjectEmpty2', () => {
92
92
  obj[sym] = 123;
93
93
  expect(isObjectEmpty2(obj)).toBe(false);
94
94
  });
95
+
96
+ test('Object with multiple Symbol properties is considered non-empty', () => {
97
+ const obj = {};
98
+
99
+ const sym1 = Symbol('test1');
100
+ const sym2 = Symbol('test2');
101
+
102
+ obj[sym1] = 123;
103
+ obj[sym2] = 456;
104
+
105
+ expect(isObjectEmpty2(obj)).toBe(false);
106
+ });
107
+
108
+ test('Object with mixed enumerable and non-enumerable properties is considered non-empty', () => {
109
+ const obj = { a: 1 };
110
+ const sym = Symbol('test');
111
+
112
+ Object.defineProperty(obj, sym, { value: 123, enumerable: false });
113
+ expect(isObjectEmpty2(obj)).toBe(false);
114
+ });
115
+
116
+ test('Object with only non-enumerable properties is considered empty', () => {
117
+ const obj = {};
118
+
119
+ Object.defineProperty(obj, 'prop1', { value: 1, enumerable: false });
120
+ Object.defineProperty(obj, 'prop2', { value: 2, enumerable: false });
121
+
122
+ expect(isObjectEmpty2(obj)).toBe(true);
123
+ });
124
+
125
+ test('Objects with prototype properties are considered non-empty', () => {
126
+ function Parent() {
127
+ this.inherited = 'value';
128
+ }
129
+
130
+ Parent.prototype.inheritedProp = 'prototype-value';
131
+
132
+ const child = new Parent();
133
+ expect(isObjectEmpty2(child)).toBe(false);
134
+ });
135
+
136
+ test('Objects with getter/setter properties', () => {
137
+ const obj = {};
138
+
139
+ Object.defineProperty(obj, 'computed', {
140
+ get() { return 'value'; },
141
+ enumerable: true
142
+ });
143
+
144
+ expect(isObjectEmpty2(obj)).toBe(false);
145
+ });
146
+
147
+ test('Object.create(null) with enumerable properties', () => {
148
+ const obj = Object.create(null);
149
+
150
+ obj.a = 1;
151
+ expect(isObjectEmpty2(obj)).toBe(false);
152
+ });
95
153
  });