|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2019 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +'use strict'; |
| 20 | + |
| 21 | +( function () { // eslint-disable-line func-names, no-restricted-syntax |
| 22 | + /** |
| 23 | + * Removes extraneous information from a path. |
| 24 | + * |
| 25 | + * @private |
| 26 | + * @param {string} txt - text 1 |
| 27 | + * @returns {string} cleaned text |
| 28 | + */ |
| 29 | + function cleanPath( txt ) { |
| 30 | + var j; |
| 31 | + if ( |
| 32 | + txt.charCodeAt( 0 ) === 34 && // " |
| 33 | + txt.charCodeAt( txt.length-1 ) === 34 // " |
| 34 | + ) { |
| 35 | + txt = txt.slice( 1, txt.length-1 ); |
| 36 | + } |
| 37 | + j = txt.indexOf( '/docs/types/' ); |
| 38 | + if ( j >= 0 ) { |
| 39 | + txt = txt.slice( 0, j ); |
| 40 | + } |
| 41 | + return txt; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Cleans up link text. |
| 46 | + * |
| 47 | + * @private |
| 48 | + * @param {Array<DOMElement>} el - list of anchor elements to clean |
| 49 | + */ |
| 50 | + function cleanLinks( el ) { |
| 51 | + var i; |
| 52 | + for ( i = 0; i < el.length; i++ ) { |
| 53 | + el[ i ].innerHTML = cleanPath( el[ i ].innerHTML ); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Updates and removes extraneous information from a heading. |
| 59 | + * |
| 60 | + * @private |
| 61 | + * @param {string} txt - text |
| 62 | + * @returns {string} cleaned text |
| 63 | + */ |
| 64 | + function cleanHeading( txt ) { |
| 65 | + if ( txt.indexOf( 'External module' ) === 0 ) { |
| 66 | + txt = 'Package: ' + cleanPath( txt.slice( 16 ) ); |
| 67 | + } |
| 68 | + return txt; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Cleans up heading text. |
| 73 | + * |
| 74 | + * @private |
| 75 | + * @param {Array<DOMElement>} el - list of heading elements to clean |
| 76 | + */ |
| 77 | + function cleanHeadings( el ) { |
| 78 | + var i; |
| 79 | + for ( i = 0; i < el.length; i++ ) { |
| 80 | + el[ i ].innerHTML = cleanHeading( el[ i ].innerHTML ); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Updates a description. |
| 86 | + * |
| 87 | + * @private |
| 88 | + * @param {string} txt - description |
| 89 | + * @returns {string} updated description |
| 90 | + */ |
| 91 | + function updateDescription( txt ) { |
| 92 | + var ch; |
| 93 | + if ( txt.length === 0 ) { |
| 94 | + return txt; |
| 95 | + } |
| 96 | + ch = txt[ 0 ].toUpperCase(); |
| 97 | + if ( ch !== txt[ 0 ] ) { |
| 98 | + txt = ch + txt.slice( 1 ); |
| 99 | + } |
| 100 | + if ( txt.charCodeAt( txt.length-1 ) !== 46 ) { // . |
| 101 | + txt += '.'; |
| 102 | + } |
| 103 | + return txt; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Updates `@param` and `@returns` descriptions. |
| 108 | + * |
| 109 | + * @private |
| 110 | + * @param {Array<DOMElement>} el - list of elements containing descriptions |
| 111 | + */ |
| 112 | + function updateDescriptions( el ) { |
| 113 | + var i; |
| 114 | + for ( i = 0; i < el.length; i++ ) { |
| 115 | + el[ i ].innerHTML = updateDescription( el[ i ].innerHTML ); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Main execution sequence. |
| 121 | + * |
| 122 | + * @private |
| 123 | + */ |
| 124 | + function main() { |
| 125 | + var el; |
| 126 | + |
| 127 | + el = document.querySelectorAll( '.tsd-kind-external-module a' ); |
| 128 | + cleanLinks( el ); |
| 129 | + |
| 130 | + el = document.querySelectorAll( '.tsd-breadcrumb a' ); |
| 131 | + cleanLinks( el ); |
| 132 | + |
| 133 | + el = document.querySelectorAll( '.tsd-page-title h1' ); |
| 134 | + cleanHeadings( el ); |
| 135 | + |
| 136 | + el = document.querySelectorAll( '.tsd-description .tsd-parameters .tsd-comment p' ); |
| 137 | + updateDescriptions( el ); |
| 138 | + |
| 139 | + el = document.querySelectorAll( '.tsd-description .tsd-returns-title + p' ); |
| 140 | + updateDescriptions( el ); |
| 141 | + } |
| 142 | + |
| 143 | + main(); |
| 144 | +})(); |
0 commit comments