1'use strict'; 2 3const yaml = 4 require(`${__dirname}/../node_modules/eslint/node_modules/js-yaml`); 5 6function isYAMLBlock(text) { 7 return /^<!-- YAML/.test(text); 8} 9 10function isSourceLink(text) { 11 return /^<!-- source_link=([^\s/]+\/)+\w+\.\w+ -->/.test(text); 12} 13 14function arrify(value) { 15 return Array.isArray(value) ? value : [value]; 16} 17 18function extractAndParseYAML(text) { 19 text = text.trim() 20 .replace(/^<!-- YAML/, '') 21 .replace(/-->$/, ''); 22 23 // js-yaml.safeLoad() throws on error. 24 const meta = yaml.safeLoad(text); 25 26 if (meta.added) { 27 // Since semver-minors can trickle down to previous major versions, 28 // features may have been added in multiple versions. 29 meta.added = arrify(meta.added); 30 } 31 32 if (meta.napiVersion) { 33 meta.napiVersion = arrify(meta.napiVersion); 34 } 35 36 if (meta.deprecated) { 37 // Treat deprecated like added for consistency. 38 meta.deprecated = arrify(meta.deprecated); 39 } 40 41 if (meta.removed) { 42 meta.removed = arrify(meta.removed); 43 } 44 45 meta.changes = meta.changes || []; 46 47 return meta; 48} 49 50module.exports = { arrify, isYAMLBlock, isSourceLink, extractAndParseYAML }; 51