Files
meteor/packages/check
James Burgess 20e89b9009 Modernize check package (#9638)
I've reverted match properties that return class instances back to normal functions, so that they can be called as constructors.

Also, I added tests to make sure we catch this issue if someone else gets the same idea that I had!
2018-03-07 11:36:48 -05:00
..
2018-03-07 11:36:48 -05:00
2018-03-07 11:36:48 -05:00
2018-03-07 11:36:48 -05:00
2016-08-30 15:40:14 -07:00

check

Source code of released version | Source code of development version


check is a lightweight package for argument checking and general pattern matching. Use it like this:

Meteor.publish("chats-in-room", function (roomId) {
  // Make sure roomId is a string, not an arbitrary mongo selector object.
  check(roomId, String);
  return Chats.find({room: roomId});
});

Meteor.methods({addChat: function (roomId, message) {
  check(roomId, String);
  check(message, {
    text: String,
    timestamp: Date,
    // Optional, but if present must be an array of strings.
    tags: Match.Optional([String])
  });

  // ... do something with the message ...
}});

For more details see the check section of the Meteor docs.