is-empty-object-x

Check a parameter is empty Object. Array, Date, Class, Function, Regex, Symoble are return false.

Usage no npm install needed!

<script type="module">
  import isEmptyObjectX from 'https://cdn.skypack.dev/is-empty-object-x';
</script>

README

isEmptyObject

NPM version Build Status Coverage Status ISC License

isEmptyObject(val?: any, checkOwnProperty?: boolean) => boolean

Check a parameter is empty Object.
Array, Date, Class, Function, Regex, Symoble are return false.
When use checkOwnProperty option true, it check a object has only own property or not.

Install

$ npm install is-empty-object-x

usage

import isEmptyObject from 'is-empty-object-x';

isEmptyObject({}); // => true;

Build

$ npm run build

Test

$ npm run test
isEmptyObject();
// => false
isEmptyObject(undefined);
// => false
isEmptyObject(null);
// => false

Boolean

isEmptyObject(true);
// => false
isEmptyObject(false);
// => false

String

isEmptyObject('String');
// => false
isEmptyObject(new String(''));
// => false;
isEmptyObject('');
// => false

Number

isEmptyObject(1);
// => false
isEmptyObject(0);
// => false
isEmptyObject(-1);
// => false
isEmptyObject(NaN);
// => false
isEmptyObject(Infinity);
// => false
isEmptyObject(-Infinity);
// => false

Array

isEmptyObject([]);
// => false

Object

isEmptyObject({});
// => true
isEmptyObject(new Object());
// => true
isEmptyObject({ foo: 1 });
// => false
isEmptyObject(new Object({ bar: 0 }));
// => false

Date

const date = new Date();
isEmptyObject(date);
// => false

Function

const func = function () { };
isEmptyObject(func);
// => false

Symbol

const symbol1 = Symbol();
isEmptyObject(symbol1);
// => false
const symbol2 = Symbol('a');
isEmptyObject(symbol2);
// => false

RegExp

const regex1 = /\w+/;
isEmptyObject(regex1);
// => false
const regex2 = new RegExp('\\w+');
isEmptyObject(regex2);
// => false

Class

class MyClass {
  constructor() { }
}
const classObj = new MyClass();
isEmptyObject(classObj);
// => false

checkOwnProperty option

const o = new Object();
o.a = 'b';
const obj = Object.create(o);
obj.a; //=> 'b'
obj.hasOwnProperty('a'); // => false

isEmptyObject(obj);
// => true

// use checkOwnProperty Option!
isEmptyObject(obj, true);
// => false