isEmptyObject
Category
Export size
min 0.31 kB · gzip 0.22 kB
See also
Returns true only for a plain object without keys ({}). Arrays, null, undefined, primitives, class instances (a Date has no own keys either) and non-empty objects are all false - an object with only symbol keys (sequelize's operators) included.
ts
import { isEmptyObject } from 'feathers-utils/helpers';Example
ts
import { isEmptyObject } from 'feathers-utils/helpers'
isEmptyObject({}) // => true
isEmptyObject({ a: 1 }) // => false
isEmptyObject({ [Op.or]: [] }) // => false
isEmptyObject([]) // => false
isEmptyObject(undefined) // => falseType declaration
Show Type Declarations
ts
/**
* Returns `true` only for a plain object without keys (`{}`). Arrays, `null`,
* `undefined`, primitives, class instances (a `Date` has no own keys either)
* and non-empty objects are all `false` - an object with only symbol keys
* (sequelize's operators) included.
*
* @example
* ```ts
*
*
* isEmptyObject({}) // => true
* isEmptyObject({ a: 1 }) // => false
* isEmptyObject({ [Op.or]: [] }) // => false
* isEmptyObject([]) // => false
* isEmptyObject(undefined) // => false
* ```
*
* @see https://utils.feathersjs.com/helpers/is-empty-object.html
*/
export declare const isEmptyObject: (obj: unknown) => boolean| Argument | Type | Description |
|---|---|---|
| obj | unknown |
Coming from lodash
_.isEmpty answers a broader question — it is true for null, undefined, [], '', 0 and any object without own string keys. isEmptyObject is only true for {}, so check for a missing value first:
ts
// before
if (_.isEmpty(query)) { ... }
// after
if (!query || isEmptyObject(query)) { ... }An object that only carries symbol keys — a sequelize query like { [Op.or]: [...] } — is empty to _.isEmpty, but not to isEmptyObject.
