0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/tools/doc/common.js
Vse Mozhet Byt b88477ef4d tools: fix comment nits in tools/doc/*.js files
* Unify first letters case.
* Unify periods.
* Delete excess spaces.
* Add some blank lines as logical delimiters.
* Remove obvious comments.
* Combine short lines, rewrap lines more logically.
* Fix typos.
* "XXX" -> "TODO:", OSX -> macOS.

PR-URL: https://github.com/nodejs/node/pull/19696
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2018-03-30 16:07:48 +03:00

38 lines
836 B
JavaScript

'use strict';
const yaml = require('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.deprecated) {
// Treat deprecated like added for consistency.
meta.deprecated = arrify(meta.deprecated);
}
meta.changes = meta.changes || [];
return meta;
}
module.exports = { isYAMLBlock, extractAndParseYAML };