0.3.5 • Published 3 years ago

assertmin v0.3.5

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

all other assertion packages on this damned registry are awful

god awful.

just use this one, it's like 4 lines of code and typescript declarations

it runs on the browser without polyfills like process for assert

import { assert } from 'assertmin';

// Boolean assertions
assert(2 + 2 === 4);

function isGoodBoy(name) {
    return name === 'dog';
}

assert(isGoodBoy('dog'));
assert(!isGoodBoy('doru'));

// Equality assertions
assert.eq(
    Math.ceil(Math.random() * 42),
    42
);

// TypeScript assertions
type Arg = number | null;

function pad(n: Arg) {
    // By the point this function is called, you're certain `n` is a number
    // But typescript doesn't know that, so assert that is the case
    assert(n !== null);

    // If you're particularly confident, you can use `assert.unchecked`
    // It won't perform any checks internally, but will still assert
    // to typescript that the condition is true

    // If you have webpack or another smart bundler,
    // `assert.dev` only runs code when `process.env.NODE_ENV`
    // is not equal to "production"

    // Now you can use it normally
    return n.toString().padStart(2, '0');
}

// Exhaustiveness checks
type A = {
    letter: 'a';
};
type B = {
    letter: 'b';
};
type Letter = A | B;

const letter: Letter = {
    letter: 'b';
};

switch (letter.letter) {
    case 'a':
        break;
    case 'b':
        // Try commenting this case out
        break;
    default:
        assert.unreachable();
}

The example above is way longer than the actual source code

0.3.5

3 years ago

0.1.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago