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.

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*!
  2. * parse-author <https://github.com/jonschlinkert/parse-author>
  3. *
  4. * Copyright (c) 2014-2017, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. var regex = require('author-regex');
  9. module.exports = function(str) {
  10. if (typeof str !== 'string') {
  11. throw new TypeError('expected author to be a string');
  12. }
  13. if (!str || !/\w/.test(str)) {
  14. return {};
  15. }
  16. var match = [].concat.apply([], regex().exec(str));
  17. var author = {};
  18. if (match[1]) {
  19. author.name = match[1];
  20. }
  21. for (var i = 2; i < match.length; i++) {
  22. var val = match[i];
  23. if (i % 2 === 0 && val && match[i + 1]) {
  24. if (val.charAt(0) === '<') {
  25. author.email = match[i + 1];
  26. i++;
  27. } else if (val.charAt(0) === '(') {
  28. author.url = match[i + 1];
  29. i++;
  30. }
  31. }
  32. }
  33. return author;
  34. };