type-enforcer

A type enforcement library for javascript

Usage no npm install needed!

<script type="module">
  import typeEnforcer from 'https://cdn.skypack.dev/type-enforcer';
</script>

README

Type Enforcer

A type enforcement library for javascript

npm build coverage deps size vulnerabilities license


Installation

npm install type-enforcer

Requires Babel 7.2+


Objects

assert : object

An assertion library for testing. Assertions do nothing if the test passes, and throw an AssertionError if they fail.

is : object

Utility functions for checking if a value is a particular data type.

enforce : object

Utility functions for enforcing data types.

method : object

Enforce data types and remove common boilerplate code on class methods.


Classes

Enum

Freezes an enumerable object and adds a few helper methods

Queue

A simple queue for callbacks that allows for adding, removing, and triggering all or specific callbacks

Removable

A mixin that adds methods to a class to facilitate clean-up

PrivateVars

A thin wrapper over WeakMap for storing private variables


Functions

abstractEquality(a, b)boolean

Performs an abstract equality check (==) between two values.

sameValue(a, b)boolean

Performs a SameValue equality check (Object.is) between two values.

sameValueZero(a, b)boolean

Performs a SameValueZero equality check between two values.

strictEquality(a, b)boolean

Performs a strict equality check (===) between two values.

applySettings(target, settings, [priority], [deferred])

Iterates over the provided settings and calls any methods of the same name, passing the value in as the argument.

castArray(value)Array

Casts a value to an array.