pax_global_header00006660000000000000000000000064143215442210014510gustar00rootroot0000000000000052 comment=8613a02bb55958a035d1988113d4814e2928b293 defined-1.0.1/000077500000000000000000000000001432154422100131055ustar00rootroot00000000000000defined-1.0.1/.eslintrc000066400000000000000000000004321432154422100147300ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "consistent-return": 1, "sort-keys": 0, }, "overrides": [ { "files": "example/**", "rules": { "no-console": 0, }, }, ], } defined-1.0.1/.github/000077500000000000000000000000001432154422100144455ustar00rootroot00000000000000defined-1.0.1/.github/FUNDING.yml000066400000000000000000000011021432154422100162540ustar00rootroot00000000000000# These are supported funding model platforms github: [ljharb] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: npm/defined community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] defined-1.0.1/.github/workflows/000077500000000000000000000000001432154422100165025ustar00rootroot00000000000000defined-1.0.1/.github/workflows/node-aught.yml000066400000000000000000000005161432154422100212620ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '< 10' type: minors command: npm run tests-only node: name: 'node < 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' defined-1.0.1/.github/workflows/node-pretest.yml000066400000000000000000000002061432154422100216340ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main defined-1.0.1/.github/workflows/node-tens.yml000066400000000000000000000005211432154422100211170ustar00rootroot00000000000000name: 'Tests: node.js >= 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 10' type: minors command: npm run tests-only node: name: 'node >= 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' defined-1.0.1/.github/workflows/rebase.yml000066400000000000000000000004111432154422100204620ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] jobs: _: name: "Automatic Rebase" runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: ljharb/rebase@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} defined-1.0.1/.github/workflows/require-allow-edits.yml000066400000000000000000000003031432154422100231170ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main defined-1.0.1/.gitignore000066400000000000000000000001721432154422100150750ustar00rootroot00000000000000# gitignore node_modules/ # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock .npmignore defined-1.0.1/.npmrc000066400000000000000000000000671432154422100142300ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s defined-1.0.1/CHANGELOG.md000066400000000000000000000067031432154422100147240ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [v1.0.1](https://github.com/ljharb/defined/compare/v1.0.0...v1.0.1) - 2022-10-12 ### Commits - [eslint] fix indentation [`84801c0`](https://github.com/ljharb/defined/commit/84801c054280c86c433022be64feddf38ac426aa) - [readme] rename, add badges [`7ccb011`](https://github.com/ljharb/defined/commit/7ccb011e69adda93a923408819730848ed9328cc) - [actions] add reusable workflows [`03917f0`](https://github.com/ljharb/defined/commit/03917f0a2a1123f71bd6a1e2d48802051614bda4) - [Dev Deps] update `tape` [`ac57011`](https://github.com/ljharb/defined/commit/ac57011cb753bf1f3937569b16f76a22ea6e9230) - [eslint] add eslint [`9bf7583`](https://github.com/ljharb/defined/commit/9bf7583959cb02ed2feac6d3781965921d2220f8) - [meta] add `auto-changelog` [`ec13b5f`](https://github.com/ljharb/defined/commit/ec13b5f04eb2273e6708bb8ac00e29b109880b07) - [meta] use `npmignore` to autogenerate an npmignore file [`549e1ff`](https://github.com/ljharb/defined/commit/549e1ff99822f86ec6394dcb4540a4ee596e7433) - Only apps should have lockfiles [`11dfedc`](https://github.com/ljharb/defined/commit/11dfedcd1cf1471fac56763064471f0093aa841f) - [meta] add `safe-publish-latest` [`efadc76`](https://github.com/ljharb/defined/commit/efadc76397fcfb4435934dab7c8a744bc831c38f) - [meta] update URLs [`aa9c486`](https://github.com/ljharb/defined/commit/aa9c48684a74611afaa50ae4429832cd39616812) - [Tests] add `aud` in `posttest` [`a0cf2fb`](https://github.com/ljharb/defined/commit/a0cf2fb66a61870e0657c4f41ba0893abfef77a1) - [meta] create FUNDING.yml; add `funding` in package.json [`b05fc5e`](https://github.com/ljharb/defined/commit/b05fc5e478baeb12822978e38232c8b8daf60c29) ## [v1.0.0](https://github.com/ljharb/defined/compare/v0.0.0...v1.0.0) - 2015-03-30 ### Commits - using testling-ci [`9f11918`](https://github.com/ljharb/defined/commit/9f11918b7dffb639fc960da7c8a5914d7df67e80) - Bump to 1.0.0 + newer tape [`3a46c81`](https://github.com/ljharb/defined/commit/3a46c81d39b5f94c0c17c47638939af2528520f3) - another test [`5c825a7`](https://github.com/ljharb/defined/commit/5c825a710662cab0b8abb37132cae19d0dcf00cb) - using travis [`4dabaf5`](https://github.com/ljharb/defined/commit/4dabaf53092665b36961a0b82a00d818051d69db) - use tape 0.2.2 [`1337250`](https://github.com/ljharb/defined/commit/1337250d7f0f7f63ebc864ad509ce1247978b451) - bump [`07dbbbf`](https://github.com/ljharb/defined/commit/07dbbbfa155c91e9ab09da07af797738340c7338) - bump [`1a6fde3`](https://github.com/ljharb/defined/commit/1a6fde32136c51b4b8d8664d2b6072d241e5b4ae) ## v0.0.0 - 2012-11-25 ### Commits - docs, example, and code ripped from the tape module [`6bec2cc`](https://github.com/ljharb/defined/commit/6bec2cc9c82f19c2960f344b5141154d6eaa7380) - package.json whatevs [`ac951cd`](https://github.com/ljharb/defined/commit/ac951cd1dd31b7944fe3b539f091766bfb178e00) - passing test [`d6e0c87`](https://github.com/ljharb/defined/commit/d6e0c87982c76f4889541d8ed57a463c259fec2c) - oh right tape [`e3f9596`](https://github.com/ljharb/defined/commit/e3f9596dcc4c5e2a2657fda5f5cad2b9957d705f) - note about perl 5.10 [`6eba8e6`](https://github.com/ljharb/defined/commit/6eba8e6a2927a5d8b748d422ad7e64b977ab4f94) - -bin [`fbf0d20`](https://github.com/ljharb/defined/commit/fbf0d20d9cec86266ed06e8fe4f5b9927917a3c5) defined-1.0.1/LICENSE000066400000000000000000000020611432154422100141110ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. defined-1.0.1/README.md000066400000000000000000000041301432154422100143620ustar00rootroot00000000000000# defined [![Version Badge][npm-version-svg]][package-url] [![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![npm badge][npm-badge-png]][package-url] 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 ``` js 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 ``` js 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](https://npmjs.org) do: ``` npm install defined ``` # license MIT [package-url]: https://npmjs.org/package/defined [npm-version-svg]: https://versionbadg.es/inspect-js/defined.svg [deps-svg]: https://david-dm.org/inspect-js/defined.svg [deps-url]: https://david-dm.org/inspect-js/defined [dev-deps-svg]: https://david-dm.org/inspect-js/defined/dev-status.svg [dev-deps-url]: https://david-dm.org/inspect-js/defined#info=devDependencies [npm-badge-png]: https://nodei.co/npm/defined.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/defined.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/defined.svg [downloads-url]: https://npm-stat.com/charts.html?package=defined [codecov-image]: https://codecov.io/gh/inspect-js/defined/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/inspect-js/defined/ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/defined [actions-url]: https://github.com/inspect-js/defined/actions defined-1.0.1/example/000077500000000000000000000000001432154422100145405ustar00rootroot00000000000000defined-1.0.1/example/defined.js000066400000000000000000000002101432154422100164650ustar00rootroot00000000000000'use strict'; var defined = require('../'); var opts = { y: false, w: 4 }; var x = defined(opts.x, opts.y, opts.w, 8); console.log(x); defined-1.0.1/index.js000066400000000000000000000002621432154422100145520ustar00rootroot00000000000000'use strict'; module.exports = function defined() { for (var i = 0; i < arguments.length; i++) { if (typeof arguments[i] !== 'undefined') { return arguments[i]; } } }; defined-1.0.1/package.json000066400000000000000000000036041432154422100153760ustar00rootroot00000000000000{ "name": "defined", "version": "1.0.1", "description": "return the first argument that is `!== undefined`", "main": "index.js", "directories": { "example": "example", "test": "test" }, "devDependencies": { "@ljharb/eslint-config": "^21.0.0", "aud": "^2.0.1", "auto-changelog": "^2.4.0", "eslint": "=8.8.0", "in-publish": "^2.0.1", "npmignore": "^0.3.0", "safe-publish-latest": "^2.0.0", "tape": "^5.6.1" }, "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublish": "not-in-publish || npm run prepublishOnly", "prepublishOnly": "safe-publish-latest", "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", "tests-only": "tape 'test/**/*.js'", "test": "npm run tests-only", "posttest": "aud --production", "version": "auto-changelog && git add CHANGELOG.md", "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" }, "testling": { "files": "test/*.js", "browsers": { "ie": [ 6, 7, 8, 9 ], "ff": [ 3.5, 10, 15 ], "chrome": [ 10, 22 ], "safari": [ 5.1 ], "opera": [ 12 ] } }, "repository": { "type": "git", "url": "git://github.com/inspect-js/defined.git" }, "homepage": "https://github.com/inspect-js/defined", "keywords": [ "undefined", "short-circuit", "||", "or", "//", "defined-or" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "funding": { "url": "https://github.com/sponsors/ljharb" }, "license": "MIT", "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true }, "publishConfig": { "ignore": [ ".github/workflows" ] } } defined-1.0.1/test/000077500000000000000000000000001432154422100140645ustar00rootroot00000000000000defined-1.0.1/test/def.js000066400000000000000000000012741432154422100151640ustar00rootroot00000000000000'use strict'; var defined = require('../'); var test = require('tape'); test('defined-or', function (t) { var u = void undefined; t.equal(defined(), u, 'empty arguments'); t.equal(defined(u), u, '1 undefined'); t.equal(defined(u, u), u, '2 undefined'); t.equal(defined(u, u, u, u), u, '4 undefineds'); t.equal(defined(undefined, false, true), false, 'false[0]'); t.equal(defined(false, true), false, 'false[1]'); t.equal(defined(undefined, 0, true), 0, 'zero[0]'); t.equal(defined(0, true), 0, 'zero[1]'); t.equal(defined(3, undefined, 4), 3, 'first arg'); t.equal(defined(undefined, 3, 4), 3, 'second arg'); t.equal(defined(undefined, undefined, 3), 3, 'third arg'); t.end(); }); defined-1.0.1/test/falsy.js000066400000000000000000000003301432154422100155340ustar00rootroot00000000000000'use strict'; var test = require('tape'); var defined = require('../'); test('falsy', function (t) { t.plan(1); var opts = { y: false, w: 4 }; var x = defined(opts.x, opts.y, opts.w, 8); t.equal(x, false); });