0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/tools/doc/common.mjs
Michaël Zasso de01f475d5
tools: update doctool dependencies, migrate to ESM
- 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>
2021-06-14 08:22:00 -07:00

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;
}