1.0.22 • Published 2 years ago

@hugoalh/undefinish v1.0.22

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Undefinish (NodeJS)

License GitHub Repository GitHub Stars GitHub Contributors GitHub Issues GitHub Pull Requests GitHub Discussions CodeFactor Grade

ReleasesLatest (GitHub Latest Release Date)Pre (GitHub Latest Pre-Release Date)
GitHub GitHub Total DownloadsGitHub Latest Release VersionGitHub Latest Pre-Release Version
NPM NPM Total DownloadsNPM Latest Release VersionNPM Latest Pre-Release Version

📝 Description

A NodeJS module to provide a better and easier coalescing, similar to the function default parameter.

Although the nullish coalescing operator (??) is an improved operator from the OR operator (||), it is still not good enough due to it considers null is an undefined value, even though this is defined and/or as expected.

The conditional (ternary) operator (?:) maybe good:

(typeof a === "undefined") ? 1 : a;

But it is not that good when need to have many:

(typeof a === "undefined") ? (
  (typeof b === "undefined") ? (
    (typeof c === "undefined") ? (
      (typeof d === "undefined") ? (
        (typeof e === "undefined") ? 1 : e
      ) : d
    ) : c
  ) : b
) : a;

Much cleaner with Undefinish:

undefinish(a, b, c, d, e, 1);

📚 Documentation

Getting Started

  • NodeJS >= v6.9.0
npm install @hugoalh/undefinish
/* Either */
const undefinish = require("@hugoalh/undefinish");// [CommonJS] Require
import undefinish from "@hugoalh/undefinish";// [ModuleJS] Default Import

API

Function

undefinish(...inputs: unknown[]): unknown;

Example

let input = {
  name: null,
  age: 8
};

input.name ?? "owl";
//=> "owl"

undefinish(input.name, "owl");
//=> null
1.0.22

2 years ago

1.0.21

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.19-beta.1

2 years ago

1.0.20

2 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.11

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

4 years ago

1.0.2

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago