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