preact-cli-unassert
Plugin for
Getting Started
Install it with npm:
npm i -D preact-cli-unassert
or with yarn:
yarn add preact-cli-unassert --dev
This will also install:
And include in your project by creating or adding to preact.config.js
.
export default function customWebpackConfiguration(config, env, helpers) {
// Along with other customizations and plugin...
require('preact-cli-unassert')(config, env);
}
Example
Use console.assert
calls to check your inputs:
import { h } from 'preact';
const Asserted = ({ name }) => {
console.assert(name != null);
return <p>Hi {name}!</p>;
}
export default Asserted;
or the usual assert
APIs:
import assert from 'assert';
function add (a, b) {
assert(!isNaN(a));
assert.equal(typeof b, 'number');
assert.ok(!isNaN(b));
return a + b;
}
Related
See also preact-cli-power-assert.
Thanks
Many thanks to Jason Miller for creating ⚛️ Preact, much of the related ecosystem and lots of useful stuff.
Heavily inspired by preact-cli-lodash from Sara Vieira.