Skip to content

Commit

Permalink
Use startsWith and includes methods (pixijs#8418)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed Jun 21, 2022
1 parent aac23cd commit 9feac0e
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/accessibility/src/AccessibilityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export class AccessibilityManager
div.style.borderStyle = 'none';

// ARIA attributes ensure that button title and hint updates are announced properly
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
if (navigator.userAgent.toLowerCase().includes('chrome'))
{
// Chrome doesn't need aria-live to work as intended; in fact it just gets more confused.
div.setAttribute('aria-live', 'off');
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/batch/BatchShaderGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export class BatchShaderGenerator
this.programCache = {};
this.defaultGroupCache = {};

if (fragTemplate.indexOf('%count%') < 0)
if (!fragTemplate.includes('%count%'))
{
throw new Error('Fragment template must contain "%count%".');
}

if (fragTemplate.indexOf('%forloop%') < 0)
if (!fragTemplate.includes('%forloop%'))
{
throw new Error('Fragment template must contain "%forloop%".');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/geometry/Geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class Geometry

this.indexBuffer = buffer;

if (this.buffers.indexOf(buffer) === -1)
if (!this.buffers.includes(buffer))
{
this.buffers.push(buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shader/utils/getAttributeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getAttributeData(program: WebGLProgram, gl: WebGLRenderingContex
{
const attribData = gl.getActiveAttrib(program, i);

if (attribData.name.indexOf('gl_') === 0)
if (attribData.name.startsWith('gl_'))
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/textures/BaseTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ export class BaseTexture<R extends Resource = Resource, RO = IAutoDetectOptions>
{
if (id)
{
if (baseTexture.textureCacheIds.indexOf(id) === -1)
if (!baseTexture.textureCacheIds.includes(id))
{
baseTexture.textureCacheIds.push(id);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/textures/Texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export class Texture<R extends Resource = Resource> extends EventEmitter
{
if (id)
{
if (texture.textureCacheIds.indexOf(id) === -1)
if (!texture.textureCacheIds.includes(id))
{
texture.textureCacheIds.push(id);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/textures/resources/BaseImageResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class BaseImageResource extends Resource
*/
static crossOrigin(element: HTMLImageElement | HTMLVideoElement, url: string, crossorigin?: boolean | string): void
{
if (crossorigin === undefined && url.indexOf('data:') !== 0)
if (crossorigin === undefined && !url.startsWith('data:'))
{
element.crossOrigin = determineCrossOrigin(url);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/textures/resources/VideoResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export class VideoResource extends BaseImageResource
static test(source: unknown, extension?: string): source is HTMLVideoElement
{
return (globalThis.HTMLVideoElement && source instanceof HTMLVideoElement)
|| VideoResource.TYPES.indexOf(extension) > -1;
|| VideoResource.TYPES.includes(extension);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/loaders/src/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class Loader
let result;

// absolute url, just use it as is.
if (parsedUrl.protocol || !parsedUrl.path || url.indexOf('//') === 0)
if (parsedUrl.protocol || !parsedUrl.path || url.startsWith('//'))
{
result = url;
}
Expand All @@ -474,7 +474,7 @@ class Loader

result = result.slice(0, result.length - hash.length);

if (result.indexOf('?') !== -1)
if (result.includes('?'))
{
result += `&${this.defaultQueryString}`;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/loaders/src/LoaderResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function _noop(): void { /* empty */ }
*/
function setExtMap(map: Dict<any>, extname: string, val: number)
{
if (extname && extname.indexOf('.') === 0)
if (extname && extname.startsWith('.'))
{
extname = extname.substring(1);
}
Expand Down Expand Up @@ -330,7 +330,7 @@ class LoaderResource
this._flags = 0;

// set data url flag, needs to be set early for some _determineX checks to work.
this._setFlag(LoaderResource.STATUS_FLAGS.DATA_URL, url.indexOf('data:') === 0);
this._setFlag(LoaderResource.STATUS_FLAGS.DATA_URL, url.startsWith('data:'));

this.name = name;

Expand Down Expand Up @@ -1036,7 +1036,7 @@ class LoaderResource
_determineCrossOrigin(url: string, loc?: any): string
{
// data: and javascript: urls are considered same-origin
if (url.indexOf('data:') === 0)
if (url.startsWith('data:'))
{
return '';
}
Expand Down
4 changes: 2 additions & 2 deletions packages/loaders/src/middleware/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function parsing(resource: LoaderResource, next: (...args: any) => void):
const type = resource.xhr.getResponseHeader('content-type');

// this is an image, convert the binary string into a data url
if (type && type.indexOf('image') === 0)
if (type && type.startsWith('image'))
{
resource.data = new Image();
resource.data.src = `data:${type};base64,${encodeBinary(resource.xhr.responseText)}`;
Expand All @@ -50,7 +50,7 @@ export function parsing(resource: LoaderResource, next: (...args: any) => void):
}
}
// if content type says this is an image, then we should transform the blob into an Image object
else if (resource.data.type.indexOf('image') === 0)
else if (resource.data.type.startsWith('image'))
{
const Url = globalThis.URL || globalThis.webkitURL;
const src = Url.createObjectURL(resource.data);
Expand Down
14 changes: 7 additions & 7 deletions packages/prepare/src/BasePrepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function findMultipleBaseTextures(item: IDisplayObjectExtended, queue: Array<any
{
const baseTexture = item._textures[i].baseTexture;

if (queue.indexOf(baseTexture) === -1)
if (!queue.includes(baseTexture))
{
queue.push(baseTexture);
result = true;
Expand All @@ -72,7 +72,7 @@ function findBaseTexture(item: Texture, queue: Array<any>): boolean
{
const texture = item.baseTexture;

if (queue.indexOf(texture) === -1)
if (!queue.includes(texture))
{
queue.push(texture);
}
Expand All @@ -96,7 +96,7 @@ function findTexture(item: IDisplayObjectExtended, queue: Array<any>): boolean
{
const texture = item._texture.baseTexture;

if (queue.indexOf(texture) === -1)
if (!queue.includes(texture))
{
queue.push(texture);
}
Expand Down Expand Up @@ -160,19 +160,19 @@ function findText(item: IDisplayObjectExtended, queue: Array<any>): boolean
if (item instanceof Text)
{
// push the text style to prepare it - this can be really expensive
if (queue.indexOf(item.style) === -1)
if (!queue.includes(item.style))
{
queue.push(item.style);
}
// also push the text object so that we can render it (to canvas/texture) if needed
if (queue.indexOf(item) === -1)
if (!queue.includes(item))
{
queue.push(item);
}
// also push the Text's texture for upload to GPU
const texture = item._texture.baseTexture;

if (queue.indexOf(texture) === -1)
if (!queue.includes(texture))
{
queue.push(texture);
}
Expand All @@ -194,7 +194,7 @@ function findTextStyle(item: TextStyle, queue: Array<any>): boolean
{
if (item instanceof TextStyle)
{
if (queue.indexOf(item) === -1)
if (!queue.includes(item))
{
queue.push(item);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/runner/src/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class Runner
*/
public contains(item: unknown): boolean
{
return this.items.indexOf(item) !== -1;
return this.items.includes(item);
}

/** Remove all listeners from the Runner */
Expand Down
2 changes: 1 addition & 1 deletion packages/text-bitmap/src/BitmapText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export class BitmapText extends Container
// the updated text (if any), removed and return them to the pool.
for (let i = 0; i < activePagesMeshData.length; i++)
{
if (newPagesMeshData.indexOf(activePagesMeshData[i]) === -1)
if (!newPagesMeshData.includes(activePagesMeshData[i]))
{
this.removeChild(activePagesMeshData[i].mesh);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/text-bitmap/src/formats/TextFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class TextFormat
*/
static test(data: unknown): boolean
{
return typeof data === 'string' && data.indexOf('info face=') === 0;
return typeof data === 'string' && data.startsWith('info face=');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/text-bitmap/src/formats/XMLStringFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class XMLStringFormat
*/
static test(data: unknown): boolean
{
if (typeof data === 'string' && data.indexOf('<font>') > -1)
if (typeof data === 'string' && data.includes('<font>'))
{
const xml = new globalThis.DOMParser().parseFromString(data, 'text/xml');

Expand Down
4 changes: 2 additions & 2 deletions packages/text/src/TextMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ export class TextMetrics
return false;
}

return (TextMetrics._newlines.indexOf(char.charCodeAt(0)) >= 0);
return TextMetrics._newlines.includes(char.charCodeAt(0));
}

/**
Expand All @@ -477,7 +477,7 @@ export class TextMetrics
return false;
}

return (TextMetrics._breakingSpaces.indexOf(char.charCodeAt(0)) >= 0);
return TextMetrics._breakingSpaces.includes(char.charCodeAt(0));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/text/src/TextStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ export class TextStyle implements ITextStyle
let fontFamily = fontFamilies[i].trim();

// Check if font already contains strings
if (!(/([\"\'])[^\'\"]+\1/).test(fontFamily) && genericFontFamilies.indexOf(fontFamily) < 0)
if (!(/([\"\'])[^\'\"]+\1/).test(fontFamily) && !genericFontFamilies.includes(fontFamily))
{
fontFamily = `"${fontFamily}"`;
}
Expand All @@ -744,7 +744,7 @@ function getSingleColor(color: string|number): string
}
else if (typeof color === 'string')
{
if ( color.indexOf('0x') === 0 )
if ( color.startsWith('0x'))
{
color = color.replace('0x', '#');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/browser/hello.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function sayHello(type: string): void
return;
}

if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
if (navigator.userAgent.toLowerCase().includes('chrome'))
{
const args = [
`\n %c %c %c PixiJS ${VERSION} - ✰ ${type} ✰ %c %c http://www.pixijs.com/ %c %c ♥%c♥%c♥ \n\n`,
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/network/determineCrossOrigin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let tempAnchor: HTMLAnchorElement | undefined;
export function determineCrossOrigin(url: string, loc: Location = globalThis.location): string
{
// data: and javascript: urls are considered same-origin
if (url.indexOf('data:') === 0)
if (url.startsWith('data:'))
{
return '';
}
Expand Down

0 comments on commit 9feac0e

Please sign in to comment.