The check method is used for find out if the argument or types are matching the pattern.
Open the command prompt window and install the package.
C:\Users\username\Desktop\meteorApp>meteor add check
In the following example, we want to check if myValue is a string. Since it is true, the app will proceed without any errors.
var myValue = 'My Value...'; check(myValue, String);
In this example, myValue is not a string but a number, hence the console will log an error.
var myValue = 1; check(myValue, String);
The Match.test is similar to check, the difference being when the test fails instead of a console error, we will get a value without breaking the server. The following example shows how to test an object with multiple keys.
var myObject = { key1 : "Value 1...", key2 : "Value 2..." } var myTest = Match.test(myObject, { key1: String, key2: String }); if ( myTest ) { console.log("Test is TRUE..."); } else { console.log("Test is FALSE..."); }
Since the both keys are strings, the test is true. The console will log the first option.
If we change the key2 to number, the test will fail and the console will log the second option.
var myObject = { key1 : "Value 1...", key2 : 1 } var myValue = 1; var myTest = Match.test(myObject, { key1: String, key2: String }); if ( myTest ) { console.log("Test is TRUE..."); } else { console.log("Test is FALSE..."); }