Skip to content

Type checking library for arguments, and complex data structures

License

Notifications You must be signed in to change notification settings

milojs/ml-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ml-check

Build Status npm version Test Coverage

An isomorphic, runtime, type checking utility that can be used on the server or in the client. Check was extracted from the Meteor framework, and has had some features added and been given full test coverage. It is used in the reactive framework milojs It allows to both document and to check parameter types in your function making code both readable and stable.

Usage

var check = milo.check
    , Match = check.Match;

function My(name, obj, cb) {
    // if any of checks fail an error will be thrown
    check(name, String);
    check(obj, Match.ObjectIncluding({ options: Object }));
    check(cb, Function);

    // ... your code
}

See Meteor docs to see how it works

Patterns

All patterns and functions described in Meteor docs work.

Unlike in Meteor, Object pattern matches instance of any class, not only plain object.

In addition to patterns described in Meteor docs the following patterns are implemented

Match.ObjectHash(pattern)

Matches an object where all properties match a given pattern

Match.Subclass(constructor [, matchThisClassToo])

Matches a class that is a subclass of a given class. If the second parameter is true, it will also match the class itself.

Without this pattern to check if MySubclass is a subclass of MyClass you would have to use

check(MySubclass, Match.Where(function() {
   return MySubclass.prototype instanceof MyClass;
});

Things we explicitly do NOT support:

  • heterogenous arrays

About

Type checking library for arguments, and complex data structures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •