zoukankan      html  css  js  c++  java
  • Meteor Match

    Match Patterns

    The following patterns can be used as pattern arguments to check and Match.test:

    Match.Any

    Matches any value.

    StringNumberBooleanundefinednull

    Matches a primitive of the given type.

    Match.Integer

    Matches a signed 32-bit integer. Doesn’t match Infinity-Infinity, or NaN.

    [pattern]

    A one-element array matches an array of elements, each of which match pattern. For example, [Number] matches a (possibly empty) array of numbers; [Match.Any] matches any array.

    {key1: pattern1, key2: pattern2, …}
    Matches an Object with the given keys, with values matching the given patterns. If any pattern is a Match.Maybe or Match.Optional, that key does not need to exist in the object. The value may not contain any keys not listed in the pattern. The value must be a plain Object with no special prototype.
    Match.ObjectIncluding({key1: pattern1, key2: pattern2, …})
    Matches an Object with the given keys; the value may also have other keys with arbitrary values.
    Object

    Matches any plain Object with any keys; equivalent to Match.ObjectIncluding({}).

    Match.Maybe(pattern)

    Matches either undefinednull, or pattern. If used in an object, matches only if the key is not set as opposed to the value being set to undefined or null. This set of conditions was chosen because undefined arguments to Meteor Methods are converted to null when sent over the wire.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    // In an object
    var pattern = { name: Match.Maybe(String) };
    check({ name: “something” }, pattern) // OK
    check({}, pattern) // OK
    check({ name: undefined }, pattern) // Throws an exception
    check({ name: null }, pattern) // Throws an exception
     
    // Outside an object
    check(null, Match.Maybe(String)); // OK
    check(undefined, Match.Maybe(String)); // OK
    Match.Optional(pattern)

    Behaves like Match.Maybe except it doesn’t accept null. If used in an object, the behavior is identical to Match.Maybe.

    Match.OneOf(pattern1, pattern2, ...)

    Matches any value that matches at least one of the provided patterns.

    Any constructor function (eg, Date)

    Matches any element that is an instance of that type.

    Match.Where(condition)

    Calls the function condition with the value as the argument. If condition returns true, this matches. If condition throws a Match.Error or returns false, this fails. If conditionthrows any other error, that error is thrown from the call to check or Match.test. Examples:

    1
    2
    3
    4
    5
    6
    7
    check(buffer, Match.Where(EJSON.isBinary));
     
    NonEmptyString = Match.Where(function (x) {
    check(x, String);
    return x.length > 0;
    });
    check(arg, NonEmptyString);
  • 相关阅读:
    把梳子卖给和尚 引起的CRM
    windows 2008 r2 安装 owas 2013
    wopihost
    电商创业,你到底需要多少人的技术团队?
    信息化,并不能代替管理
    可遇不可求的Question之error: Failed dependencies: MySQLconflicts 错误篇
    可遇不可求的Question之flash的socket连接安全策略文件篇
    可遇不可求的Question之MySQL系统变量interactive_timeout 与 wait_timeout 篇
    可遇不可求的Question之导入mysql中文乱码解决方法篇
    Codesmith怎么判断sqlserver数据库字段是不是标识自增字段
  • 原文地址:https://www.cnblogs.com/BSor/p/6134203.html
Copyright © 2011-2022 走看看