Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

defined

inspect-js11.4mMIT1.0.1TypeScript support: definitely-typed

return the first argument that is !== undefined

undefined, short-circuit, ||, or, //, defined-or

readme

defined Version Badge

github actions coverage License Downloads

npm badge

return the first argument that is !== undefined

Most of the time when I chain together ||s, I actually just want the first item that is not undefined, not the first non-falsy item.

This module is like the defined-or (//) operator in perl 5.10+.

example

var defined = require('defined');
var opts = { y : false, w : 4 };
var x = defined(opts.x, opts.y, opts.w, 100);
console.log(x);
$ node example/defined.js
false

The return value is false because false is the first item that is !== undefined.

methods

var defined = require('defined')

var x = defined(a, b, c...)

Return the first item in the argument list a, b, c... that is !== undefined.

If all the items are === undefined, return undefined.

install

With npm do:

npm install defined

license

MIT

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.0.1 - 2022-10-12

Commits

  • [eslint] fix indentation 84801c0
  • [readme] rename, add badges 7ccb011
  • [actions] add reusable workflows 03917f0
  • [Dev Deps] update tape ac57011
  • [eslint] add eslint 9bf7583
  • [meta] add auto-changelog ec13b5f
  • [meta] use npmignore to autogenerate an npmignore file 549e1ff
  • Only apps should have lockfiles 11dfedc
  • [meta] add safe-publish-latest efadc76
  • [meta] update URLs aa9c486
  • [Tests] add aud in posttest a0cf2fb
  • [meta] create FUNDING.yml; add funding in package.json b05fc5e

v1.0.0 - 2015-03-30

Commits

v0.0.0 - 2012-11-25

Commits