Skip to content

Instantly share code, notes, and snippets.

@xk
Created March 10, 2014 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xk/9473457 to your computer and use it in GitHub Desktop.
Save xk/9473457 to your computer and use it in GitHub Desktop.
Blocks === multiline
/*!
multiline
Multiline strings in JavaScript
https://github.com/sindresorhus/multiline
by Sindre Sorhus
MIT License
*/
(function () {
'use strict';
// start matching after: comment start block => ! or @preserve => optional whitespace => newline
// stop matching before: last newline => optional whitespace => comment end block
var reCommentContents = /\/\*!?(?:\@preserve)?\s*(?:\r\n|\n)([\s\S]*?)(?:\r\n|\n)\s*\*\//;
var multiline = 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];
};
if (typeof module !== 'undefined' && module.exports) {
module.exports = multiline;
} else {
window.multiline = multiline;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment