1.0.0 • Published 11 months ago
@allnulled/ensure v1.0.0
ensure
Simple API to do checks and keep good error reporting. For node.js or browser.
Installation
npm install -s @allnulled/ensureThen on node.js:
const ensure = require("@allnulled/ensure");Or on browser:
<script src="node_modules/@allnulled/ensure/ensure.js"></script>This will overwrite the global ensure as a function.
Usage
This is all the API. With can you can do anything: it must return true, otherwise it will throw an error.
The others are variants of can.
const v = 500;
ensure({ v }).is(500);
ensure({ v }).isnt(501);
ensure({ v }).type("number");
ensure({ v }).notType("string");
ensure({ v }).can(n => n > 100);
ensure({ v }).cant(n => n < 100);
ensure({ v }).throws(n => { throw new Error("wherever"); });
ensure({ v }).doesntThrow(n => "ok!");1.0.0
11 months ago