0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/tools/doc/common.js
Kyle Farnung 8476053c13 n-api: restrict exports by version
* Move `napi_get_uv_event_loop` into the `NAPI_VERSION >= 2` section
* Move `napi_open_callback_scope`, `napi_close_callback_scope`,
  `napi_fatal_exception`, `napi_add_env_cleanup_hook`, and
  `napi_remove_env_cleanup_hook` into the `NAPI_VERSION >= 3` section
* Added a missing `added` property to `napi_get_uv_event_loop` in the
  docs
* Added a `napiVersion` property to the docs and updated the parser and
  generator to use it.
* Added usage documentation

PR-URL: https://github.com/nodejs/node/pull/19962
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2018-07-05 10:19:27 -07:00

43 lines
967 B
JavaScript

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