0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/tools/doc/common.js

43 lines
967 B
JavaScript
Raw Normal View History

'use strict';
const yaml =
require(`${__dirname}/../node_modules/eslint/node_modules/js-yaml`);
function isYAMLBlock(text) {
return /^<!-- YAML/.test(text);
}
function arrify(value) {
return Array.isArray(value) ? value : [value];
}
function extractAndParseYAML(text) {
text = text.trim()
.replace(/^<!-- YAML/, '')
.replace(/-->$/, '');
// js-yaml.safeLoad() throws on error.
const meta = yaml.safeLoad(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);
}
meta.changes = meta.changes || [];
return meta;
}
module.exports = { isYAMLBlock, extractAndParseYAML };