mirror of
https://github.com/google/blockly.git
synced 2026-03-18 11:10:11 +01:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user