-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.js
26 lines (17 loc) · 793 Bytes
/
utils.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
var cloneRegexp = require('clone-regexp');
// Copied from:
// https://github.com/timmfin/broccoli-sprockets-dependencies/blob/4f20be3924d93577c156b3385fc9f2900af6a595/resolver.coffee#L13-L34
var HEADER_PATTERN = /^(?:\s*((?:\/[*](?:\s*|.+?)*?[*]\/)|(?:\#\#\#\n(?:[\s\S]*)\n\#\#\#)|(?:\/\/.*\n?)+|(?:\#.*\n?)+)*)*/m;
var DIRECTIVE_PATTERN = /^(\W*=)\s*(\w+)\s*(.*?)(\*\/)?$/gm;
function extractHeader(content, customHeaderPattern) {
var headerPattern = cloneRegexp(customHeaderPattern || HEADER_PATTERN);
// Must be at the very beginning of the file
if ((match = headerPattern.exec(content)) && match && match.index === 0) {
return match[0];
}
}
module.exports = {
HEADER_PATTERN: HEADER_PATTERN,
DIRECTIVE_PATTERN: DIRECTIVE_PATTERN,
extractHeader: extractHeader
};