-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
72 lines (59 loc) · 974 Bytes
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Parsers
*/
var parsers = {};
parsers.js = require('./lib/js');
parsers.css = require('./lib/css');
parsers.html = require('./lib/html');
/**
* Export `deps`
*/
module.exports = deps;
/**
* Allow registering custom types
*
* @param {String} type
* @param {Function} fn
*/
exports.register = function (type, fn) {
parsers[type] = fn;
};
/**
* Initialize `deps`
*
* @param {String} str
* @param {String} ext
* @param {Function} fn
*/
function deps(str, ext, fn) {
return fn
? rewrite(str, ext, fn)
: parse(str, ext);
};
/**
* Parse
*
* @param {String} str
* @param {String} ext
* @api public
*/
function parse(str, ext) {
var parser = parsers[ext];
return parser
? parser(str)
: [];
}
/**
* Rewrite
*
* @param {String} str
* @param {String} ext
* @param {Function} fn
* @api public
*/
function rewrite(str, ext, fn) {
var rewriter = parsers[ext];
return rewriter
? rewriter(str, ext, fn)
: str;
}