![Meteor Tutorial](/meteor/images/meteor-mini-logo.jpg)
- Meteor Tutorial
- Meteor - Home
- Meteor - Overview
- Meteor - Environment Setup
- Meteor - First Application
- Meteor - Templates
- Meteor - Collections
- Meteor - Forms
- Meteor - Events
- Meteor - Session
- Meteor - Tracker
- Meteor - Packages
- Meteor - Core API
- Meteor - Check
- Meteor - Blaze
- Meteor - Timers
- Meteor - EJSON
- Meteor - HTTP
- Meteor - Email
- Meteor - Assets
- Meteor - Security
- Meteor - Sorting
- Meteor - Accounts
- Meteor - Methods
- Meteor - Package.js
- Meteor - Publish & Subscribe
- Meteor - Structure
- Meteor - Deployment
- Meteor - Running on mobile
- Meteor - ToDo App
- Meteor - Best Practices
- Meteor Useful Resources
- Meteor - Quick Guide
- Meteor - Useful Resources
- Meteor - Discussion
Meteor - Check
The check method is used for find out if the argument or types are matching the pattern.
Installing Check Package
Open the command prompt window and install the package.
C:\Users\username\Desktop\meteorApp>meteor add check
Using 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.
meteorApp.js
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.
meteorApp.js
var myValue = 1; check(myValue, String);
![Meteor Check Log Error](/meteor/images/meteor-check-log-error.jpg)
Match Test
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.
meteorApp.js
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.
![Meteor Match Test True](/meteor/images/meteor-match-test-true.jpg)
If we change the key2 to number, the test will fail and the console will log the second option.
meteorApp.js
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..."); }
![Meteor Match Test False](/meteor/images/meteor-match-test-false.jpg)