25 lines
693 B
JavaScript
25 lines
693 B
JavaScript
'use strict';
|
|
var stripIndent = require('strip-indent');
|
|
|
|
// start matching after: comment start block => ! or @preserve => optional whitespace => newline
|
|
// stop matching before: last newline => optional whitespace => comment end block
|
|
var reCommentContents = /\/\*!?(?:\@preserve)?[ \t]*(?:\r\n|\n)([\s\S]*?)(?:\r\n|\n)[ \t]*\*\//;
|
|
|
|
var multiline = module.exports = function (fn) {
|
|
if (typeof fn !== 'function') {
|
|
throw new TypeError('Expected a function');
|
|
}
|
|
|
|
var match = reCommentContents.exec(fn.toString());
|
|
|
|
if (!match) {
|
|
throw new TypeError('Multiline comment missing.');
|
|
}
|
|
|
|
return match[1];
|
|
};
|
|
|
|
multiline.stripIndent = function (fn) {
|
|
return stripIndent(multiline(fn));
|
|
};
|