empty-utils

1.0.1 • Public • Published

empty-utils

Two utils to check the given value is empty or not.

Downloads install size

Install

$ npm install empty-utils

Usage

import { isEmpty, isNotEmpty } from 'empty-utils'

// will return "true"
isEmpty(null)
isEmpty(undefined)
isEmpty('')
isEmpty([])
isEmpty({})
isEmpty(Object.create(null))
isEmpty({ [Symbol('foo')]: 'bar' })
isEmpty(new Map())
isEmpty(new Set())
isEmpty(new RegExp())

// will return "false"
isEmpty(0)
isEmpty(5)
isEmpty(0.0)
isEmpty(0.1)
isEmpty(BigInt(0))
isEmpty(3n)
isEmpty(true)
isEmpty(false)
isEmpty(' ')
isEmpty('😸')
isEmpty([1])
isEmpty([{}])
isEmpty(['hello'])
isEmpty(new WeakMap())
isEmpty(new WeakSet())
isEmpty(function () {})
isEmpty(Number.NaN)
isEmpty(Infinity)
isEmpty(Symbol('bar'))
isEmpty(new Date())
isEmpty(/kurdish/)

Strict mode?

Once the strict mode is enabled 0 (zero) as Number or BigInt and Strings filled with spaces will be evaluated as empty. However the objects only contains Symbol(s) will be evaluated as not empty.

// strict mode
isEmpty(0, true)    // true
isEmpty(0n, true)   // true
isEmpty(' ', true)  // true

isEmpty({ [Symbol('foo')]: 'bar' }, true)  // false

Available utils

Name Description
isEmpty A function who checks if the given value is empty.
isNotEmpty A function who checks if the given value is not empty.

Options

Name Type Default Description
value any - The thing to be checked.
strict boolean false Strict mode

Readme

Keywords

Package Sidebar

Install

npm i empty-utils

Weekly Downloads

40

Version

1.0.1

License

MIT

Unpacked Size

26.5 kB

Total Files

9

Last publish

Collaborators

  • hsynlms