type-dragoon

1.0.5 • Public • Published

type-dragoon

Type enforcer for JavaScript in Node.js

Installation

npm i type-dragoon

Importing

const t = require('type-dragoon');

Usage

General

const name = 'Lelouch';
const age = 18;
const alive = false;

t({string: name}, {number: age}, {boolean: alive});
// continues if correct types, else throws an error

Multiple types

t({'number|string': 18});

Custom errors

t({boolean: 'not a boolean', TypeError: 'My generic error'});
// throws 'TypeError: My generic error'

Callback on error

t({object: undefined, onWrongType: () => {
    console.log('My nice callback');
}});

Data types

  • undefined
  • null
  • object
  • array
  • boolean
  • function
  • number
  • bigint
  • string
  • symbol

Error types (mdn)

  • EvalError
  • RangeError
  • ReferenceError
  • SyntaxError
  • TypeError
  • URIError

Package Sidebar

Install

npm i type-dragoon

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

6.56 kB

Total Files

8

Last publish

Collaborators

  • cuadrix