Browse Source

doc: linkify type[] syntax, support lowercase for primitives

PR-URL: https://github.com/nodejs/node/pull/11167
Backport-PR-URL: https://github.com/nodejs/node/pull/13054
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
v6.x
Roman Reiss 8 years ago
committed by Myles Borins
parent
commit
b62cec8b02
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 27
      tools/doc/type-parser.js

27
tools/doc/type-parser.js

@ -5,12 +5,12 @@ const jsDocUrl = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
const jsPrimitiveUrl = 'https://developer.mozilla.org/en-US/docs/Web/' + const jsPrimitiveUrl = 'https://developer.mozilla.org/en-US/docs/Web/' +
'JavaScript/Data_structures'; 'JavaScript/Data_structures';
const jsPrimitives = { const jsPrimitives = {
'Integer': 'Number', // this is for extending 'integer': 'Number', // this is for extending
'Number': 'Number', 'number': 'Number',
'String': 'String', 'string': 'String',
'Boolean': 'Boolean', 'boolean': 'Boolean',
'Null': 'Null', 'null': 'Null',
'Symbol': 'Symbol' 'symbol': 'Symbol'
}; };
const jsGlobalTypes = [ const jsGlobalTypes = [
'Error', 'Object', 'Function', 'Array', 'TypedArray', 'Uint8Array', 'Error', 'Object', 'Function', 'Array', 'TypedArray', 'Uint8Array',
@ -49,7 +49,16 @@ module.exports = {
typeText = typeText.trim(); typeText = typeText.trim();
if (typeText) { if (typeText) {
let typeUrl = null; let typeUrl = null;
const primitive = jsPrimitives[typeText];
// To support type[], we store the full string and use
// the bracket-less version to lookup the type URL
const typeTextFull = typeText;
if (/\[]$/.test(typeText)) {
typeText = typeText.slice(0, -2);
}
const primitive = jsPrimitives[typeText.toLowerCase()];
if (primitive !== undefined) { if (primitive !== undefined) {
typeUrl = `${jsPrimitiveUrl}#${primitive}_type`; typeUrl = `${jsPrimitiveUrl}#${primitive}_type`;
} else if (jsGlobalTypes.indexOf(typeText) !== -1) { } else if (jsGlobalTypes.indexOf(typeText) !== -1) {
@ -60,9 +69,9 @@ module.exports = {
if (typeUrl) { if (typeUrl) {
typeLinks.push('<a href="' + typeUrl + '" class="type">&lt;' + typeLinks.push('<a href="' + typeUrl + '" class="type">&lt;' +
typeText + '&gt;</a>'); typeTextFull + '&gt;</a>');
} else { } else {
typeLinks.push('<span class="type">&lt;' + typeText + '&gt;</span>'); typeLinks.push('<span class="type">&lt;' + typeTextFull + '&gt;</span>');
} }
} }
}); });

Loading…
Cancel
Save