# optval

> Tiny module for setting a default value when a parameter is undefind or null

Latest version **1.0.1** (published 2014-10-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install optval
pnpm add optval
yarn add optval
bun add optval
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2014-10-10 |
| First published | 2014-10-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | John Frizelle |
| Maintainers | johnfriz |
| Keywords | typeof, undefined, optional, parameter |

## Links

- npm: https://www.npmjs.com/package/optval
- Repository: https://github.com/johnfriz/node-optval
- Issues: https://github.com/johnfriz/node-optval/issues
- npm.io page: https://npm.io/package/optval

## Recent versions

- 1.0.1 (latest) — 2014-10-10
- 1.0.0 — 2014-10-09

## README

# node-optval

Tiny module for setting a default value when a parameter is undefind or null.

Shorthand for

```
(typeof(param) === 'undefined' || param === null) ? defaultVal : param
```

The tests say it all...

```
assert.equal('foo', optval('foo'));
assert.equal('foo', optval('foo', 'bar'));

assert.equal('bar', optval(undefined, 'bar'));
assert.equal('bar', optval(null, 'bar'));

assert.equal(undefined, optval(undefined));
assert.equal(undefined, optval(null));

assert.equal(undefined, optval(undefined, undefined));
assert.equal(undefined, optval(null, undefined));

assert.equal(null, optval(undefined, null));
assert.equal(null, optval(null, null));
```


# Changelog

## 1.0.1
2 more tests for undefined & null with no default param

## 1.0.0
Inital version

---
_Source: https://npm.io/package/optval · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
