1.3.4 • Published 9 years ago

easier-types v1.3.4

Weekly downloads
42
License
MIT
Repository
github
Last release
9 years ago

easy-types

Easy type checking for node.js.

Installation

npm install easy-types

Usage

function Something() {}
var types = {
  myCrazyObject: {
    // Primitive type checking.
    a: 'string',
    b: 'number',
    c: 'boolean',
    d: 'function',
    e: 'object',
    // Defined types
    f: 'int',
    g: 'null',
    h: 'buffer',
    i: 'date',
    // Functions
    j: function(e){ return e === 42; },
    // Arrays
    k: '[int]',
    // User defined types
    l: 'otherObj',
    // Arrays with optional type
    m: '[string?]',
    // Arrays of user defined types
    n: '[otherObj]',
    // Optional types
    o: 'number?',
    // Optional user defined types
    p: '[otherObj?]',
    // Constructors
    q: Something
  },

  otherObj : {
    a : 'int',
    b : 'otherObj?'
  },
};
var check = require('./easy-types.js');

check.addTypes(types);

var toCheck = {
  a: 'domo arigato',
  b: 3.14159,
  c: false,
  d: function(){},
  e: {},
  f: 42,
  g: null,
  h: new Buffer(1),
  i: new Date(),
  j: 42,
  k: [1,2,3,4],
  l: {a:1, b: {a:1, b:undefined}},
  m: ['abc', null, 'def'],
  n: [{a:1, b:undefined}, {a:1, b:undefined}],
  p: [undefined, {a:1, b:undefined}],
  q: new Something()
};

try {
  check(toCheck).is('myCrazyObject');
  console.log('verified');
  // Your awesome code here.
} catch (e) {
  console.log(e);
}
1.3.4

9 years ago

1.3.3

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.9

9 years ago

1.1.8

9 years ago

1.1.7

9 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago