-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: parse types into links in doc html gen
Changes the parsing of parameter types in the doc html gen Links to either MDN or nodejs docs depending on type See #4350 PR-URL: #4741 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Chris Dickinson <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
- Loading branch information
1 parent
f2e4f62
commit 22c8d50
Showing
2 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
const nodeDocUrl = ''; | ||
const jsDocUrl = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/' + | ||
'Reference/Global_Objects/'; | ||
const jsPrimitiveUrl = 'https://developer.mozilla.org/en-US/docs/Web/' + | ||
'JavaScript/Data_structures'; | ||
const jsPrimitives = [ | ||
'Number', 'String', 'Boolean', 'Null', 'Symbol' | ||
] | ||
const jsGlobalTypes = [ | ||
'Error', 'Object', 'Function', 'Array', 'Uint8Array', | ||
'Uint16Array', 'Uint32Array', 'Int8Array', 'Int16Array', 'Int32Array', | ||
'Uint8ClampedArray', 'Float32Array', 'Float64Array', 'Date', 'RegExp', | ||
'ArrayBuffer', 'DataView', 'Promise' | ||
]; | ||
const typeMap = { | ||
'Buffer': 'buffer.html#buffer_class_buffer', | ||
'Handle': 'net.html#net_server_listen_handle_backlog_callback', | ||
'Stream': 'stream.html#stream_stream', | ||
'stream.Writable': 'stream.html#stream_class_stream_writable', | ||
'stream.Readable': 'stream.html#stream_class_stream_readable', | ||
'ChildProcess': 'child_process.html#child_process_class_childprocess', | ||
'cluster.Worker': 'cluster.html#cluster_class_worker', | ||
'dgram.Socket': 'dgram.html#dgram_class_dgram_socket', | ||
'net.Socket': 'net.html#net_class_net_socket', | ||
'EventEmitter': 'events.html#events_class_events_eventemitter', | ||
'Timer': 'timers.html#timers_timers' | ||
}; | ||
|
||
module.exports = { | ||
toLink: function (typeInput) { | ||
let typeLinks = []; | ||
typeInput = typeInput.replace('{', '').replace('}', ''); | ||
let typeTexts = typeInput.split('|'); | ||
|
||
typeTexts.forEach(function (typeText) { | ||
typeText = typeText.trim(); | ||
if (typeText) { | ||
let typeUrl = null; | ||
if (jsPrimitives.indexOf(typeText) !== -1) { | ||
typeUrl = jsPrimitiveUrl + '#' + typeText + '_type'; | ||
} else if (jsGlobalTypes.indexOf(typeText) !== -1) { | ||
typeUrl = jsDocUrl + typeText; | ||
} else if (typeMap[typeText]) { | ||
typeUrl = nodeDocUrl + typeMap[typeText]; | ||
} | ||
|
||
if (typeUrl) { | ||
typeLinks.push('<a href="' + typeUrl + '" class="type"><' + | ||
typeText + '></a>'); | ||
} else { | ||
typeLinks.push('<span class="type"><' + typeText + '></span>'); | ||
} | ||
} | ||
}); | ||
|
||
return typeLinks.length ? typeLinks.join(' | ') : typeInput; | ||
} | ||
} |