is-object-empty2 1.0.6 → 1.0.8

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
@@ -5,7 +5,8 @@
5
5
  <img src="https://img.shields.io/badge/License-MIT-yellow.svg">
6
6
  </p>
7
7
 
8
- # Simple yet robust NPM package that checks if a value is a plain empty object in `JavaScript` and `TypeScript`.
8
+ * Simple yet robust NPM package that checks if a value is a plain empty object in `JavaScript` and `TypeScript`.
9
+ * ♻️ Works seamlessly with `CommonJS`, `ESM` and `TypeScript`
9
10
 
10
11
  - Returns `true` **only** for plain objects with no own enumerable properties (`{}` or `Object.create(null)`).
11
12
  - Returns `false` for `Arrays`, `null`, `undefined`, `functions`, `symbols`, `BigInt`, objects with keys or object with at least one own enumerable property (string or symbol)
@@ -29,7 +30,7 @@ $ npm i is-object-empty2
29
30
  - Returns `true` only for empty objects (`{}`), and `false` for arrays, null, undefined, or objects with keys.
30
31
  - See examples below
31
32
 
32
- # JavaScript
33
+ ## CommonJS
33
34
  ```javascript
34
35
  const isObjectEmpty2 = require('is-object-empty2');
35
36
 
@@ -40,7 +41,18 @@ console.log(isObjectEmpty2(null)); // false
40
41
  console.log(isObjectEmpty2(undefined)); // false
41
42
  ```
42
43
 
43
- # TypeScript
44
+ ## ESM
45
+ ```javascript
46
+ import isObjectEmpty2 from 'is-object-empty2';
47
+
48
+ console.log(isObjectEmpty2({})); // true
49
+ console.log(isObjectEmpty2({ a: 1 })); // false
50
+ console.log(isObjectEmpty2([])); // false
51
+ console.log(isObjectEmpty2(null)); // false
52
+ console.log(isObjectEmpty2(undefined)); // false
53
+ ```
54
+
55
+ ## TypeScript
44
56
  ```javascript
45
57
  import isObjectEmpty2 = require('is-object-empty2');
46
58
 
package/index.d.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  * Checks if a given value is a plain object and has no own properties.
3
3
  * Returns `true` only for empty plain objects (`{}`), and `false` for arrays, null, undefined, or objects with keys.
4
4
  *
5
+ * Handles edge cases like objects with enumerable symbols, getters/setters, and prototype properties.
6
+ *
5
7
  * @param {unknown} obj - The value to check.
6
8
  * @returns {boolean} - `true` if the value is an empty object, otherwise `false`.
7
9
  *
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.6
3
+ * @version: v1.0.8
4
4
  * @link: https://github.com/tutyamxx/is-object-empty2
5
5
  * @license: MIT
6
6
  **/
@@ -10,6 +10,8 @@
10
10
  * Checks if a given value is a plain object with no own properties.
11
11
  * Returns `true` only for empty objects (`{}`), and `false` for arrays, null, undefined, or objects with keys.
12
12
  *
13
+ * Handles edge cases like objects with enumerable symbols, getters/setters, and prototype properties.
14
+ *
13
15
  * @param {unknown} obj - The value to check.
14
16
  * @returns {boolean} `true` if the value is an empty plain object, otherwise `false`.
15
17
  *
@@ -25,4 +27,8 @@ const isObjectEmpty2 = obj => (!!obj && typeof obj === 'object')
25
27
  && !(Object.keys(obj)?.length ?? 0)
26
28
  && !(Object.getOwnPropertySymbols(obj)?.some(s => Object.getOwnPropertyDescriptor(obj, s)?.enumerable) ?? false);
27
29
 
30
+ // --| CommonJS export
28
31
  module.exports = isObjectEmpty2;
32
+
33
+ // --| ESM default export for `import` statements
34
+ module.exports.default = isObjectEmpty2;
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "is-object-empty2",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
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
+ "module": "index.js",
6
7
  "types": "index.d.ts",
8
+ "exports": {
9
+ "require": "./index.js",
10
+ "import": "./index.js",
11
+ "types": "./index.d.ts"
12
+ },
7
13
  "scripts": {
8
14
  "test": "jest --verbose"
9
15
  },
@@ -138,6 +138,7 @@ describe('isObjectEmpty2', () => {
138
138
 
139
139
  Object.defineProperty(obj, 'computed', {
140
140
  get() { return 'value'; },
141
+ set() { /* setter */ },
141
142
  enumerable: true
142
143
  });
143
144