You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
748 B

4 years ago
  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;