chore: Use .includes and .startsWith, not .indexOf (#7936)

Easier to read than the diverse collection of `=== 0` and `!== -1` and `> -1` tests.
This commit is contained in:
Neil Fraser
2024-03-15 00:03:55 +01:00
committed by GitHub
parent 81e2203f7f
commit 0ecbcde9fc
42 changed files with 62 additions and 64 deletions

View File

@@ -225,9 +225,9 @@ function wrapScore(
score -= Math.pow(maxLength - lineLengths[i], 1.5);
// Optimize for structure.
// Add score to line endings after punctuation.
if ('.?!'.indexOf(linePunctuation[i]) !== -1) {
if ('.?!'.includes(linePunctuation[i])) {
score += limit / 3;
} else if (',;)]}'.indexOf(linePunctuation[i]) !== -1) {
} else if (',;)]}'.includes(linePunctuation[i])) {
score += limit / 4;
}
}

View File

@@ -62,7 +62,7 @@ export function getRelativeXY(element: Element): Coordinate {
// Then check for style = transform: translate(...) or translate3d(...)
const style = element.getAttribute('style');
if (style && style.indexOf('translate') > -1) {
if (style && style.includes('translate')) {
const styleComponents = style.match(XY_STYLE_REGEX);
if (styleComponents) {
xy.x += Number(styleComponents[1]);
@@ -90,7 +90,7 @@ export function getInjectionDivXY(element: Element): Coordinate {
x = x + xy.x;
y = y + xy.y;
const classes = element.getAttribute('class') || '';
if ((' ' + classes + ' ').indexOf(' injectionDiv ') !== -1) {
if ((' ' + classes + ' ').includes(' injectionDiv ')) {
break;
}
element = element.parentNode as Element;

View File

@@ -381,7 +381,7 @@ function addAttributes(node: Node, obj: AnyDuringMigration) {
// AnyDuringMigration because: Property 'attributes' does not exist on type
// 'Node'.
const attr = (node as AnyDuringMigration).attributes[j];
if (attr.nodeName.indexOf('css-') > -1) {
if (attr.nodeName.includes('css-')) {
obj['cssconfig'] = obj['cssconfig'] || {};
obj['cssconfig'][attr.nodeName.replace('css-', '')] = attr.value;
} else {

View File

@@ -37,7 +37,7 @@ let isMobile: boolean;
* @returns True if name is present.
*/
function has(name: string): boolean {
return rawUpper.indexOf(name.toUpperCase()) !== -1;
return rawUpper.includes(name.toUpperCase());
}
// Browsers. Logic from: