2021-06-08 10:44:33 +00:00
|
|
|
import yaml from 'js-yaml';
|
2015-11-14 02:40:38 +00:00
|
|
|
|
2021-06-08 10:44:33 +00:00
|
|
|
export function isYAMLBlock(text) {
|
2018-03-25 15:47:22 +00:00
|
|
|
return /^<!-- YAML/.test(text);
|
2015-11-14 02:40:38 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 10:44:33 +00:00
|
|
|
export function isSourceLink(text) {
|
2020-06-22 17:56:08 +00:00
|
|
|
return /^<!-- source_link=([^\s/]+\/)+\w+\.\w+ -->/.test(text);
|
|
|
|
}
|
|
|
|
|
2021-06-08 10:44:33 +00:00
|
|
|
export function arrify(value) {
|
2016-04-30 23:51:38 +00:00
|
|
|
return Array.isArray(value) ? value : [value];
|
|
|
|
}
|
|
|
|
|
2021-06-08 10:44:33 +00:00
|
|
|
export function extractAndParseYAML(text) {
|
2018-03-21 14:37:12 +00:00
|
|
|
text = text.trim()
|
|
|
|
.replace(/^<!-- YAML/, '')
|
2015-11-14 02:40:38 +00:00
|
|
|
.replace(/-->$/, '');
|
|
|
|
|
2021-01-08 10:39:13 +00:00
|
|
|
// js-yaml.load() throws on error.
|
|
|
|
const meta = yaml.load(text);
|
2016-04-30 23:51:38 +00:00
|
|
|
|
2024-10-09 06:42:16 +00:00
|
|
|
// Since semver-minors can trickle down to previous major versions,
|
|
|
|
// features may have been added in multiple versions.
|
|
|
|
meta.added &&= arrify(meta.added);
|
|
|
|
|
|
|
|
meta.napiVersion &&= arrify(meta.napiVersion);
|
|
|
|
|
|
|
|
// Treat deprecated like added for consistency.
|
|
|
|
meta.deprecated &&= arrify(meta.deprecated);
|
|
|
|
|
|
|
|
meta.removed &&= arrify(meta.removed);
|
|
|
|
|
|
|
|
meta.changes ||= [];
|
2017-01-10 19:43:57 +00:00
|
|
|
|
2016-04-30 23:51:38 +00:00
|
|
|
return meta;
|
2015-11-14 02:40:38 +00:00
|
|
|
}
|