Use String#startsWith instead of String#indexOf
This commit is contained in:
@@ -14,7 +14,7 @@ if (data.type && data.type.names) {
|
||||
<div class="anchor" id="<?js= id ?>">
|
||||
</div>
|
||||
<h4 class="name">
|
||||
<?js= data.attribs + (data.scope === 'static' ? longname : name.indexOf('module:') === 0 ? name.split('/').pop() : name) + typeSignature ?>
|
||||
<?js= data.attribs + (data.scope === 'static' ? longname : name.startsWith('module:') ? name.split('/').pop() : name) + typeSignature ?>
|
||||
<?js= this.partial('stability.tmpl', data) ?>
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
var self = this;
|
||||
|
||||
function toShortName(name) {
|
||||
return name.indexOf('module:') === 0 ? name.split('/').pop() : name;
|
||||
return name.startsWith('module:') ? name.split('/').pop() : name;
|
||||
}
|
||||
|
||||
function getItemCssClass(type) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?js
|
||||
var params = obj;
|
||||
|
||||
|
||||
/* sort subparams under their parent params (like opts.classname) */
|
||||
var parentParam = null;
|
||||
params.forEach(function(param, i) {
|
||||
if (!param) { return; }
|
||||
if ( parentParam && param.name && param.name.indexOf(parentParam.name + '.') === 0 ) {
|
||||
if (parentParam && param.name && param.name.startsWith(parentParam.name + '.')) {
|
||||
param.name = param.name.substr(parentParam.name.length+1);
|
||||
parentParam.subparams = parentParam.subparams || [];
|
||||
parentParam.subparams.push(param);
|
||||
@@ -15,30 +15,30 @@
|
||||
parentParam = param;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/* determine if we need extra "attributes" column */
|
||||
params.hasAttributes = false;
|
||||
params.hasName = false;
|
||||
|
||||
|
||||
var colspan = 2;
|
||||
params.forEach(function(param) {
|
||||
if (!param) { return; }
|
||||
if (param.type && param.type.names && param.type.names.includes('undefined')) {
|
||||
param.optional = true;
|
||||
}
|
||||
if (param.name.indexOf('var_') == 0) {
|
||||
if (param.name.startsWith('var_')) {
|
||||
params.hasAttributes = true;
|
||||
param.variable = true;
|
||||
}
|
||||
|
||||
|
||||
if (param.optional || param.nullable) {
|
||||
params.hasAttributes = true;
|
||||
}
|
||||
|
||||
|
||||
if (param.name) {
|
||||
params.hasName = true;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
?>
|
||||
|
||||
@@ -48,25 +48,25 @@
|
||||
<?js if (params.hasName) {?>
|
||||
<th>Name</th>
|
||||
<?js } ?>
|
||||
|
||||
|
||||
<th>Type</th>
|
||||
|
||||
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
|
||||
<tbody>
|
||||
<?js
|
||||
var self = this;
|
||||
params.forEach(function(param) {
|
||||
if (!param) { return; }
|
||||
?>
|
||||
|
||||
|
||||
<tr class="<?js= (param.stability && param.stability !== 'stable') ? 'unstable' : '' ?>">
|
||||
<?js if (params.hasName) {?>
|
||||
<td class="name"><code><?js= param.name.replace(/^opt_/, "") ?></code></td>
|
||||
<?js } ?>
|
||||
|
||||
|
||||
<?js if (!param.subparams) {?>
|
||||
<td class="type">
|
||||
<?js if (param.type && param.type.names) {?>
|
||||
@@ -87,7 +87,7 @@
|
||||
<?js= self.partial('params.tmpl', param.subparams) ?>
|
||||
<?js } ?></td>
|
||||
</tr>
|
||||
|
||||
|
||||
<?js }); ?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -1,11 +1,11 @@
|
||||
<?js
|
||||
var props = obj;
|
||||
|
||||
|
||||
/* sort subprops under their parent props (like opts.classname) */
|
||||
var parentProp = null;
|
||||
props.forEach(function(prop, i) {
|
||||
if (!prop) { return; }
|
||||
if ( parentProp && prop.name && prop.name.indexOf(parentProp.name + '.') === 0 ) {
|
||||
if (parentProp && prop.name && prop.name.startsWith(parentProp.name + '.')) {
|
||||
prop.name = prop.name.substr(parentProp.name.length+1);
|
||||
parentProp.subprops = parentProp.subprops || [];
|
||||
parentProp.subprops.push(prop);
|
||||
@@ -15,23 +15,23 @@
|
||||
parentProp = prop;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/* determine if we need extra columns, "attributes" and "default" */
|
||||
props.hasAttributes = false;
|
||||
props.hasDefault = false;
|
||||
props.hasName = false;
|
||||
|
||||
|
||||
props.forEach(function(prop) {
|
||||
if (!prop) { return; }
|
||||
|
||||
|
||||
if (prop.optional || prop.nullable) {
|
||||
props.hasAttributes = true;
|
||||
}
|
||||
|
||||
|
||||
if (prop.name) {
|
||||
props.hasName = true;
|
||||
}
|
||||
|
||||
|
||||
if (typeof prop.defaultvalue !== 'undefined') {
|
||||
props.hasDefault = true;
|
||||
}
|
||||
@@ -44,51 +44,51 @@
|
||||
<?js if (props.hasName) {?>
|
||||
<th>Name</th>
|
||||
<?js } ?>
|
||||
|
||||
|
||||
<th>Type</th>
|
||||
|
||||
|
||||
<?js if (props.hasAttributes) {?>
|
||||
<th>Argument</th>
|
||||
<?js } ?>
|
||||
|
||||
|
||||
<?js if (props.hasDefault) {?>
|
||||
<th>Default</th>
|
||||
<?js } ?>
|
||||
|
||||
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
|
||||
<tbody>
|
||||
<?js
|
||||
var self = this;
|
||||
props.forEach(function(prop) {
|
||||
if (!prop) { return; }
|
||||
?>
|
||||
|
||||
|
||||
<tr>
|
||||
<?js if (props.hasName) {?>
|
||||
<td class="name"><code><?js= prop.name ?></code></td>
|
||||
<?js } ?>
|
||||
|
||||
|
||||
<td class="type">
|
||||
<?js if (prop.type && prop.type.names) {?>
|
||||
<?js= self.partial('type.tmpl', prop.type.names) ?>
|
||||
<?js } ?>
|
||||
</td>
|
||||
|
||||
|
||||
<?js if (props.hasAttributes) {?>
|
||||
<td class="attributes">
|
||||
<?js if (prop.optional) { ?>
|
||||
<optional><br>
|
||||
<?js } ?>
|
||||
|
||||
|
||||
<?js if (prop.nullable) { ?>
|
||||
<nullable><br>
|
||||
<?js } ?>
|
||||
</td>
|
||||
<?js } ?>
|
||||
|
||||
|
||||
<?js if (props.hasDefault) {?>
|
||||
<td class="default">
|
||||
<?js if (typeof prop.defaultvalue !== 'undefined') { ?>
|
||||
@@ -96,12 +96,12 @@
|
||||
<?js } ?>
|
||||
</td>
|
||||
<?js } ?>
|
||||
|
||||
|
||||
<td class="description last"><?js= prop.description ?><?js if (prop.subprops) { ?>
|
||||
<h6>Properties</h6><?js= self.partial('properties.tmpl', prop.subprops) ?>
|
||||
<?js } ?></td>
|
||||
</tr>
|
||||
|
||||
|
||||
<?js }); ?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -10,9 +10,9 @@ returns.forEach(function (ret, i) {
|
||||
var name = ret.name || ret.description;
|
||||
var startSpacePos = name.indexOf(" ");
|
||||
|
||||
if (parentReturn !== null && name.indexOf(parentReturn.name + '.') === 0) {
|
||||
if (parentReturn !== null && name.startsWith(parentReturn.name + '.')) {
|
||||
ret.name = isNamed ? name.substr(parentReturn.name.length + 1) : name.substr(parentReturn.name.length + 1, startSpacePos - (parentReturn.name.length + 1));
|
||||
|
||||
|
||||
parentReturn.subReturns = parentReturn.subReturns || [];
|
||||
parentReturn.subReturns.push(ret);
|
||||
returns[i] = null;
|
||||
@@ -20,7 +20,7 @@ returns.forEach(function (ret, i) {
|
||||
if (!isNamed) {
|
||||
ret.name = ret.description.substr(0, startSpacePos !== -1 ? startSpacePos : ret.description.length);
|
||||
}
|
||||
|
||||
|
||||
parentReturn = ret;
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ if (returns.length > 1) {
|
||||
ret.type.names.forEach(function(name, i) { ?>
|
||||
<?js= self.linkto(name, self.htmlsafe(name)) ?>
|
||||
<?js if (i < ret.type.names.length-1) { ?> | <?js } ?>
|
||||
<?js });
|
||||
<?js });
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user