Created
March 10, 2014 20:21
-
-
Save xk/9473457 to your computer and use it in GitHub Desktop.
Blocks === multiline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
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