Native module playground

Edit the source.
Run the real module.

The isolated editor imports the checked-in index.js through a native browser import map. There is no compiled playground copy.

Live editor

Press Run or Ctrl/⌘ + Enter.

The playground loads only the shared browser-safe entry. Node adapter examples run in Node and are documented on the reference page.

Recipes

Load a focused example.

Strict and weak modes

JavaScript
import Is from 'strong-type';

const is=new Is;
const weakIs=new Is(false);

console.log(is.string('type'));
console.log(weakIs.number('42'));

try{
    is.number('42');
}catch(error){
    console.error(error.message);
}

Unions and collections

JavaScript
import Is from 'strong-type';

const is=new Is;
const values=[new Map,new Set,'type',42];

for(const value of values){
    console.log(
        value,
        is.union(value,'map|set|string|number')
    );
}

Extend the validator

JavaScript
import Is from 'strong-type';

class Pizza{}

class MyIs extends Is{
    pizza(value){
        return this.instanceCheck(value,Pizza);
    }
}

const is=new MyIs;
console.log(is.pizza(new Pizza));
console.log(is.union(new Pizza,'pizza|string'));

Same pattern in your page

A normal module script is enough.

HTML
<script type="module">
    import Is from 'https://riaevangelist.github.io/strong-type/index.js';

    const is=new Is(false);
    document.body.dataset.valid=String(is.string('strong-type'));
</script>

For local development, run npm start and open http://localhost:8000/playground.html.