-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
26 lines (23 loc) · 863 Bytes
/
example.js
File metadata and controls
26 lines (23 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var parse = require('./index');
// an array of patterns to match to, callbacks included
var patterns = [
{
pattern: 'Order {integer} rolls of toilet paper',
callback: function (rolls)
{
console.log('I will order ' + rolls + ' of toilet paper');
}
},
{
pattern: 'Remind me to {string} tomorrow',
callback: function (reminder)
{
console.log('I will remind you to ' + reminder + ' tomorrow at noon');
}
}
];
// parser stops after the first match is found, so the order of patterns is important.
// matching is case-insensitive
parse('Remind me to pay the taxes tomorrow', patterns);
// what if no match is found?
parse('Order bazillion rolls of toilet paper', patterns, function(msg) { console.log('Sorry, could not understand what you meant by: ' + msg); });