1.0.2 • Published 6 years ago

@typeforce/elvis v1.0.2

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

elvis

NPM NPM CDN LICENSE

Return an alternative value if a specific value is null or undefined.

Usage

    npm install @typeforce/elvis --save   # Install package via NPM
    import { expect } from "chai";
    import elvis from "@typeforce/elvis";

    expect(elvis("foo", "bar")).to.equal("foo");
    expect(elvis(42, 5)).to.equal(42);
    expect(elvis(false, "foo")).to.equal("foo"));

    expect(elvis(undefined, "bar")).to.equal("bar");
    expect(elvis(null, "foo")).to.equal("foo");
    expect(elvis(undefined, undefined).to.be.undefined;
    expect(elvis(null, null)).to.be.null;

This package contains TypeScript type declarations.

Content Delivery Network (CDN)

This package can be imported via unpkg as demonstrated below.

    <script src="https://unpkg.com/@typeforce/elvis/dist/index.min.js"></script>
    <script type="application/javascript">
        var x = "foo";
        console.log(elvis(x, "bar"));
        // -> "foo"!
    </script>

Build & Test

When building the project, a folder named dist/ will be created if it does not already exist, where the compiled code will be outputted to. Type declaration files will also be generated and outputted to the dist/ folder.

A minified Javascript version of the entire project will be generated and outputted to dist/index.min.js.

    npm install     # Installs dependencies.
    npm run build   # Build the project.

This package uses Gulp for building, and Chai and Mocha for testing.

    npm test       # Run tests.

License

Refer to the LICENSE file for license information.