npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ifnotundef

v1.1.3

Published

a set of helper functions that simplify the (is a undefined ? b : c) syntax

Downloads

30

Readme

ifnotundef

GitHub version npm version NPM monthly downloads Build Status Coverage Status

A set of helper functions that simplify the (is a undefined ? b : c) syntax

Author: Loïc Formont
License: MIT Licensed
Example

var undef = require("ifnotundef");

undef.if(a, b, [c]) ⇒ *

Two parameters mode If a is undefined, return b else a Three parameters mode If a is undefined, return c else b

Kind: static method of ifnotundef
Returns: * - a, b or c depending on their undefined status

| Param | Type | Description | | --- | --- | --- | | a | * | the first parameter | | b | * | the second parameter | | [c] | * | the third parameter |

Example
Two ways to use if. Either with two parameters (a||b):

var myHost = undef.if(options.host, options.hostname);

or with three parameters (a?b:c):

var myHost = undef.if(options.host, options.hostname, 'localhost');

undef.is(a, b) ⇒ boolean

Invert of "check"

Kind: static method of ifnotundef
Returns: boolean - a or a[b]'s undefined status

| Param | Type | Description | | --- | --- | --- | | a | * | the variable to check | | b | * | the child path |

Example

if(undef.is(options.host)) console.log('Deal with it');

undef.isnot(a, b) ⇒ boolean

Alias of "check"

Kind: static method of ifnotundef
Returns: boolean - a or a[b]'s undefined status

| Param | Type | Description | | --- | --- | --- | | a | * | the variable to check | | b | * | the child path |

Example

if(undef.isnot(options.host)) console.log('Great');

undef.check(a, b) ⇒ boolean

One parameters mode If a is undefined, false else true Two parameters mode If a[b] is undefined, false else true

Kind: static method of ifnotundef
Returns: boolean - a or a[b]'s undefined status

| Param | Type | Description | | --- | --- | --- | | a | * | the variable to check | | b | * | the child path |

Example

if(!undef.check(options.host)) console.log('Deal with it');

undef.try(a, [b]) ⇒ *

One parameters mode If a is undefined, throw a else return a Two parameters mode If a is undefined, throw b else return a

Kind: static method of ifnotundef
Returns: * - a or exception depending on a's undefined status

| Param | Type | Description | | --- | --- | --- | | a | * | the parameter to try | | [b] | * | the error message |

Example
Two ways to use if. Either with one parameter:

var myHost = undef.try(options.host);

or with two parameters:

var myUndefined = undef.try(undefined, 'undefined is not defined ... ;-)');
// Exeption raised above

undef.child(a, b, c, [d]) ⇒ *

Three parameters mode If a[b] is undefined, return c else a[b] Four parameters mode If a[b] is undefined, return d else c

Kind: static method of ifnotundef
Returns: * - a[b] or c or d depending on their undefined status

| Param | Type | Description | | --- | --- | --- | | a | * | the object | | b | * | the child path | | c | * | the first value | | [d] | * | the second value |

Example
Two ways to use child. Either with three parameters (a[b]||c):

var myHost = undef.child(options, ['params', 'host'], 'localhost');

or with four parameters (a[b]?c:d):

var myHost = undef.child(options, ['params'], options.params.host, 'localhost');