Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
assert
✓ import { assert } from 'rtts_assert';
✗ const assert = require('rtts_assert');
ESM-only since v2; no CommonJS support.
assert.type
✓ assert.type(value, Type);
✗ assert(value, Type);
assert.type requires two args; direct assert() with one arg is different (returns an assertion object).
assert.define
✓ assert.define('MyType', function(value) { ... });
✗ assert.define(MyType, function(value) { ... });
First argument must be a string name, not a class/function.
Shows basic type assertion, value assertion, and custom type definition.
import { assert } from 'rtts_assert';
assert.type('hello', String); // passes
assert.type(42, String); // throws: Expected String, got Number.
const value = 'test';
assert(value).is(String); // passes
assert(value).is(Number); // throws
assert.define('Email', function(value) {
assert(value).is(String);
if (value.indexOf('@') === -1) {
assert.fail('must contain @');
}
});
assert.type('user@example.com', Email); // passes
assert.type('invalid', Email); // throws: must contain @
Debug
Known issues
breakingassert.argumentTypes is deprecated and removed in v2; use assert.type instead.fixReplace assert.argumentTypes(arg1, Type, arg2, Type) with individual assert.type calls.
affects: >=2.0.0
deprecatedES5 build script es5build.js is no longer maintained.fixUse a modern bundler (e.g., esbuild, Webpack) to transpile ES6 sources.
affects: >=2.0.0
gotchaassert(value).is(...) returns an assertion object, not a boolean; must be called as a statement.fixDo not assign the result: use assert(value).is(Type) without assignment.
affects: *
gotchaCustom types defined with assert.define must use a string name; using a class name will silently fail.fixassert.define('MyClass', fn) instead of assert.define(MyClass, fn). affects: *
breakingPredefined types like assert.string now require assert.type(value, assert.string) instead of assert(value).is(assert.string) pattern changed.fixUse assert.type(value, assert.string) or assert(value).is(assert.string) still works.
affects: >=2.0.0-alpha.37
Errors
Common errors & fixes
TypeError: assert.argumentTypes is not a function
assert.argumentTypes was removed in v2.0.0.
fixReplace with assert.type(arg1, Type), assert.type(arg2, Type), etc.
Error: Expected argument to be a string but got 'undefined'
assert.define first argument must be a string name, not a type reference.
fixassert.define('MyType', ..., not assert.define(MyType, ...). AssertionError: Expected String, got Number.
Value does not match the asserted type.
fixCheck the value and type: assert.type(value, ActualType).
Upgrade
Version history
2.0.0-alpha.37latest on npm
Audit
Dependencies
No dependency data recorded yet.