Use String#startsWith instead of String#indexOf
This commit is contained in:
@@ -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(');
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user