_insertWrapDetails.js 748 B

123456789101112131415161718192021222324
  1. /** Used to match wrap detail comments. */
  2. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/;
  3. /**
  4. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5. *
  6. * @private
  7. * @param {string} source The source to modify.
  8. * @returns {Array} details The details to insert.
  9. * @returns {string} Returns the modified source.
  10. */
  11. function insertWrapDetails(source, details) {
  12. var length = details.length;
  13. if (!length) {
  14. return source;
  15. }
  16. var lastIndex = length - 1;
  17. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  18. details = details.join(length > 2 ? ', ' : ' ');
  19. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  20. }
  21. module.exports = insertWrapDetails;