mirror of
https://github.com/nodejs/node.git
synced 2024-11-27 22:16:50 +01:00
71785889c8
PR-URL: https://github.com/nodejs/node/pull/55044 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
38 lines
898 B
JavaScript
38 lines
898 B
JavaScript
import yaml from 'js-yaml';
|
|
|
|
export function isYAMLBlock(text) {
|
|
return /^<!-- YAML/.test(text);
|
|
}
|
|
|
|
export function isSourceLink(text) {
|
|
return /^<!-- source_link=([^\s/]+\/)+\w+\.\w+ -->/.test(text);
|
|
}
|
|
|
|
export function arrify(value) {
|
|
return Array.isArray(value) ? value : [value];
|
|
}
|
|
|
|
export function extractAndParseYAML(text) {
|
|
text = text.trim()
|
|
.replace(/^<!-- YAML/, '')
|
|
.replace(/-->$/, '');
|
|
|
|
// js-yaml.load() throws on error.
|
|
const meta = yaml.load(text);
|
|
|
|
// 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 ||= [];
|
|
|
|
return meta;
|
|
}
|