项目作者: fmartin5

项目描述 :
Runtime type checking and assertion library.
高级语言: JavaScript
项目地址: git://github.com/fmartin5/type-checking.git
创建时间: 2017-12-21T20:31:10Z
项目社区:https://github.com/fmartin5/type-checking

开源协议:GNU Affero General Public License v3.0

下载


type-checking

@fmartin5/type-checking"">NPM Version
@fmartin5/type-checking"">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.
  • Aims to provide readable error messages.
  • Does not rely on Symbol.toStringTag
  • You can easily disable typeChecking.assert() (but not .expect()) for production:
    in Node: by setting the NODE_NDEBUG environment variable;
    in Nashorn: by setting the “nashorn.ndebug” system property.
  • 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.

Installation

  1. npm install @fmartin5/type-checking

Usage

  1. const tc = require("@fmartin5/type-checking");
  2. let x = 0;
  3. tc.isNumber(x); // true
  4. tc.isInteger(x); // true
  5. tc.isPositiveNumber(x); // true
  6. tc.isPositiveInteger(x); // true
  7. tc.isStrictlyPositiveNumber(x); // false
  8. tc.isStrictlyPositiveInteger(x); // false
  9. let map = new Map();
  10. tc.isMap(map); // true
  11. tc.isWeakMap(map); // false
  12. tc.expectMap(map); //
  13. tc.expectWeakMap(map); // TypeError: expected a 'WeaMap' object.

Tests

Clone the repo, then do:

  1. npm install
  2. npm test

License

AGPL-3.0