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

22 lines
414 B
JavaScript
Raw Normal View History

'use strict';
const yaml = require('js-yaml');
function isYAMLBlock(text) {
return !!text.match(/^<!-- YAML/);
}
exports.isYAMLBlock = isYAMLBlock;
function extractAndParseYAML(text) {
text = text.trim();
text = text.replace(/^<!-- YAML/, '')
.replace(/-->$/, '');
// js-yaml.safeLoad() throws on error
return yaml.safeLoad(text);
}
exports.extractAndParseYAML = extractAndParseYAML;