From 6776c354b80e25ff5445dc627d826ecf42bdfd87 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Wed, 17 Apr 2013 11:54:54 -0700 Subject: [PATCH] start of docs for check --- docs/client/api.html | 43 +++++++++++++++++++++++++++++++++++++++++++ docs/client/api.js | 43 +++++++++++++++++++++++++++++++++++++++++++ docs/client/docs.js | 6 ++++++ 3 files changed, 92 insertions(+) diff --git a/docs/client/api.html b/docs/client/api.html index 921c182596..0fa422de61 100644 --- a/docs/client/api.html +++ b/docs/client/api.html @@ -2273,6 +2273,49 @@ sub-template. {{/api_box_inline}} +

Match

+ +Meteor methods and publish functions take arbitrary [EJSON](#ejson) types as +arguments, but most arguments are expected to be of a particular type. Meteor's +`check` package is a lightweight library for checking that arguments and other +values are of the expected type. + +XXX EXAMPLE HERE + +{{> api_box check}} + +If the match fails, `check` throws a `Match.Error` describing how it failed. If +this error gets sent over the wire to the client, it will appear only as +`Meteor.Error(400, "Match Failed")`; the failure details will be written to the +server logs but not revealed to the client. + +{{> api_box match_test}} + +{{#api_box_inline matchpatterns}} + +The following patterns can be used as pattern arguments to `check` and `Match.test`: + + +
+{{#dtdd "String, Number, Boolean, undefined, null"}} +Matches a primitive of the given type. +{{/dtdd}} + +{{#dtdd "Match.Any"}} +Matches any value. +{{/dtdd}} + +{{#dtdd "A constructor function"}} +Matches any element that is an instance of that type. For example, `Date`. +{{/dtdd}} + +{{#dtdd "[pattern]"}} +A one-element array matches an array of elements, each of which match the +{{/dtdd}} + +
+ +{{/api_box_inline}}

Timers

diff --git a/docs/client/api.js b/docs/client/api.js index 2a0b0b1944..cc0b3266f2 100644 --- a/docs/client/api.js +++ b/docs/client/api.js @@ -1357,6 +1357,49 @@ Template.api.accounts_emailTemplates = { +Template.api.check = { + id: "check", + name: "check(value, pattern)", + locus: "Anywhere", + descr: ["Checks that a value matches a [pattern](#matchpatterns). If the value does not match the pattern, throws a `Match.Error`."], + args: [ + { + name: "value", + type: "Any", + descr: "The value to check" + }, + { + name: "pattern", + type: "Match pattern", + descr: "The [pattern](#matchpatterns) to match `value` against" + } + ] +}; + +Template.api.match_test = { + id: "match_test", + name: "Match.test(value, pattern)", + locus: "Anywhere", + descr: ["Returns true if the value matches the [pattern](#matchpatterns)."], + args: [ + { + name: "value", + type: "Any", + descr: "The value to check" + }, + { + name: "pattern", + type: "Match pattern", + descr: "The [pattern](#matchpatterns) to match `value` against" + } + ] +}; + +Template.api.matchpatterns = { + id: "matchpatterns", + name: "Match patterns" +}; + Template.api.setTimeout = { id: "meteor_settimeout", name: "Meteor.setTimeout(func, delay)", diff --git a/docs/client/docs.js b/docs/client/docs.js index 352262e212..2c13526aa3 100644 --- a/docs/client/docs.js +++ b/docs/client/docs.js @@ -242,6 +242,12 @@ var toc = [ {name: "Reactivity isolation", style: "noncode", id: "isolate"} ], + "Match", [ + "check", + "Match.test", + {name: "Match patterns", style: "noncode"} + ], + "Timers", [ "Meteor.setTimeout", "Meteor.setInterval",