Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-it-set

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-it-set

A one-liner to check if a property is set (not null, undefined or empty string).

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
Maintainers
1
Weekly downloads
 
Created
Source

Is It Set

Build Status

A one-liner to check if a property is set (not null, undefined or an empty string).

Installation

Run the following command to make this package available in your project:

npm install is-it-set --save

Usage

Import this package into your script like this:

const isSet = require('is-it-set');

Now you can run isSet on any input:

/*
 * Empty strings, `null` and `undefined` all return `false`
 */
isSet('')        // => false
isSet(null)      // => false
isSet(undefined) // => false

/*
 * Any other input returns `true`
 */
isSet(0)         // => true
isSet(-1)        // => true
isSet(' ')       // => true
isSet(false)     // => true
isSet('Hello')   // => true
isSet(Infinity)  // => true
isSet(Date)      // => true

Why does this package exist?

JavaScript has some opinions on what should be considered falsy, and that's great for developer convenience when dealing with variable data.

However, sometimes the only values that should not pass a test (like an if()) should be data types that purposefully mean "no data" -- null, undefined and the empty string (''). Empty strings are often used as a no-data indicator in JSON documents.

A Simple Example

function squareNumber(input) {
  /**
   * A simple check to make sure there's data to work with
   */
  if (isSet(input)) {
    return input * input;	  
  } else {
    throw new ReferenceError('No input given');
  }
}

Versioning

This repo follows SemVer

Tests

To run the tests for this package, clone the repo and run the following in your terminal:

npm install
npm test

Keywords

FAQs

Package last updated on 12 Jun 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc