-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAIMLParser.js
More file actions
36 lines (27 loc) · 866 Bytes
/
Copy pathAIMLParser.js
File metadata and controls
36 lines (27 loc) · 866 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
27
28
29
30
31
32
33
34
35
36
'use strict';
var parseString = require('xml2js').parseString;
module.exports.parse = function (stringToParse, callback) {
if (arguments.length < 2) {
throw new Error('Too few arguments: need at least two arguments');
}
if (typeof stringToParse !== 'string') {
throw new TypeError('First argument must be a string');
}
if (typeof callback !== 'function') {
throw new TypeError('Second argument must be a function');
}
parseString(stringToParse, function (err, _result) {
var result = [];
// istanbul ignore next
if (_result !== undefined) {
for (var i = 0; i < _result.aiml.pattern.length; i++) {
var tempObj = {
trigger: _result.aiml.pattern[i].toLowerCase(),
responses: [_result.aiml.template[i]]
};
result.push(tempObj);
}
}
callback(result);
});
};