Skip to content

Commit

Permalink
Code cleanup and style formatting (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenscordeirobr authored Jun 22, 2023
1 parent 90d4c5d commit bcb3113
Show file tree
Hide file tree
Showing 38 changed files with 164 additions and 166 deletions.
2 changes: 1 addition & 1 deletion src/defines/magick-define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IDefine } from './define';
import { MagickFormat } from '../magick-format';

export class MagickDefine implements IDefine {
constructor (format: MagickFormat, name: string, value: string) {
constructor(format: MagickFormat, name: string, value: string) {
this.format = format;
this.name = name;
this.value = value;
Expand Down
4 changes: 2 additions & 2 deletions src/formats/dng/dng-read-defines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { IDefine } from '../../defines/define';
import { MagickFormat } from '../../magick-format';

export class DngReadDefines extends DefinesCreator {
constructor () {
super(MagickFormat.Dng);
constructor() {
super(MagickFormat.Dng);
}

disableAutoBrightness?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/gravity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export enum Gravity {
/** @internal */
export function* _getEdges(gravities: Gravity[]): Generator<string> {
for (const gravity of gravities) {
switch(gravity) {
switch (gravity) {
case Gravity.North:
yield 'north'
break
Expand Down
4 changes: 2 additions & 2 deletions src/image-magick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class ImageMagick {
/** @internal */
async _initialize(wasmLocationOrData?: string | ByteArray): Promise<void> {
await this.loader(wasmLocationOrData);
}
}

/** @internal */
static get _api(): ImageMagickApi {
Expand Down Expand Up @@ -97,7 +97,7 @@ export class ImageMagick {
static read<TReturnType>(fileName: string, settings: MagickReadSettings, func: (image: IMagickImage) => Promise<TReturnType>): Promise<TReturnType>;
static read<TReturnType>(fileName: string, func: (image: IMagickImage) => TReturnType): TReturnType;
static read<TReturnType>(fileName: string, func: (image: IMagickImage) => Promise<TReturnType>): Promise<TReturnType>;
static read<TReturnType>(colorOrArrayOrFileName: MagickColor | ByteArray | string, widthOrFormatOrSetttingsOrFunc: number | MagickFormat | MagickReadSettings | ((image: IMagickImage) => TReturnType | Promise<TReturnType>) , heightOrFunc?: number | ((image: IMagickImage) => TReturnType | Promise<TReturnType>), func?: (image: IMagickImage) => TReturnType | Promise<TReturnType>): TReturnType | Promise<TReturnType> {
static read<TReturnType>(colorOrArrayOrFileName: MagickColor | ByteArray | string, widthOrFormatOrSetttingsOrFunc: number | MagickFormat | MagickReadSettings | ((image: IMagickImage) => TReturnType | Promise<TReturnType>), heightOrFunc?: number | ((image: IMagickImage) => TReturnType | Promise<TReturnType>), func?: (image: IMagickImage) => TReturnType | Promise<TReturnType>): TReturnType | Promise<TReturnType> {
return MagickImage._use(image => {
let callback = func;
if (colorOrArrayOrFileName instanceof MagickColor) {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/disposable-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export class DisposableArray<TReturnType> implements IDisposable {
this._bytes = ImageMagick._api.HEAPU8.subarray(pointer, pointer + length);
}

func(array : DisposableArray<TReturnType>): TReturnType | Promise<TReturnType> {
func(array: DisposableArray<TReturnType>): TReturnType | Promise<TReturnType> {
if (array._bytes === undefined)
return array._func(new Uint8Array());
else
return array._func(array._bytes);
return array._func(array._bytes);
}

dispose(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/disposable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Disposable {
}
} catch (error) {
instance.dispose();
throw(error);
throw (error);
}
}
}
3 changes: 1 addition & 2 deletions src/internal/exception/exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ export class Exception {
return error;

const relatedErrors: MagickError[] = [];
for (let i = 0; i < nestedCount; i++)
{
for (let i = 0; i < nestedCount; i++) {
const related = ImageMagick._api._MagickExceptionHelper_Related(exception, i);
const relatedSeverity = Exception.getErrorSeverity(related);
const relatedError = Exception.createError(related, relatedSeverity);
Expand Down
4 changes: 2 additions & 2 deletions src/internal/magick-rectangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class MagickRectangle {
let width = geometry.width;
let height = geometry.height;
if (geometry.isPercentage) {
width = new Percentage(geometry.width).multiply(image.width);
height = new Percentage(geometry.height).multiply(image.height);
width = new Percentage(geometry.width).multiply(image.width);
height = new Percentage(geometry.height).multiply(image.height);
}

ImageMagick._api._MagickRectangle_Width_Set(rectangle, width);
Expand Down
3 changes: 1 addition & 2 deletions src/log-event-types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

export enum LogEventTypes
{
export enum LogEventTypes {
None = 0x000000,
Accelerate = 0x00001,
Annotate = 0x00002,
Expand Down
2 changes: 1 addition & 1 deletion src/magick-geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class MagickGeometry {
} else {
const instance = ImageMagick._api._MagickGeometry_Create();
try {
_withString(widthOrValueOrX, valuePtr => {
_withString(widthOrValueOrX, valuePtr => {
const flags = ImageMagick._api._MagickGeometry_Initialize(instance, valuePtr);
if (flags === GeometryFlags.NoValue)
throw new MagickError('invalid geometry specified');
Expand Down
23 changes: 11 additions & 12 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export interface IMagickImage extends IDisposable {
colorFuzz: Percentage;
colormapSize: number;
colorSpace: ColorSpace;
colorType : ColorType;
colorType: ColorType;
comment: string | null;
compose: CompositeOperator;
readonly compression: CompressionMethod;
Expand Down Expand Up @@ -500,7 +500,7 @@ export class MagickImage extends NativeInstance implements IMagickImage {

get interlace(): Interlace { return ImageMagick._api._MagickImage_Interlace_Get(this._instance); }

get interpolate(): PixelInterpolateMethod { return ImageMagick._api._MagickImage_Interpolate_Get(this._instance);}
get interpolate(): PixelInterpolateMethod { return ImageMagick._api._MagickImage_Interpolate_Get(this._instance); }
set interpolate(value: PixelInterpolateMethod) { ImageMagick._api._MagickImage_Interpolate_Set(this._instance, value); }

get label(): string | null {
Expand Down Expand Up @@ -619,7 +619,7 @@ export class MagickImage extends NativeInstance implements IMagickImage {
const channels = this.valueOrDefault(channelsOrUndefined, Channels.Undefined);

Exception.use(exception => {
ImageMagick._api._MagickImage_BrightnessContrast(this._instance, brightness.toDouble(), contrast.toDouble(), channels, exception.ptr);
ImageMagick._api._MagickImage_BrightnessContrast(this._instance, brightness.toDouble(), contrast.toDouble(), channels, exception.ptr);
});
}

Expand All @@ -634,7 +634,7 @@ export class MagickImage extends NativeInstance implements IMagickImage {
charcoal(radius: number, sigma: number): void;
charcoal(radiusOrUndefined?: number, sigmaOrUndefined?: number): void {
const radius = radiusOrUndefined === undefined ? 0 : radiusOrUndefined;
const sigma =sigmaOrUndefined === undefined ? 1 :sigmaOrUndefined;
const sigma = sigmaOrUndefined === undefined ? 1 : sigmaOrUndefined;
Exception.use(exception => {
const instance = ImageMagick._api._MagickImage_Charcoal(this._instance, radius, sigma, exception.ptr);
this._setInstance(instance, exception);
Expand Down Expand Up @@ -688,7 +688,7 @@ export class MagickImage extends NativeInstance implements IMagickImage {
composite(image: IMagickImage, compose: CompositeOperator, point: Point, channels: Channels): void;
composite(image: IMagickImage, compose: CompositeOperator, point: Point, args: string): void;
composite(image: IMagickImage, compose: CompositeOperator, point: Point, args: string, channels: Channels): void;
composite(image: IMagickImage, composeOrPoint?: CompositeOperator | Point, pointOrArgsOrChannels?: Point | string | Channels, channelsOrArgs?: Channels | string, channelsOrUndefined?: Channels): void {
composite(image: IMagickImage, composeOrPoint?: CompositeOperator | Point, pointOrArgsOrChannels?: Point | string | Channels, channelsOrArgs?: Channels | string, channelsOrUndefined?: Channels): void {
let x = 0;
let y = 0;
let compose = CompositeOperator.In;
Expand Down Expand Up @@ -741,7 +741,7 @@ export class MagickImage extends NativeInstance implements IMagickImage {
compositeGravity(image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, channels: Channels): void;
compositeGravity(image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, args: string): void;
compositeGravity(image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, args: string, channels: Channels): void;
compositeGravity(image: IMagickImage, gravity: Gravity, composeOrPoint?: CompositeOperator | Point, pointOrArgsOrChannels?: Point | string | Channels, channelsOrArgs?: Channels | string, channelsOrUndefined?: Channels): void {
compositeGravity(image: IMagickImage, gravity: Gravity, composeOrPoint?: CompositeOperator | Point, pointOrArgsOrChannels?: Point | string | Channels, channelsOrArgs?: Channels | string, channelsOrUndefined?: Channels): void {
let x = 0;
let y = 0;
let compose = CompositeOperator.In;
Expand Down Expand Up @@ -833,8 +833,7 @@ export class MagickImage extends NativeInstance implements IMagickImage {
});
}

cropToTiles(geometry: MagickGeometry): IMagickImageCollection
{
cropToTiles(geometry: MagickGeometry): IMagickImageCollection {
return Exception.use(exception => {
return _withString(geometry.toString(), geometryPtr => {
const images = ImageMagick._api._MagickImage_CropToTiles(this._instance, geometryPtr, exception.ptr);
Expand Down Expand Up @@ -1236,7 +1235,7 @@ export class MagickImage extends NativeInstance implements IMagickImage {
});
}

separate<TReturnType>(func: (images: IMagickImageCollection) => TReturnType ): TReturnType;
separate<TReturnType>(func: (images: IMagickImageCollection) => TReturnType): TReturnType;
separate<TReturnType>(func: (images: IMagickImageCollection) => Promise<TReturnType>): Promise<TReturnType>;
separate<TReturnType>(func: (images: IMagickImageCollection) => TReturnType, channels: Channels): TReturnType;
separate<TReturnType>(func: (images: IMagickImageCollection) => Promise<TReturnType>, channels: Channels): Promise<TReturnType>;
Expand Down Expand Up @@ -1334,7 +1333,7 @@ export class MagickImage extends NativeInstance implements IMagickImage {
Exception.use(exception => {
const instance = ImageMagick._api._MagickImage_Splice(this._instance, geometryPtr, exception.ptr);
this._setInstance(instance, exception);
});
});
});
}

Expand All @@ -1344,7 +1343,7 @@ export class MagickImage extends NativeInstance implements IMagickImage {
const channels = this.valueOrDefault(channelsOrUndefined, Channels.Default);
return Exception.usePointer(exception => {
const list = ImageMagick._api._MagickImage_Statistics(this._instance, channels, exception);
const statistics = Statistics._create(this, list, channels);
const statistics = Statistics._create(this, list, channels);
ImageMagick._api._Statistics_DisposeList(list);
return statistics;
});
Expand Down Expand Up @@ -1564,7 +1563,7 @@ export class MagickImage extends NativeInstance implements IMagickImage {

private readOrPing(ping: boolean, fileNameOrArrayOrColor: string | ByteArray | MagickColor, settingsOrWidthOrUndefined?: MagickReadSettings | number, heightOrUndefined?: number): void {
Exception.use(exception => {
const readSettings = settingsOrWidthOrUndefined instanceof MagickReadSettings ? settingsOrWidthOrUndefined : new MagickReadSettings(this._settings);
const readSettings = settingsOrWidthOrUndefined instanceof MagickReadSettings ? settingsOrWidthOrUndefined : new MagickReadSettings(this._settings);
readSettings._ping = ping;
this._settings._ping = ping;

Expand Down
4 changes: 2 additions & 2 deletions src/magick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Magick {
}

const eventTypeString = Magick.getEventTypeString(eventTypes);
_withString(eventTypeString, instance => ImageMagick._api._Magick_SetLogEvents(instance));
_withString(eventTypeString, instance => ImageMagick._api._Magick_SetLogEvents(instance));
}

/** @internal */
Expand Down Expand Up @@ -89,7 +89,7 @@ export class Magick {
case LogEventTypes.Wand: return 'Wand';
case LogEventTypes.None:
default:
return 'None';
return 'None';
}
}
}
3 changes: 1 addition & 2 deletions src/pixel-intensity-method.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

export enum PixelIntensityMethod
{
export enum PixelIntensityMethod {
Undefined,
Average,
Brightness,
Expand Down
2 changes: 1 addition & 1 deletion src/pixels/pixel-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class PixelCollection extends NativeInstance implements IPixelCollection
static _use<TReturnType>(image: IMagickImage, func: (pixels: IPixelCollection) => TReturnType): TReturnType;
/** @internal */
static _use<TReturnType>(image: IMagickImage, func: (pixels: IPixelCollection) => Promise<TReturnType>): Promise<TReturnType>;
static _use<TReturnType>(image: IMagickImage, func: (pixels: IPixelCollection) => TReturnType | Promise<TReturnType>): TReturnType | Promise<TReturnType>{
static _use<TReturnType>(image: IMagickImage, func: (pixels: IPixelCollection) => TReturnType | Promise<TReturnType>): TReturnType | Promise<TReturnType> {
const pixels = new PixelCollection(image);
return Disposable._disposeAfterExecution(pixels, func);
}
Expand Down
6 changes: 3 additions & 3 deletions src/primary-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import { ImageMagick } from "./image-magick";

export class PrimaryInfo {
private _x : number;
private _y : number;
private _z : number;
private _x: number;
private _y: number;
private _z: number;

constructor(x: number, y: number, z: number) {
this._x = x;
Expand Down
6 changes: 3 additions & 3 deletions src/settings/magick-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export class MagickSettings {
return this._options[nameOrFormat] ?? null;
}

setDefine(name: string, value: string ): void;
setDefine(format: MagickFormat, name: string, value: string ): void;
setDefine(name: string, value: string): void;
setDefine(format: MagickFormat, name: string, value: string): void;
setDefine(format: MagickFormat, name: string, value: number): void;
setDefine(format: MagickFormat, name: string, value: boolean): void;
setDefine(nameOrFormat: MagickFormat | string, nameOrValue: string, value?: string | number | boolean): void {
Expand Down Expand Up @@ -98,7 +98,7 @@ export class MagickSettings {
const clone = new MagickSettings();
Object.assign(clone, this);
return clone;
}
}

/** @internal */
_use<TReturnType>(func: (settings: NativeMagickSettings) => TReturnType): TReturnType {
Expand Down
10 changes: 5 additions & 5 deletions src/settings/montage-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { MagickGeometry } from '../magick-geometry';
import { NativeMontageSettings } from './native-montage-settings';

export class MontageSettings {
backgroundColor? : MagickColor;
backgroundColor?: MagickColor;

borderColor? : MagickColor;
borderColor?: MagickColor;

borderWidth?: number;

fillColor? : MagickColor;
fillColor?: MagickColor;

font?: string;

Expand All @@ -30,15 +30,15 @@ export class MontageSettings {

shadow?: boolean;

strokeColor? : MagickColor;
strokeColor?: MagickColor;

textureFileName?: string;

tileGeometry?: MagickGeometry;

title?: string;

transparentColor? : MagickColor;
transparentColor?: MagickColor;

/** @internal */
_use<TReturnType>(func: (settings: NativeMontageSettings) => TReturnType): TReturnType
Expand Down
4 changes: 2 additions & 2 deletions src/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Statistics implements IStatistics {

image.channels.forEach(channel => {
if (((<number>channels >> <number>channel) & 0x01) != 0)
instance.addChannel(list, channel);
instance.addChannel(list, channel);
});

instance.addChannel(list, PixelChannel.Composite);
Expand All @@ -51,7 +51,7 @@ export class Statistics implements IStatistics {
private addChannel(list: number, channel: PixelChannel) {
const instance = ImageMagick._api._Statistics_GetInstance(list, channel);
if (instance !== 0) {
this._channels[channel] = new ChannelStatistics(channel, instance);
this._channels[channel] = new ChannelStatistics(channel, instance);
}
}
}
4 changes: 2 additions & 2 deletions tests/defines/defines-creator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { MagickFormat } from '../../src/magick-format';
import { MagickReadSettings } from '../../src/settings/magick-read-settings';

class TestDefinesCreator extends DefinesCreator {
constructor () {
constructor() {
super(MagickFormat.A);
}

getDefines (): IDefine[] {
getDefines(): IDefine[] {
return [this.createDefine('test', 'empty')];
}
}
Expand Down
4 changes: 3 additions & 1 deletion tests/image-magick/read-collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ describe('ImageMagick#readCollection', () => {
await ImageMagick.readCollection(TestImages.roseSparkleGif.data, settings, async () => {
await bogusAsyncMethod();
});
}).rejects.toThrowError('ImproperImageHeader');
})
.rejects
.toThrowError('ImproperImageHeader');
});

it('should read image from array with settings', () => {
Expand Down
8 changes: 4 additions & 4 deletions tests/image-magick/read-from-canvas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ describe('ImageMagick#readFromCanvas', () => {
canvas.width = 1;
canvas.height = 2;

window.HTMLCanvasElement.prototype.getContext = vi.fn(function(contextId: string) {
window.HTMLCanvasElement.prototype.getContext = vi.fn(function (contextId: string) {
expect(contextId).toBe('2d');
return {
getImageData: function(x: number, y: number, width: number, height: number) {
getImageData: function (x: number, y: number, width: number, height: number) {
expect(x).toBe(0);
expect(y).toBe(0);
expect(width).toBe(canvas.width);
Expand Down Expand Up @@ -47,10 +47,10 @@ describe('ImageMagick#readFromCanvas', () => {
canvas.width = 1;
canvas.height = 2;

window.HTMLCanvasElement.prototype.getContext = vi.fn(function(contextId: string) {
window.HTMLCanvasElement.prototype.getContext = vi.fn(function (contextId: string) {
expect(contextId).toBe('2d');
return {
getImageData: function(x: number, y: number, width: number, height: number) {
getImageData: function (x: number, y: number, width: number, height: number) {
expect(x).toBe(0);
expect(y).toBe(0);
expect(width).toBe(canvas.width);
Expand Down
2 changes: 1 addition & 1 deletion tests/magick-color/to-string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('MagickColor#toString', () => {
});

it('should return cmyka color for cmyk color', () => {
const color = new MagickColor(10, 20, 30,40, 50);
const color = new MagickColor(10, 20, 30, 40, 50);

expect(color.toString()).toBe('cmyka(10,20,30,40,0.1961)');
});
Expand Down
Loading

0 comments on commit bcb3113

Please sign in to comment.