Use String#startsWith instead of String#indexOf

This commit is contained in:
Maximilian Krög
2022-08-04 23:59:17 +02:00
parent 0b945f2321
commit bb3c5bf144
14 changed files with 51 additions and 53 deletions

View File

@@ -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>

View File

@@ -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) {

View File

@@ -5,7 +5,7 @@
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);
@@ -26,7 +26,7 @@
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;
}

View File

@@ -5,7 +5,7 @@
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);

View File

@@ -10,7 +10,7 @@ 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 || [];

View File

@@ -34,7 +34,7 @@ exports.publish = function (data, opts) {
return (
this.meta &&
this.meta.path &&
this.longname.indexOf('<anonymous>') !== 0 &&
!this.longname.startsWith('<anonymous>') &&
this.longname !== 'module:ol'
);
},

View File

@@ -29,10 +29,10 @@ exports.handlers = {
observable.name = name;
observable.readonly =
typeof observable.readonly == 'boolean' ? observable.readonly : true;
if (doclet.name.indexOf('get') === 0) {
if (doclet.name.startsWith('get')) {
observable.type = doclet.returns[0].type;
observable.description = doclet.returns[0].description;
} else if (doclet.name.indexOf('set') === 0) {
} else if (doclet.name.startsWith('set')) {
observable.readonly = false;
}
if (doclet.stability) {

View File

@@ -27,7 +27,7 @@ function getKMLImage(href) {
let url = href;
let path = window.location.href;
path = path.slice(0, path.lastIndexOf('/') + 1);
if (href.indexOf(path) === 0) {
if (href.startsWith(path)) {
const regexp = new RegExp(href.replace(path, '') + '$', 'i');
const kmlFile = zip.file(regexp)[0];
if (kmlFile) {

View File

@@ -86,7 +86,7 @@ map.on(['click', 'pointermove'], function (event) {
}
const fid = feature.getId();
if (selectElement.value.indexOf('singleselect') === 0) {
if (selectElement.value.startsWith('singleselect')) {
selection = {};
}
// add selected feature to lookup

View File

@@ -168,11 +168,11 @@ function fromStringInternal_(s) {
}
}
color = [r, g, b, a / 255];
} else if (s.indexOf('rgba(') == 0) {
} else if (s.startsWith('rgba(')) {
// rgba()
color = s.slice(5, -1).split(',').map(Number);
normalize(color);
} else if (s.indexOf('rgb(') == 0) {
} else if (s.startsWith('rgb(')) {
// rgb()
color = s.slice(4, -1).split(',').map(Number);
color.push(1);
@@ -225,7 +225,5 @@ export function isStringColor(s) {
if (NAMED_COLOR_RE_.test(s)) {
s = fromNamed(s);
}
return (
HEX_COLOR_RE_.test(s) || s.indexOf('rgba(') === 0 || s.indexOf('rgb(') === 0
);
return HEX_COLOR_RE_.test(s) || s.startsWith('rgba(') || s.startsWith('rgb(');
}

View File

@@ -822,7 +822,7 @@ function getTypeName(featurePrefix, featureType) {
featurePrefix = featurePrefix ? featurePrefix : FEATURE_PREFIX;
const prefix = featurePrefix + ':';
// The featureType already contains the prefix.
if (featureType.indexOf(prefix) === 0) {
if (featureType.startsWith(prefix)) {
return featureType;
} else {
return prefix + featureType;

View File

@@ -864,7 +864,7 @@ class WKB extends FeatureFormat {
options.dataProjection && getProjection(options.dataProjection);
if (dataProjection) {
const code = dataProjection.getCode();
if (code.indexOf('EPSG:') === 0) {
if (code.startsWith('EPSG:')) {
srid = Number(code.substring(5));
}
}

View File

@@ -114,7 +114,7 @@ export function getMapTileUrlTemplate(links, mediaType) {
}
if (knownMapMediaTypes[link.type]) {
fallbackUrlTemplate = link.href;
} else if (!fallbackUrlTemplate && link.type.indexOf('image/') === 0) {
} else if (!fallbackUrlTemplate && link.type.startsWith('image/')) {
fallbackUrlTemplate = link.href;
}
}

View File

@@ -5,7 +5,7 @@ import {fileURLToPath} from 'url';
import {spawn} from 'child_process';
import {walk} from 'walk';
const isWindows = process.platform.indexOf('win') === 0;
const isWindows = process.platform.startsWith('win');
const baseDir = dirname(fileURLToPath(import.meta.url));
const sourceDir = path.join(baseDir, '..', 'src');