mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
de01f475d5
- Migrated to ESM because some dependencies now require it. - Did not update `highlight.js` to v11 because it has many breaking changes. - Used non-deprecated `highlight.js` API. Refs: https://github.com/highlightjs/highlight.js/issues/2277 Fixes: https://github.com/nodejs/node/issues/38938 Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs/node/pull/38966 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
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);
|
|
|
|
if (meta.added) {
|
|
// Since semver-minors can trickle down to previous major versions,
|
|
// features may have been added in multiple versions.
|
|
meta.added = arrify(meta.added);
|
|
}
|
|
|
|
if (meta.napiVersion) {
|
|
meta.napiVersion = arrify(meta.napiVersion);
|
|
}
|
|
|
|
if (meta.deprecated) {
|
|
// Treat deprecated like added for consistency.
|
|
meta.deprecated = arrify(meta.deprecated);
|
|
}
|
|
|
|
if (meta.removed) {
|
|
meta.removed = arrify(meta.removed);
|
|
}
|
|
|
|
meta.changes = meta.changes || [];
|
|
|
|
return meta;
|
|
}
|