forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.js
More file actions
40 lines (29 loc) · 913 Bytes
/
Copy pathcommon.js
File metadata and controls
40 lines (29 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'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;