0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/tools/doc/common.js
Anna Henningsen 00ffa33564
tools: allow multiple added: version entries
Allow multiple `added:` version entries, since semver-minors
can trickle down to previous major versions, and thus
features may have been added in multiple versions.

Also include `deprecated:` entries and apply the same logic
to them for consistency.

Stylize the added HTML as `Added in:` and `Deprecated since:`.

PR-URL: https://github.com/nodejs/node/pull/6495
Reviewed-By: Robert Jefe Lindstaedt <robert.lindstaedt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-05-05 01:15:10 +02:00

41 lines
913 B
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 || 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 || meta.Deprecated;
if (deprecated) {
// Treat deprecated like added for consistency.
meta.deprecated = arrify(deprecated);
}
return meta;
}
exports.extractAndParseYAML = extractAndParseYAML;