forked from alextownleymakes/htmlTagValidator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (37 loc) · 1 KB
/
index.js
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
37
38
39
40
41
42
43
var htmlParser = require('./src/html-parser'),
toStr = function (f) {
return Object.prototype.toString.call(f);
};
function htmlTagValidator(source, callback) {
var options = htmlTagValidator._options, func = callback;
if (arguments.length > 2) {
options = callback;
func = arguments[2];
}
if (toStr(func) !== '[object Function]') {
// Sync
if (toStr(func) === '[object Object]') {
options = func;
}
return htmlParser.parse(source, options);
}
// Async
setTimeout((function (ctx, s, o, f) {
return function () {
var ast, err;
try {
ast = htmlParser.parse(s, o);
} catch (e) {
err = e;
}
f.apply(ctx, [err, ast]);
};
})(this, source, options, func), 0);
};
htmlTagValidator.NAME = "html-tag-validator";
htmlTagValidator.VERSION = "1.6.0";
htmlTagValidator._options = {};
htmlTagValidator.setOptions = function(options) {
this._options = options != null ? options : {};
};
module.exports = htmlTagValidator;