Use includes instead of indexOf

This commit is contained in:
Maximilian Krög
2022-08-05 00:36:16 +02:00
parent 5e34b9aa20
commit 0b945f2321
26 changed files with 50 additions and 57 deletions

View File

@@ -461,7 +461,7 @@ exports.publish = function (taffyData, opts, tutorials) {
data().each(function (doclet) { data().each(function (doclet) {
const url = helper.longnameToUrl[doclet.longname]; const url = helper.longnameToUrl[doclet.longname];
if (url.indexOf('#') > -1) { if (url.includes('#')) {
doclet.id = helper.longnameToUrl[doclet.longname].split(/#/).pop(); doclet.id = helper.longnameToUrl[doclet.longname].split(/#/).pop();
} else { } else {
doclet.id = doclet.name; doclet.id = doclet.name;

View File

@@ -79,7 +79,7 @@
<?js if (doc.kind == 'class') { <?js if (doc.kind == 'class') {
var subclasses = self.find(function() { var subclasses = self.find(function() {
return this.augments && this.augments.indexOf(doc.longname) > -1; return this.augments && this.augments.includes(doc.longname);
}) })
if (subclasses.length) { if (subclasses.length) {
?> ?>

View File

@@ -6,7 +6,7 @@
<p class="code-caption"><?js= example.caption ?></p> <p class="code-caption"><?js= example.caption ?></p>
<?js } ?> <?js } ?>
<?js if (example.code.toString().indexOf('<pre>') === -1) { ?> <?js if (!example.code.toString().includes('<pre>')) { ?>
<pre class="prettyprint"><code><?js= example.code ?></code></pre> <pre class="prettyprint"><code><?js= example.code ?></code></pre>
<?js } else { ?> <?js } else { ?>
<?js= example.code.replace(/<pre>/g, '<pre class="prettyprint">') ?> <?js= example.code.replace(/<pre>/g, '<pre class="prettyprint">') ?>

View File

@@ -23,7 +23,7 @@
var colspan = 2; var colspan = 2;
params.forEach(function(param) { params.forEach(function(param) {
if (!param) { return; } if (!param) { return; }
if (param.type && param.type.names && param.type.names.indexOf('undefined') !== -1) { if (param.type && param.type.names && param.type.names.includes('undefined')) {
param.optional = true; param.optional = true;
} }
if (param.name.indexOf('var_') == 0) { if (param.name.indexOf('var_') == 0) {
@@ -70,7 +70,7 @@
<?js if (!param.subparams) {?> <?js if (!param.subparams) {?>
<td class="type"> <td class="type">
<?js if (param.type && param.type.names) {?> <?js if (param.type && param.type.names) {?>
<?js= self.partial('type.tmpl', param.type.names) + (param.optional && typeof param.defaultvalue === 'undefined' && param.type.names.indexOf('undefined') === -1 ? ' | undefined' : '') ?> <?js= self.partial('type.tmpl', param.type.names) + (param.optional && typeof param.defaultvalue === 'undefined' && !param.type.names.includes('undefined') ? ' | undefined' : '') ?>
<?js if (typeof param.defaultvalue !== 'undefined') { ?> <?js if (typeof param.defaultvalue !== 'undefined') { ?>
(defaults to <?js= self.htmlsafe(param.defaultvalue) ?>) (defaults to <?js= self.htmlsafe(param.defaultvalue) ?>)
<?js } ?> <?js } ?>

View File

@@ -59,7 +59,7 @@ exports.publish = function (data, opts) {
if ( if (
constructor && constructor &&
constructor.substr(-1) === '_' && constructor.substr(-1) === '_' &&
constructor.indexOf('module:') === -1 !constructor.includes('module:')
) { ) {
assert.strictEqual( assert.strictEqual(
doc.inherited, doc.inherited,

View File

@@ -37,7 +37,7 @@ function includeAugments(doclet) {
if (doclet.fires && cls.fires) { if (doclet.fires && cls.fires) {
for (let i = 0, ii = cls.fires.length; i < ii; ++i) { for (let i = 0, ii = cls.fires.length; i < ii; ++i) {
const fires = cls.fires[i]; const fires = cls.fires[i];
if (doclet.fires.indexOf(fires) == -1) { if (!doclet.fires.includes(fires)) {
doclet.fires.push(fires); doclet.fires.push(fires);
} }
} }
@@ -58,7 +58,7 @@ function includeAugments(doclet) {
doclet.fires = []; doclet.fires = [];
} }
cls.fires.forEach(function (f) { cls.fires.forEach(function (f) {
if (doclet.fires.indexOf(f) == -1) { if (!doclet.fires.includes(f)) {
doclet.fires.push(f); doclet.fires.push(f);
} }
}); });
@@ -68,7 +68,7 @@ function includeAugments(doclet) {
doclet.observables = []; doclet.observables = [];
} }
cls.observables.forEach(function (f) { cls.observables.forEach(function (f) {
if (doclet.observables.indexOf(f) == -1) { if (!doclet.observables.includes(f)) {
doclet.observables.push(f); doclet.observables.push(f);
} }
}); });

View File

@@ -76,7 +76,7 @@ function shouldProcessString(tagName, text) {
let shouldProcess = true; let shouldProcess = true;
// we only want to process `@author` and `@see` tags that contain Markdown links // we only want to process `@author` and `@see` tags that contain Markdown links
if ((tagName === 'author' || tagName === 'see') && text.indexOf('[') === -1) { if ((tagName === 'author' || tagName === 'see') && !text.includes('[')) {
shouldProcess = false; shouldProcess = false;
} }

View File

@@ -42,14 +42,14 @@ exports.handlers = {
cls.observables = []; cls.observables = [];
} }
observable = observables[doclet.observable]; observable = observables[doclet.observable];
if (observable.type && cls.observables.indexOf(observable) == -1) { if (observable.type && !cls.observables.includes(observable)) {
cls.observables.push(observable); cls.observables.push(observable);
} }
if (!cls.fires) { if (!cls.fires) {
cls.fires = []; cls.fires = [];
} }
event = 'module:ol/Object.ObjectEvent#event:change:' + name; event = 'module:ol/Object.ObjectEvent#event:change:' + name;
if (cls.fires.indexOf(event) == -1) { if (!cls.fires.includes(event)) {
cls.fires.push(event); cls.fires.push(event);
} }
} }

View File

@@ -74,11 +74,11 @@ const exportOptions = {
useCORS: true, useCORS: true,
ignoreElements: function (element) { ignoreElements: function (element) {
const className = element.className || ''; const className = element.className || '';
return !( return (
className.indexOf('ol-control') === -1 || className.includes('ol-control') &&
className.indexOf('ol-scale') > -1 || !className.includes('ol-scale') &&
(className.indexOf('ol-attribution') > -1 && (!className.includes('ol-attribution') ||
className.indexOf('ol-uncollapsible') > -1) !className.includes('ol-uncollapsible'))
); );
}, },
}; };

View File

@@ -67,7 +67,7 @@ class Target extends Disposable {
} }
const listeners = this.listeners_ || (this.listeners_ = {}); const listeners = this.listeners_ || (this.listeners_ = {});
const listenersForType = listeners[type] || (listeners[type] = []); const listenersForType = listeners[type] || (listeners[type] = []);
if (listenersForType.indexOf(listener) === -1) { if (!listenersForType.includes(listener)) {
listenersForType.push(listener); listenersForType.push(listener);
} }
} }

View File

@@ -167,7 +167,7 @@ class GMLBase extends XMLFeature {
const child = /** @type {Element} */ (node.childNodes[i]); const child = /** @type {Element} */ (node.childNodes[i]);
if (child.nodeType === 1) { if (child.nodeType === 1) {
const ft = child.nodeName.split(':').pop(); const ft = child.nodeName.split(':').pop();
if (featureType.indexOf(ft) === -1) { if (!featureType.includes(ft)) {
let key = ''; let key = '';
let count = 0; let count = 0;
const uri = child.namespaceURI; const uri = child.namespaceURI;
@@ -206,10 +206,9 @@ class GMLBase extends XMLFeature {
/** @type {Object<string, import("../xml.js").Parser>} */ /** @type {Object<string, import("../xml.js").Parser>} */
const parsers = {}; const parsers = {};
for (let i = 0, ii = featureTypes.length; i < ii; ++i) { for (let i = 0, ii = featureTypes.length; i < ii; ++i) {
const featurePrefix = const featurePrefix = featureTypes[i].includes(':')
featureTypes[i].indexOf(':') === -1 ? featureTypes[i].split(':')[0]
? defaultPrefix : defaultPrefix;
: featureTypes[i].split(':')[0];
if (featurePrefix === p) { if (featurePrefix === p) {
parsers[featureTypes[i].split(':').pop()] = parsers[featureTypes[i].split(':').pop()] =
localName == 'featureMembers' localName == 'featureMembers'

View File

@@ -262,7 +262,7 @@ class MVT extends FeatureFormat {
const pbfLayers = pbf.readFields(layersPBFReader, {}); const pbfLayers = pbf.readFields(layersPBFReader, {});
const features = []; const features = [];
for (const name in pbfLayers) { for (const name in pbfLayers) {
if (layers && layers.indexOf(name) == -1) { if (layers && !layers.includes(name)) {
continue; continue;
} }
const pbfLayer = pbfLayers[name]; const pbfLayer = pbfLayers[name];

View File

@@ -110,7 +110,7 @@ class TopoJSON extends JSONFeature {
const property = this.layerName_; const property = this.layerName_;
let feature; let feature;
for (const objectName in topoJSONFeatures) { for (const objectName in topoJSONFeatures) {
if (this.layers_ && this.layers_.indexOf(objectName) == -1) { if (this.layers_ && !this.layers_.includes(objectName)) {
continue; continue;
} }
if (topoJSONFeatures[objectName].type === 'GeometryCollection') { if (topoJSONFeatures[objectName].type === 'GeometryCollection') {

View File

@@ -498,10 +498,10 @@ class WkbWriter {
*/ */
writeWkbHeader(wkbType, srid) { writeWkbHeader(wkbType, srid) {
wkbType %= 1000; // Assume 1000 is an upper limit for type ID wkbType %= 1000; // Assume 1000 is an upper limit for type ID
if (this.layout_.indexOf('Z') >= 0) { if (this.layout_.includes('Z')) {
wkbType += this.isEWKB_ ? 0x80000000 : 1000; wkbType += this.isEWKB_ ? 0x80000000 : 1000;
} }
if (this.layout_.indexOf('M') >= 0) { if (this.layout_.includes('M')) {
wkbType += this.isEWKB_ ? 0x40000000 : 2000; wkbType += this.isEWKB_ ? 0x40000000 : 2000;
} }
if (this.isEWKB_ && Number.isInteger(srid)) { if (this.isEWKB_ && Number.isInteger(srid)) {

View File

@@ -11,13 +11,13 @@ const ua =
* User agent string says we are dealing with Firefox as browser. * User agent string says we are dealing with Firefox as browser.
* @type {boolean} * @type {boolean}
*/ */
export const FIREFOX = ua.indexOf('firefox') !== -1; export const FIREFOX = ua.includes('firefox');
/** /**
* User agent string says we are dealing with Safari as browser. * User agent string says we are dealing with Safari as browser.
* @type {boolean} * @type {boolean}
*/ */
export const SAFARI = ua.indexOf('safari') !== -1 && ua.indexOf('chrom') == -1; export const SAFARI = ua.includes('safari') && !ua.includes('chrom');
/** /**
* https://bugs.webkit.org/show_bug.cgi?id=237906 * https://bugs.webkit.org/show_bug.cgi?id=237906
@@ -25,22 +25,20 @@ export const SAFARI = ua.indexOf('safari') !== -1 && ua.indexOf('chrom') == -1;
*/ */
export const SAFARI_BUG_237906 = export const SAFARI_BUG_237906 =
SAFARI && SAFARI &&
!!( (ua.includes('version/15.4') ||
ua.indexOf('version/15.4') >= 0 || !!ua.match(/cpu (os|iphone os) 15_4 like mac os x/));
ua.match(/cpu (os|iphone os) 15_4 like mac os x/)
);
/** /**
* User agent string says we are dealing with a WebKit engine. * User agent string says we are dealing with a WebKit engine.
* @type {boolean} * @type {boolean}
*/ */
export const WEBKIT = ua.indexOf('webkit') !== -1 && ua.indexOf('edge') == -1; export const WEBKIT = ua.includes('webkit') && !ua.includes('edge');
/** /**
* User agent string says we are dealing with a Mac as platform. * User agent string says we are dealing with a Mac as platform.
* @type {boolean} * @type {boolean}
*/ */
export const MAC = ua.indexOf('macintosh') !== -1; export const MAC = ua.includes('macintosh');
/** /**
* The ratio between physical pixels and device-independent pixels * The ratio between physical pixels and device-independent pixels

View File

@@ -455,7 +455,7 @@ class Modify extends PointerInteraction {
const segment = segments[i]; const segment = segments[i];
for (let s = 0, ss = segment.length; s < ss; ++s) { for (let s = 0, ss = segment.length; s < ss; ++s) {
const feature = segment[s].feature; const feature = segment[s].feature;
if (feature && features.indexOf(feature) === -1) { if (feature && !features.includes(feature)) {
this.featuresBeingModified_.push(feature); this.featuresBeingModified_.push(feature);
} }
} }
@@ -887,11 +887,11 @@ class Modify extends PointerInteraction {
const dragSegment = this.dragSegments_[i]; const dragSegment = this.dragSegments_[i];
const segmentData = dragSegment[0]; const segmentData = dragSegment[0];
const feature = segmentData.feature; const feature = segmentData.feature;
if (features.indexOf(feature) === -1) { if (!features.includes(feature)) {
features.push(feature); features.push(feature);
} }
const geometry = segmentData.geometry; const geometry = segmentData.geometry;
if (geometries.indexOf(geometry) === -1) { if (!geometries.includes(geometry)) {
geometries.push(geometry); geometries.push(geometry);
} }
const depth = segmentData.depth; const depth = segmentData.depth;

View File

@@ -24,7 +24,7 @@ export function jsonp(url, callback, opt_errback, opt_callbackParam) {
script.async = true; script.async = true;
script.src = script.src =
url + url +
(url.indexOf('?') == -1 ? '?' : '&') + (url.includes('?') ? '&' : '?') +
(opt_callbackParam || 'callback') + (opt_callbackParam || 'callback') +
'=' + '=' +
key; key;
@@ -131,7 +131,7 @@ export function getJSON(url) {
* @return {string} The full URL. * @return {string} The full URL.
*/ */
export function resolveUrl(base, url) { export function resolveUrl(base, url) {
if (url.indexOf('://') >= 0) { if (url.includes('://')) {
return url; return url;
} }
return new URL(url, base).href; return new URL(url, base).href;

View File

@@ -231,7 +231,7 @@ class ExecutorGroup {
if ( if (
!declutteredFeatures || !declutteredFeatures ||
(builderType !== 'Image' && builderType !== 'Text') || (builderType !== 'Image' && builderType !== 'Text') ||
declutteredFeatures.indexOf(feature) !== -1 declutteredFeatures.includes(feature)
) { ) {
const idx = (indexes[i] - 3) / 4; const idx = (indexes[i] - 3) / 4;
const x = hitTolerance - (idx % contextSize); const x = hitTolerance - (idx % contextSize);

View File

@@ -330,7 +330,7 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer {
} }
if ( if (
!this.newTiles_ && !this.newTiles_ &&
(inTransition || this.renderedTiles.indexOf(tile) === -1) (inTransition || !this.renderedTiles.includes(tile))
) { ) {
this.newTiles_ = true; this.newTiles_ = true;
} }

View File

@@ -195,11 +195,7 @@ class Zoomify extends TileImage {
}); });
let url = options.url; let url = options.url;
if ( if (url && !url.includes('{TileGroup}') && !url.includes('{tileIndex}')) {
url &&
url.indexOf('{TileGroup}') == -1 &&
url.indexOf('{tileIndex}') == -1
) {
url += '{TileGroup}/{z}-{x}-{y}.jpg'; url += '{TileGroup}/{z}-{x}-{y}.jpg';
} }
const urls = expandUrl(url); const urls = expandUrl(url);

View File

@@ -204,7 +204,7 @@ export function isTypeUnique(valueType) {
*/ */
export function numberToGlsl(v) { export function numberToGlsl(v) {
const s = v.toString(); const s = v.toString();
return s.indexOf('.') === -1 ? s + '.0' : s; return s.includes('.') ? s : s + '.0';
} }
/** /**
@@ -395,7 +395,7 @@ Operators['get'] = {
assertArgsCount(args, 1); assertArgsCount(args, 1);
assertString(args[0]); assertString(args[0]);
const value = args[0].toString(); const value = args[0].toString();
if (context.attributes.indexOf(value) === -1) { if (!context.attributes.includes(value)) {
context.attributes.push(value); context.attributes.push(value);
} }
const prefix = context.inFragmentShader ? 'v_' : 'a_'; const prefix = context.inFragmentShader ? 'v_' : 'a_';
@@ -420,7 +420,7 @@ Operators['var'] = {
assertArgsCount(args, 1); assertArgsCount(args, 1);
assertString(args[0]); assertString(args[0]);
const value = args[0].toString(); const value = args[0].toString();
if (context.variables.indexOf(value) === -1) { if (!context.variables.includes(value)) {
context.variables.push(value); context.variables.push(value);
} }
return uniformNameForVariable(value); return uniformNameForVariable(value);

View File

@@ -143,7 +143,7 @@ export function createFromCapabilitiesMatrixSet(
} }
// Fallback for tileMatrix identifiers that don't get prefixed // Fallback for tileMatrix identifiers that don't get prefixed
// by their tileMatrixSet identifiers. // by their tileMatrixSet identifiers.
if (elt[identifierPropName].indexOf(':') === -1) { if (!elt[identifierPropName].includes(':')) {
return ( return (
matrixSet[identifierPropName] + ':' + elt[identifierPropName] === matrixSet[identifierPropName] + ':' + elt[identifierPropName] ===
elt_ml[matrixIdsPropName] elt_ml[matrixIdsPropName]

View File

@@ -22,6 +22,6 @@ export function appendParams(uri, params) {
// remove any trailing ? or & // remove any trailing ? or &
uri = uri.replace(/[?&]$/, ''); uri = uri.replace(/[?&]$/, '');
// append ? or & depending on whether uri has existing parameters // append ? or & depending on whether uri has existing parameters
uri = uri.indexOf('?') === -1 ? uri + '?' : uri + '&'; uri += uri.includes('?') ? '&' : '?';
return uri + qs; return uri + qs;
} }

View File

@@ -562,7 +562,7 @@ export function parseLiteralStyle(style) {
// for each feature attribute used in the fragment shader, define a varying that will be used to pass data // for each feature attribute used in the fragment shader, define a varying that will be used to pass data
// from the vertex to the fragment shader, as well as an attribute in the vertex shader (if not already present) // from the vertex to the fragment shader, as well as an attribute in the vertex shader (if not already present)
fragContext.attributes.forEach(function (attrName) { fragContext.attributes.forEach(function (attrName) {
if (vertContext.attributes.indexOf(attrName) === -1) { if (!vertContext.attributes.includes(attrName)) {
vertContext.attributes.push(attrName); vertContext.attributes.push(attrName);
} }
builder.addVarying(`v_${attrName}`, 'float', `a_${attrName}`); builder.addVarying(`v_${attrName}`, 'float', `a_${attrName}`);

View File

@@ -30,7 +30,7 @@ function getImport(symbol, member) {
if ( if (
member && member &&
namedExport.length > 1 && namedExport.length > 1 &&
(defaultExport.length <= 1 || defaultExport[0].indexOf('.') !== -1) (defaultExport.length <= 1 || defaultExport[0].includes('.'))
) { ) {
const from = namedExport[0].replace(/^module\:/, './'); const from = namedExport[0].replace(/^module\:/, './');
const importName = from.replace(/[.\/]+/g, '_'); const importName = from.replace(/[.\/]+/g, '_');
@@ -52,7 +52,7 @@ function formatSymbolExport(symbol, namespaces, imports) {
const last = nsParts.length - 1; const last = nsParts.length - 1;
const imp = getImport(symbol, nsParts[last]); const imp = getImport(symbol, nsParts[last]);
if (imp) { if (imp) {
const isNamed = parts[0].indexOf('.') !== -1; const isNamed = parts[0].includes('.');
const importName = isNamed const importName = isNamed
? '_' + nsParts.slice(0, last).join('_') + '$' + nsParts[last] ? '_' + nsParts.slice(0, last).join('_') + '$' + nsParts[last]
: '$' + nsParts.join('$'); : '$' + nsParts.join('$');
@@ -79,7 +79,7 @@ function generateExports(symbols) {
const blocks = []; const blocks = [];
symbols.forEach(function (symbol) { symbols.forEach(function (symbol) {
const name = symbol.name; const name = symbol.name;
if (name.indexOf('#') == -1) { if (!name.includes('#')) {
const imp = getImport(symbol); const imp = getImport(symbol);
if (imp) { if (imp) {
imports[imp] = true; imports[imp] = true;

View File

@@ -966,7 +966,7 @@ describe('ol.interaction.Modify', function () {
const listeners = feature.listeners_['change']; const listeners = feature.listeners_['change'];
const candidates = Object.values(modify); const candidates = Object.values(modify);
return listeners.filter(function (listener) { return listeners.filter(function (listener) {
return candidates.indexOf(listener) !== -1; return candidates.includes(listener);
}); });
}; };
}); });