Skip to content

Commit

Permalink
feat: added isNull function, more secure checks
Browse files Browse the repository at this point in the history
build: changed canvas test package
matteobruni committed Nov 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f8fc83b commit 891e2a2
Showing 150 changed files with 409 additions and 249 deletions.
4 changes: 2 additions & 2 deletions engine/src/Options/Classes/AnimatableColor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray, isString } from "../../Utils/TypeUtils.js";
import { isArray, isNull, isString } from "../../Utils/TypeUtils.js";
import { HslAnimation } from "./HslAnimation.js";
import type { IAnimatableColor } from "../Interfaces/IAnimatableColor.js";
import type { IColorAnimation } from "../Interfaces/IColorAnimation.js";
@@ -42,7 +42,7 @@ export class AnimatableColor extends OptionsColor implements IAnimatableColor, I
load(data?: RecursivePartial<IAnimatableColor>): void {
super.load(data);

if (!data) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/AnimationOptions.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import type { IOptionLoader } from "../Interfaces/IOptionLoader.js";
import type { RangeValue } from "../../Types/RangeValue.js";
import type { RecursivePartial } from "../../Types/RecursivePartial.js";
import { StartValueType } from "../../Enums/Types/StartValueType.js";
import { isNull } from "../../Utils/TypeUtils.js";
import { setRangeValue } from "../../Utils/NumberUtils.js";

export class AnimationOptions implements IAnimation, IOptionLoader<IAnimation> {
@@ -69,7 +70,7 @@ export class RangedAnimationOptions extends AnimationOptions implements IOptionL
load(data?: RecursivePartial<IRangedAnimation>): void {
super.load(data);

if (!data) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/Background/Background.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import type { IBackground } from "../../Interfaces/Background/IBackground.js";
import type { IOptionLoader } from "../../Interfaces/IOptionLoader.js";
import { OptionsColor } from "../OptionsColor.js";
import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
import { isNull } from "../../../Utils/TypeUtils.js";

/**
* [[include:Options/Background.md]]
@@ -25,7 +26,7 @@ export class Background implements IBackground, IOptionLoader<IBackground> {
}

load(data?: RecursivePartial<IBackground>): void {
if (!data) {
if (isNull(data)) {
return;
}

4 changes: 2 additions & 2 deletions engine/src/Options/Classes/BackgroundMask/BackgroundMask.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { isNull, isString } from "../../../Utils/TypeUtils.js";
import { BackgroundMaskCover } from "./BackgroundMaskCover.js";
import type { IBackgroundMask } from "../../Interfaces/BackgroundMask/IBackgroundMask.js";
import type { IBackgroundMaskCover } from "../../Interfaces/BackgroundMask/IBackgroundMaskCover.js";
import type { IColor } from "../../../Core/Interfaces/Colors.js";
import type { IOptionLoader } from "../../Interfaces/IOptionLoader.js";
import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
import { isString } from "../../../Utils/TypeUtils.js";

/**
* [[include:Options/BackgroundMask.md]]
@@ -33,7 +33,7 @@ export class BackgroundMask implements IBackgroundMask, IOptionLoader<IBackgroun
}

load(data?: RecursivePartial<IBackgroundMask>): void {
if (!data) {
if (isNull(data)) {
return;
}

Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import type { IBackgroundMaskCover } from "../../Interfaces/BackgroundMask/IBack
import type { IOptionLoader } from "../../Interfaces/IOptionLoader.js";
import { OptionsColor } from "../OptionsColor.js";
import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
import { isNull } from "../../../Utils/TypeUtils.js";

/**
*/
@@ -15,7 +16,7 @@ export class BackgroundMaskCover implements IBackgroundMaskCover, IOptionLoader<
}

load(data?: RecursivePartial<IBackgroundMaskCover> | undefined): void {
if (!data) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/ColorAnimation.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import type { IColorAnimation } from "../Interfaces/IColorAnimation.js";
import type { IOptionLoader } from "../Interfaces/IOptionLoader.js";
import type { RangeValue } from "../../Types/RangeValue.js";
import type { RecursivePartial } from "../../Types/RecursivePartial.js";
import { isNull } from "../../Utils/TypeUtils.js";
import { setRangeValue } from "../../Utils/NumberUtils.js";

/**
@@ -20,7 +21,7 @@ export class ColorAnimation extends AnimationOptions implements IColorAnimation,
load(data?: RecursivePartial<IColorAnimation>): void {
super.load(data);

if (!data) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/FullScreen/FullScreen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IFullScreen } from "../../Interfaces/FullScreen/IFullScreen.js";
import type { IOptionLoader } from "../../Interfaces/IOptionLoader.js";
import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
import { isNull } from "../../../Utils/TypeUtils.js";

/**
* The options to set the particles in the background using CSS `fixed` position
@@ -28,7 +29,7 @@ export class FullScreen implements IFullScreen, IOptionLoader<IFullScreen> {
}

load(data?: RecursivePartial<IFullScreen>): void {
if (!data) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/HslAnimation.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import { ColorAnimation } from "./ColorAnimation.js";
import type { IHslAnimation } from "../Interfaces/IHslAnimation.js";
import type { IOptionLoader } from "../Interfaces/IOptionLoader.js";
import type { RecursivePartial } from "../../Types/RecursivePartial.js";
import { isNull } from "../../Utils/TypeUtils.js";

export class HslAnimation implements IHslAnimation, IOptionLoader<IHslAnimation> {
h;
@@ -15,7 +16,7 @@ export class HslAnimation implements IHslAnimation, IOptionLoader<IHslAnimation>
}

load(data?: RecursivePartial<IHslAnimation>): void {
if (!data) {
if (isNull(data)) {
return;
}

Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import type { IClickEvent } from "../../../Interfaces/Interactivity/Events/IClic
import type { IOptionLoader } from "../../../Interfaces/IOptionLoader.js";
import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
import type { SingleOrMultiple } from "../../../../Types/SingleOrMultiple.js";
import { isNull } from "../../../../Utils/TypeUtils.js";

/**
* [[include:Options/Interactivity/Click.md]]
@@ -23,7 +24,7 @@ export class ClickEvent implements IClickEvent, IOptionLoader<IClickEvent> {
}

load(data?: RecursivePartial<IClickEvent>): void {
if (!data) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/Interactivity/Events/DivEvent.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import type { IDivEvent } from "../../../Interfaces/Interactivity/Events/IDivEve
import type { IOptionLoader } from "../../../Interfaces/IOptionLoader.js";
import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
import type { SingleOrMultiple } from "../../../../Types/SingleOrMultiple.js";
import { isNull } from "../../../../Utils/TypeUtils.js";

/**
* [[include:Options/Interactivity/Div.md]]
@@ -30,7 +31,7 @@ export class DivEvent implements IDivEvent, IOptionLoader<IDivEvent> {
}

load(data?: RecursivePartial<IDivEvent>): void {
if (!data) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/Interactivity/Events/Events.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
import { ResizeEvent } from "./ResizeEvent.js";
import type { SingleOrMultiple } from "../../../../Types/SingleOrMultiple.js";
import { executeOnSingleOrMultiple } from "../../../../Utils/Utils.js";
import { isNull } from "../../../../Utils/TypeUtils.js";

/**
* [[include:Options/Interactivity/Events.md]]
@@ -25,7 +26,7 @@ export class Events implements IEvents, IOptionLoader<IEvents> {
}

load(data?: RecursivePartial<IEvents>): void {
if (!data) {
if (isNull(data)) {
return;
}

Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import type { IOptionLoader } from "../../../Interfaces/IOptionLoader.js";
import { Parallax } from "./Parallax.js";
import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
import type { SingleOrMultiple } from "../../../../Types/SingleOrMultiple.js";
import { isNull } from "../../../../Utils/TypeUtils.js";

/**
* [[include:Options/Interactivity/Hover.md]]
@@ -19,7 +20,7 @@ export class HoverEvent implements IHoverEvent, IOptionLoader<IHoverEvent> {
}

load(data?: RecursivePartial<IHoverEvent>): void {
if (!data) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/Interactivity/Events/Parallax.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IOptionLoader } from "../../../Interfaces/IOptionLoader.js";
import type { IParallax } from "../../../Interfaces/Interactivity/Events/IParallax.js";
import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
import { isNull } from "../../../../Utils/TypeUtils.js";

/**
*/
@@ -16,7 +17,7 @@ export class Parallax implements IParallax, IOptionLoader<IParallax> {
}

load(data?: RecursivePartial<IParallax>): void {
if (!data) {
if (isNull(data)) {
return;
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IOptionLoader } from "../../../Interfaces/IOptionLoader.js";
import type { IResizeEvent } from "../../../Interfaces/Interactivity/Events/IResizeEvent.js";
import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
import { isNull } from "../../../../Utils/TypeUtils.js";

export class ResizeEvent implements IResizeEvent, IOptionLoader<IResizeEvent> {
delay;
@@ -12,7 +13,7 @@ export class ResizeEvent implements IResizeEvent, IOptionLoader<IResizeEvent> {
}

load(data?: RecursivePartial<IResizeEvent>): void {
if (data === undefined) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/Interactivity/Interactivity.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import type { IOptionLoader } from "../../Interfaces/IOptionLoader.js";
import { InteractivityDetect } from "../../../Enums/InteractivityDetect.js";
import { Modes } from "./Modes/Modes.js";
import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
import { isNull } from "../../../Utils/TypeUtils.js";

/**
* [[include:Options/Interactivity.md]]
@@ -25,7 +26,7 @@ export class Interactivity implements IInteractivity, IOptionLoader<IInteractivi
}

load(data?: RecursivePartial<IInteractivity>): void {
if (!data) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/Interactivity/Modes/Modes.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import type { IExternalInteractor } from "../../../../Core/Interfaces/IExternalI
import type { IModes } from "../../../Interfaces/Interactivity/Modes/IModes.js";
import type { IOptionLoader } from "../../../Interfaces/IOptionLoader.js";
import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
import { isNull } from "../../../../Utils/TypeUtils.js";

/**
* [[include:Options/Interactivity/Modes.md]]
@@ -20,7 +21,7 @@ export class Modes implements IModes, IOptionLoader<IModes> {
}

load(data?: RecursivePartial<IModes>): void {
if (!data) {
if (isNull(data)) {
return;
}

3 changes: 2 additions & 1 deletion engine/src/Options/Classes/ManualParticle.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import type { IParticlesOptions } from "../Interfaces/Particles/IParticlesOption
import { PixelMode } from "../../Enums/Modes/PixelMode.js";
import type { RecursivePartial } from "../../Types/RecursivePartial.js";
import { deepExtend } from "../../Utils/Utils.js";
import { isNull } from "../../Utils/TypeUtils.js";

const defaultPosition = 50;

@@ -13,7 +14,7 @@ export class ManualParticle implements IManualParticle, IOptionLoader<IManualPar
position?: ICoordinatesWithMode;

load(data?: RecursivePartial<IManualParticle>): void {
if (!data) {
if (isNull(data)) {
return;
}

4 changes: 2 additions & 2 deletions engine/src/Options/Classes/Options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { deepExtend, executeOnSingleOrMultiple, safeMatchMedia } from "../../Utils/Utils.js";
import { isBoolean, isNull } from "../../Utils/TypeUtils.js";
import { Background } from "./Background/Background.js";
import { BackgroundMask } from "./BackgroundMask/BackgroundMask.js";
import type { Container } from "../../Core/Container.js";
@@ -16,7 +17,6 @@ import { ResponsiveMode } from "../../Enums/Modes/ResponsiveMode.js";
import type { SingleOrMultiple } from "../../Types/SingleOrMultiple.js";
import { Theme } from "./Theme/Theme.js";
import { ThemeMode } from "../../Enums/Modes/ThemeMode.js";
import { isBoolean } from "../../Utils/TypeUtils.js";
import { loadParticlesOptions } from "../../Utils/OptionsUtils.js";
import { setRangeValue } from "../../Utils/NumberUtils.js";

@@ -88,7 +88,7 @@ export class Options implements IOptions, IOptionLoader<IOptions> {
* @param data - the source data to load into the instance
*/
load(data?: ISourceOptions): void {
if (!data) {
if (isNull(data)) {
return;
}

8 changes: 5 additions & 3 deletions engine/src/Options/Classes/OptionsColor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IRangeHsl, IRangeHsv, IRangeRgb, IRangeValueColor } from "../../Core/Interfaces/Colors.js";
import { isArray, isString } from "../../Utils/TypeUtils.js";
import { isArray, isNull, isString } from "../../Utils/TypeUtils.js";
import type { IOptionLoader } from "../Interfaces/IOptionLoader.js";
import type { IOptionsColor } from "../Interfaces/IOptionsColor.js";
import type { RecursivePartial } from "../../Types/RecursivePartial.js";
@@ -35,10 +35,12 @@ export class OptionsColor implements IOptionsColor, IOptionLoader<IOptionsColor>
}

load(data?: RecursivePartial<IOptionsColor>): void {
if (data?.value === undefined) {
if (isNull(data)) {
return;
}

this.value = data.value;
if (!isNull(data.value)) {
this.value = data.value;
}
}
}
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import type { IOptionLoader } from "../../../Interfaces/IOptionLoader.js";
import type { IParticlesBounce } from "../../../Interfaces/Particles/Bounce/IParticlesBounce.js";
import { ParticlesBounceFactor } from "./ParticlesBounceFactor.js";
import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
import { isNull } from "../../../../Utils/TypeUtils.js";

export class ParticlesBounce implements IParticlesBounce, IOptionLoader<IParticlesBounce> {
readonly horizontal;
@@ -13,7 +14,7 @@ export class ParticlesBounce implements IParticlesBounce, IOptionLoader<IParticl
}

load(data?: RecursivePartial<IParticlesBounce>): void {
if (!data) {
if (isNull(data)) {
return;
}

4 changes: 2 additions & 2 deletions engine/src/Options/Classes/Particles/Collisions/Collisions.ts
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@ import type { IOptionLoader } from "../../../Interfaces/IOptionLoader.js";
import { ParticlesBounce } from "../Bounce/ParticlesBounce.js";
import type { RangeValue } from "../../../../Types/RangeValue.js";
import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
import { isNull } from "../../../../Utils/TypeUtils.js";
import { setRangeValue } from "../../../../Utils/NumberUtils.js";

/**
* [[include:Collisions.md]]
*/
export class Collisions implements ICollisions, IOptionLoader<ICollisions> {
@@ -30,7 +30,7 @@ export class Collisions implements ICollisions, IOptionLoader<ICollisions> {
}

load(data?: RecursivePartial<ICollisions>): void {
if (!data) {
if (isNull(data)) {
return;
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ICollisionsAbsorb } from "../../../Interfaces/Particles/Collisions/ICollisionsAbsorb.js";
import type { IOptionLoader } from "../../../Interfaces/IOptionLoader.js";
import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
import { isNull } from "../../../../Utils/TypeUtils.js";

export class CollisionsAbsorb implements ICollisionsAbsorb, IOptionLoader<ICollisionsAbsorb> {
speed;
@@ -10,7 +11,7 @@ export class CollisionsAbsorb implements ICollisionsAbsorb, IOptionLoader<IColli
}

load(data?: RecursivePartial<ICollisionsAbsorb>): void {
if (!data) {
if (isNull(data)) {
return;
}

Loading

0 comments on commit 891e2a2

Please sign in to comment.