New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

is-blank-js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-blank-js

A lightweight utility that adds an .isBlank() method to native JavaScript types, inspired by Ruby on Rails' Object#blank?.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

is-blank-js

A JavaScript utility to check for blank values, inspired by Ruby on Rails' blank? method.

This library extends the prototypes of String, Array, Object, and Boolean to include an isBlank() method.

Installation

npm install is-blank-js

Usage

First, require the package to extend the prototypes:

require('is-blank-js');

Then, you can use the isBlank() method on your objects:

Strings

A string is blank if it's empty or contains only whitespace.

"".isBlank() // => true
"   ".isBlank() // => true
"hello".isBlank() // => false

Arrays

An array is blank if it's empty.

[].isBlank() // => true
[1, 2].isBlank() // => false

Objects

An object is blank if it's a plain object with no keys.

({}).isBlank() // => true
({ a: 1 }).isBlank() // => false

Booleans

A boolean is blank if it's false.

false.isBlank() // => true
true.isBlank() // => false

Numbers

A number is never blank.

(0).isBlank() // => false
(1).isBlank() // => false

Comparison to Rails' blank?

This library aims to replicate the behavior of Rails' blank? method for common JavaScript types.

Value in JavaScriptisBlank()
""true
" "true
[]true
{}true
falsetrue
truefalse
0false
null(error)
undefined(error)

Note: This library does not handle null or undefined because they don't have prototypes to extend. Calling isBlank() on null or undefined will result in a TypeError.

Development

To run the tests:

node test.js

Keywords

blank

FAQs

Package last updated on 05 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts