4.0.0 • Published 3 years ago

likewise v4.0.0

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

about

Produces exceptions for failing assertions. Includes ready-made checks for truthiness and equality. Combines with tapeling in tapeless for TAP formatted output.

setup

Download from the npm registry:

# Add to package.json
npm install likewise --save-dev

Source from an import map to use with Deno or in-browser directly:

{
  "imports": {
    "likewise": "https://cdn.jsdelivr.net/npm/likewise@latest/main.js"
  }
}

usage

The named export reassert() is available for creating own assertions. For example,

import { reassert } from "likewise"

// Basic truthiness checking
const truthy = (v) => !!v
const falsy = (v) => !v

// Wrap with `reassert()` to throw an `Error` with
// the 'expected' value and an 'operator' key on failure,
// the 2nd and 3rd arguments respectively
const ok = reassert(truthy, true, "!!")
const notOk = reassert(falsy, false, "!")

// Clean run
console.assert(ok(true), "ok")
console.assert(notOk(0), "not ok")

Additionally, ok() and equal() plus counterparts are attached to assert() already wrapped. For example,

import { assert } from "likewise"

const { ok, notOk, equal, notEqual } = assert

// Clean run
console.assert(ok(true), "ok")
console.assert(notOk(0), "not ok")

// Based on `Object.is()`
console.assert(equal(null, null), "equal")
console.assert(notEqual(null, 0), "not equal")

see also

3.0.3

3 years ago

4.0.0

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.7

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.2

4 years ago

1.0.1

4 years ago

1.0.0

6 years ago

0.0.5

6 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago