From bb3c5bf14477365e793aefb40f57a19a49953e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Thu, 4 Aug 2022 23:59:17 +0200 Subject: [PATCH] Use String#startsWith instead of String#indexOf --- config/jsdoc/api/template/tmpl/members.tmpl | 2 +- .../jsdoc/api/template/tmpl/navigation.tmpl | 2 +- config/jsdoc/api/template/tmpl/params.tmpl | 28 +++++++------- .../jsdoc/api/template/tmpl/properties.tmpl | 38 +++++++++---------- config/jsdoc/api/template/tmpl/returns.tmpl | 8 ++-- config/jsdoc/info/publish.js | 2 +- config/jsdoc/plugins/observable.cjs | 4 +- examples/drag-and-drop-custom-kmz.js | 2 +- examples/vector-tile-selection.js | 2 +- src/ol/color.js | 8 ++-- src/ol/format/WFS.js | 2 +- src/ol/format/WKB.js | 2 +- src/ol/source/ogcTileUtil.js | 2 +- tasks/generate-info.js | 2 +- 14 files changed, 51 insertions(+), 53 deletions(-) diff --git a/config/jsdoc/api/template/tmpl/members.tmpl b/config/jsdoc/api/template/tmpl/members.tmpl index 243e1f22cd..19f224e3d5 100644 --- a/config/jsdoc/api/template/tmpl/members.tmpl +++ b/config/jsdoc/api/template/tmpl/members.tmpl @@ -14,7 +14,7 @@ if (data.type && data.type.names) {

- +

diff --git a/config/jsdoc/api/template/tmpl/navigation.tmpl b/config/jsdoc/api/template/tmpl/navigation.tmpl index 982bc186f6..d4666b9805 100644 --- a/config/jsdoc/api/template/tmpl/navigation.tmpl +++ b/config/jsdoc/api/template/tmpl/navigation.tmpl @@ -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) { diff --git a/config/jsdoc/api/template/tmpl/params.tmpl b/config/jsdoc/api/template/tmpl/params.tmpl index d00a53401b..c5529e932f 100644 --- a/config/jsdoc/api/template/tmpl/params.tmpl +++ b/config/jsdoc/api/template/tmpl/params.tmpl @@ -1,11 +1,11 @@ @@ -48,25 +48,25 @@ Name - + Type - + Description - + - + - + @@ -87,7 +87,7 @@ - + \ No newline at end of file diff --git a/config/jsdoc/api/template/tmpl/properties.tmpl b/config/jsdoc/api/template/tmpl/properties.tmpl index 97a3d23abd..c3b4ebeab1 100644 --- a/config/jsdoc/api/template/tmpl/properties.tmpl +++ b/config/jsdoc/api/template/tmpl/properties.tmpl @@ -1,11 +1,11 @@ Name - + Type - + Argument - + Default - + Description - + - + - + - + <optional>
- + <nullable>
- + @@ -96,12 +96,12 @@ - +
Properties
- + \ No newline at end of file diff --git a/config/jsdoc/api/template/tmpl/returns.tmpl b/config/jsdoc/api/template/tmpl/returns.tmpl index b83aa5797a..41a25b788b 100644 --- a/config/jsdoc/api/template/tmpl/returns.tmpl +++ b/config/jsdoc/api/template/tmpl/returns.tmpl @@ -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) { ?> | - diff --git a/config/jsdoc/info/publish.js b/config/jsdoc/info/publish.js index 9c469fed2e..5d1c015f1b 100644 --- a/config/jsdoc/info/publish.js +++ b/config/jsdoc/info/publish.js @@ -34,7 +34,7 @@ exports.publish = function (data, opts) { return ( this.meta && this.meta.path && - this.longname.indexOf('') !== 0 && + !this.longname.startsWith('') && this.longname !== 'module:ol' ); }, diff --git a/config/jsdoc/plugins/observable.cjs b/config/jsdoc/plugins/observable.cjs index b4da2ae2ef..14e7f38658 100644 --- a/config/jsdoc/plugins/observable.cjs +++ b/config/jsdoc/plugins/observable.cjs @@ -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) { diff --git a/examples/drag-and-drop-custom-kmz.js b/examples/drag-and-drop-custom-kmz.js index 81ad5d95b5..e24427a73e 100644 --- a/examples/drag-and-drop-custom-kmz.js +++ b/examples/drag-and-drop-custom-kmz.js @@ -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) { diff --git a/examples/vector-tile-selection.js b/examples/vector-tile-selection.js index 5dd228dcae..57325b7e4d 100644 --- a/examples/vector-tile-selection.js +++ b/examples/vector-tile-selection.js @@ -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 diff --git a/src/ol/color.js b/src/ol/color.js index 482ebb01a1..e47c5cebf4 100644 --- a/src/ol/color.js +++ b/src/ol/color.js @@ -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('); } diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index 88570faaf6..c1b1baf133 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -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; diff --git a/src/ol/format/WKB.js b/src/ol/format/WKB.js index e18a410fac..d757aa68c1 100644 --- a/src/ol/format/WKB.js +++ b/src/ol/format/WKB.js @@ -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)); } } diff --git a/src/ol/source/ogcTileUtil.js b/src/ol/source/ogcTileUtil.js index 2925218236..83e302cf06 100644 --- a/src/ol/source/ogcTileUtil.js +++ b/src/ol/source/ogcTileUtil.js @@ -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; } } diff --git a/tasks/generate-info.js b/tasks/generate-info.js index bcf89bedce..3c772ccfd0 100644 --- a/tasks/generate-info.js +++ b/tasks/generate-info.js @@ -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');