native ESM · zero runtime dependencies · no build

Know what a value is.
Enforce what it should be.

strong-type gives JavaScript one clear type-checking surface across browsers and Node. Strict checks throw. Non-strict checks return booleans. The source you read is the source the runtime executes.

  • isomorphic core
  • 201 documented validators
  • 90.96% native executable-line coverage
type-gate.js
import Is from 'strong-type';

const is=new Is;
const value=new Map;

is.map(value);       // true
is.string(value);    // TypeError

Native by design

Nothing between your code and JavaScript.

There is no production dependency tree, CommonJS copy, transpiler, framework, or bundle. The optional Node adapter imports only built-in Node modules and never enters the default import graph.

Project guarantees
PropertyGuaranteeWhat it means
Module formatNative ESMRun the checked-in JavaScript directly.
Runtime dependenciesNoneNo third-party production packages.
Build stepNoneNo bundler or transpiler is required.
Default entrystrong-typeBrowser-safe and Node-safe.
Node entrystrong-type/nodeExplicit Node built-ins and exact util checks.
Testsvanilla-test 2.1.01,268 focused tests across five exclusive suites, plus seven shared behaviors in Node and real Chrome.

Install

One package. Two explicit entry points.

npm
npm install strong-type
Import options
ImportRuntimeContentsBuild required
strong-typeBrowser + Node183 isomorphic validatorsNo
strong-type/index.jsBrowser + NodeCompatibility path to the same coreNo
strong-type/nodeNode onlyCore plus 18 Node validatorsNo
strong-type/node.jsNode onlyCompatibility path to the Node adapterNo

Quick start

Strict when enforcing. Boolean when inspecting.

JavaScript
import Is from 'strong-type';

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

is.string('strong-type');        // true
weakIs.number('42');             // false
is.union(new Map,'map|set');     // true

is.number('42');                 // throws TypeError
Strict and non-strict behavior
ModeCreatePassing checkFailing check
Strictnew IstrueThrows TypeError
Non-strictnew Is(false)truefalse

Direct browser import

Use a module script. Still no bundle.

strong-type works with bundlers and without a bundler. Bundlers resolve the bare package import normally. Native browser ESM uses an import map and executes the same checked-in module with no build or transpilation step.

Load the checked-in module directly from this project’s own Pages URL, or self-host the same file. The browser executes it as native ESM.

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

    const is=new Is;
    console.log(is.url(new URL('https://example.com')));
</script>

For a bare package name, point a native import map at your self-hosted package file:

HTML · import map
<script type="importmap">
{
    "imports": {
        "strong-type": "./node_modules/strong-type/index.js"
    }
}
</script>

<script type="module">
    import Is from 'strong-type';
    console.log(new Is(false).string('native ESM'));
</script>
Import-map paths are relative to the HTML document. Serve the app over HTTP(S) and configure the server to expose the mapped node_modules file; file:// is not supported. There are no runtime dependencies, so no dependency entries or nested-version scopes are needed.

Runtime boundary

The default graph stays isomorphic.

Browserimport Is from 'strong-type'
→
index.jszero host imports
←
Nodeimport Is from 'strong-type'
Node precision→import Is from 'strong-type/node'→node:* built-ins only

Tested in public

Web-standard tests. Native coverage.

The five-suite registry runs through vanilla-test 2.1.0. A shared bare-import behavioral inventory also runs unchanged in Node and real Chrome through the explicit browser import map. The native Node V8 collector measures only the shipped runtime sources and enforces per-file release floors in CI.

1,268passing tests
90.96%executable lines
71.77%V8 block ranges
98.80%function ranges
See suites, coverage, and CI matrix

Focused documentation

Choose the page for the job.