extract_description.js 547 B

12345678910111213141516171819202122
  1. module.exports = extractDescription
  2. // Extracts description from contents of a readme file in markdown format
  3. function extractDescription (d) {
  4. if (!d) {
  5. return
  6. }
  7. if (d === 'ERROR: No README data found!') {
  8. return
  9. }
  10. // the first block of text before the first heading
  11. // that isn't the first line heading
  12. d = d.trim().split('\n')
  13. for (var s = 0; d[s] && d[s].trim().match(/^(#|$)/); s++) {
  14. ;
  15. }
  16. var l = d.length
  17. for (var e = s + 1; e < l && d[e].trim(); e++) {
  18. ;
  19. }
  20. return d.slice(s, e).join(' ').trim()
  21. }