mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
doc: linkify type[] syntax, support lowercase for primitives
PR-URL: https://github.com/nodejs/node/pull/11167 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
1 file changed
+18
-9
@@ -4,12 +4,12 @@ const jsDocPrefix = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/';
|
||||
const jsDocUrl = jsDocPrefix + 'Reference/Global_Objects/';
|
||||
const jsPrimitiveUrl = jsDocPrefix + 'Data_structures';
|
||||
const jsPrimitives = {
|
||||
'Integer': 'Number', // this is for extending
|
||||
'Number': 'Number',
|
||||
'String': 'String',
|
||||
'Boolean': 'Boolean',
|
||||
'Null': 'Null',
|
||||
'Symbol': 'Symbol'
|
||||
'integer': 'Number', // this is for extending
|
||||
'number': 'Number',
|
||||
'string': 'String',
|
||||
'boolean': 'Boolean',
|
||||
'null': 'Null',
|
||||
'symbol': 'Symbol'
|
||||
};
|
||||
const jsGlobalTypes = [
|
||||
'Error', 'Object', 'Function', 'Array', 'TypedArray', 'Uint8Array',
|
||||
@@ -67,7 +67,16 @@ module.exports = {
|
||||
typeText = typeText.trim();
|
||||
if (typeText) {
|
||||
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) {
|
||||
typeUrl = `${jsPrimitiveUrl}#${primitive}_type`;
|
||||
} else if (jsGlobalTypes.indexOf(typeText) !== -1) {
|
||||
@@ -78,9 +87,9 @@ module.exports = {
|
||||
|
||||
if (typeUrl) {
|
||||
typeLinks.push('<a href="' + typeUrl + '" class="type"><' +
|
||||
typeText + '></a>');
|
||||
typeTextFull + '></a>');
|
||||
} else {
|
||||
typeLinks.push('<span class="type"><' + typeText + '></span>');
|
||||
typeLinks.push('<span class="type"><' + typeTextFull + '></span>');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user