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

isset-helper

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isset-helper

A tiny helper method, checking a variable for existence

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Isset Helper

A tiny helper method for Javascript, checking a variable for existence.

Since checking variable types and existence always has been painful in Javascript, validation conditions normally are exhausting. This module solves this definitely.


Installation

as a module

Install the library through your preferred package manager:

$ npm install --save isset-helper
# or
$ yarn add isset-helper

Then you can require the module as usual:

const isset = require('isset-helper');

in the browser

Include one of the following script tags in your pages head:

<script src="https://cdn.jsdelivr.net/npm/isset-helper@2/dist/isset.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/mcstreetguy/isset-helper@2/dist/isset.min.js"></script>
<script src="https://bundle.run/isset-helper@2.0/dist/isset.min.js"></script>
<script src="https://unpkg.com/isset-helper@2/dist/isset.min.js"></script>

The library registers the isset function automatically on the window object.

Usage

isset(variable, type);

variable can be anything. It's value is going to be checked.
type can be a string, class or even left out.

The algorithm follows the subsequent rules:

  1. variable is not null
  2. variable is not undefined
  3. If type is a string, typeof variable has to match type
  4. Otherwise, variable has to match instanceof type
  5. If type is "string", variable is not an empty string

Please notice:

  • The algorithm always runs the instanceof-check, leaving it out of consideration if the check produces any error.
  • The algorithm doesn't check for the exact value (apart from the empty string case mentioned above), thus false will also be considered valid.

Contributing

If, contrary to expectations, you find an error in the function, please report it to the Issues page.

License

This library is licensed under the MIT License. You may find a copy of the license at the root of the project source.

FAQs

Package last updated on 09 Oct 2018

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