mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 16:55:46 +00:00

PR-URL: https://github.com/nodejs/node/pull/19512 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const yaml = require('js-yaml');
|
|
|
|
function isYAMLBlock(text) {
|
|
return !!text.match(/^<!-- YAML/);
|
|
}
|
|
|
|
exports.isYAMLBlock = isYAMLBlock;
|
|
|
|
function arrify(value) {
|
|
return Array.isArray(value) ? value : [value];
|
|
}
|
|
|
|
function extractAndParseYAML(text) {
|
|
text = text.trim();
|
|
|
|
text = text.replace(/^<!-- YAML/, '')
|
|
.replace(/-->$/, '');
|
|
|
|
// js-yaml.safeLoad() throws on error
|
|
const meta = yaml.safeLoad(text);
|
|
|
|
const added = meta.added;
|
|
if (added) {
|
|
// Since semver-minors can trickle down to previous major versions,
|
|
// features may have been added in multiple versions.
|
|
meta.added = arrify(added);
|
|
}
|
|
|
|
const deprecated = meta.deprecated;
|
|
if (deprecated) {
|
|
// Treat deprecated like added for consistency.
|
|
meta.deprecated = arrify(deprecated);
|
|
}
|
|
|
|
meta.changes = meta.changes || [];
|
|
meta.changes.forEach((entry) => {
|
|
entry.description = entry.description.replace(/^\^\s*/, '');
|
|
});
|
|
|
|
return meta;
|
|
}
|
|
|
|
exports.extractAndParseYAML = extractAndParseYAML;
|