Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

@fmartin5/type-checking

1.1.1 • Public • Published

type-checking

NPM Version NPM Downloads

Runtime type checking and type assertion library for Node and the browser

  • Traditional syntax.

  • Aims to cover every EcmaScript language type and specification type except Proxy.

  • Offers a small set of composable numeric predicates and assertions for integers, signed numbers, and special numbers.

  • Cross-realm/iframe support (i.e., predicates should remain correct across different realms).

  • Does not get easily fooled by the value of the Symbol.toStringTag property.

  • Handles -0 and NaN correctly.

  • Does not aim to cover any DOM API type.

  • Does not aim to cover complex constrained string types like email address etc.

  • Does not aim to offer custom type constructor.

  • Aims to provide readable error messages.

  • Does not rely on Symbol.toStringTag

Installation

npm install @fmartin5/type-checking

Usage

const tc = require("@fmartin5/type-checking");
 
let x = 0;
 
tc.isNumber(x); // true
tc.isInteger(x); // true
 
tc.isPositiveNumber(x); // true
tc.isPositiveInteger(x); // true
 
tc.isStrictlyPositiveNumber(x); // false
tc.isStrictlyPositiveInteger(x); // false
 
 
let map = new Map();
tc.isMap(map); // true
tc.isWeakMap(map); // false
 
tc.expectMap(map); //
tc.expectWeakMap(map); // TypeError: expected a 'WeaMap' object.
 
 

Tests

Clone the repo, then do:

npm install
npm test

License

AGPL-3.0

Install

npm i @fmartin5/type-checking

DownloadsWeekly Downloads

1

Version

1.1.1

License

AGPL-3.0

Unpacked Size

86.5 kB

Total Files

7

Last publish

Collaborators

  • avatar