From: Jérôme Benoit Date: Sat, 6 Jul 2024 20:51:36 +0000 (+0200) Subject: refactor: format code X-Git-Tag: v4.0.17~1^2~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9183b8807bdac35067a22362216d1deadc16421f;p=poolifier.git refactor: format code Signed-off-by: Jérôme Benoit --- diff --git a/jsr.json b/jsr.json index ac86155a..ff144fb6 100644 --- a/jsr.json +++ b/jsr.json @@ -4,11 +4,6 @@ "version": "4.0.16", "exports": "./src/index.ts", "publish": { - "include": [ - "LICENSE", - "README.md", - "jsr.json", - "src/**/*.ts" - ] + "include": ["LICENSE", "README.md", "jsr.json", "src/**/*.ts"] } } diff --git a/src/fixed-priority-queue.ts b/src/fixed-priority-queue.ts index 1597860e..74d43c4b 100644 --- a/src/fixed-priority-queue.ts +++ b/src/fixed-priority-queue.ts @@ -1,4 +1,8 @@ -import { defaultQueueSize, type FixedQueueNode, type IFixedQueue } from './utility-types.js' +import { + defaultQueueSize, + type FixedQueueNode, + type IFixedQueue, +} from './utility-types.js' /** * Fixed priority queue. diff --git a/src/fixed-queue.ts b/src/fixed-queue.ts index 4856b304..171cd578 100644 --- a/src/fixed-queue.ts +++ b/src/fixed-queue.ts @@ -1,4 +1,8 @@ -import { defaultQueueSize, type FixedQueueNode, type IFixedQueue } from './utility-types.js' +import { + defaultQueueSize, + type FixedQueueNode, + type IFixedQueue, +} from './utility-types.js' /** * Fixed queue. @@ -118,9 +122,7 @@ export class FixedQueue implements IFixedQueue { ) } if (size < 0) { - throw new RangeError( - `Invalid fixed queue size: ${size.toString()} < 0` - ) + throw new RangeError(`Invalid fixed queue size: ${size.toString()} < 0`) } } } diff --git a/src/priority-queue.ts b/src/priority-queue.ts index ac75fc06..1e15fe2d 100644 --- a/src/priority-queue.ts +++ b/src/priority-queue.ts @@ -2,7 +2,12 @@ import { FixedPriorityQueue } from './fixed-priority-queue.js' import { FixedQueue } from './fixed-queue.js' -import { defaultBucketSize, type FixedQueueNode, type IFixedQueue, type PriorityQueueNode } from './utility-types.js' +import { + defaultBucketSize, + type FixedQueueNode, + type IFixedQueue, + type PriorityQueueNode, +} from './utility-types.js' /** * Priority queue. @@ -65,7 +70,7 @@ export class PriorityQueue { this.priorityEnabled = enablePriority let head: PriorityQueueNode let tail: PriorityQueueNode - let prevNode : PriorityQueueNode | undefined + let prevNode: PriorityQueueNode | undefined let node: PriorityQueueNode | undefined = this.tail let buckets = 0 while (node != null) { @@ -205,7 +210,9 @@ export class PriorityQueue { } } - private getPriorityQueueNode (nodeArray?: FixedQueueNode[]): PriorityQueueNode { + private getPriorityQueueNode ( + nodeArray?: FixedQueueNode[] + ): PriorityQueueNode { let fixedQueue: IFixedQueue if (this.priorityEnabled) { fixedQueue = new FixedPriorityQueue(this.bucketSize) diff --git a/src/utility-types.ts b/src/utility-types.ts index e40d7b52..858dc0e6 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -245,12 +245,12 @@ export interface IFixedQueue { * Checks if the fixed queue is empty. * @returns `true` if the fixed queue is empty, `false` otherwise. */ - empty(): boolean + empty: () => boolean /** * Checks if the fixed queue is full. * @returns `true` if the fixed queue is full, `false` otherwise. */ - full(): boolean + full: () => boolean /** * Enqueue data into the fixed queue. * @param data - Data to enqueue. @@ -258,28 +258,28 @@ export interface IFixedQueue { * @returns The new size of the fixed queue. * @throws If the fixed queue is full. */ - enqueue (data: T, priority?: number): number + enqueue: (data: T, priority?: number) => number /** * Gets data from the fixed queue. * @param index - The index of the data to get. * @returns The data at the index or `undefined` if the fixed queue is empty or the index is out of bounds. */ - get (index: number): T | undefined + get: (index: number) => T | undefined /** * Dequeue data from the fixed queue. * @returns The dequeued data or `undefined` if the fixed queue is empty. */ - dequeue (): T | undefined + dequeue: () => T | undefined /** * Clears the fixed queue. */ - clear (): void + clear: () => void /** * Returns an iterator for the fixed queue. * @returns An iterator for the fixed queue. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols */ - [Symbol.iterator] (): Iterator + [Symbol.iterator]: () => Iterator } /** diff --git a/tests/fixed-priority-queue.test.mjs b/tests/fixed-priority-queue.test.mjs index e474bd1c..9321709d 100644 --- a/tests/fixed-priority-queue.test.mjs +++ b/tests/fixed-priority-queue.test.mjs @@ -1,8 +1,6 @@ import { expect } from 'expect' -import { - FixedPriorityQueue, -} from '../lib/fixed-priority-queue.cjs' +import { FixedPriorityQueue } from '../lib/fixed-priority-queue.cjs' import { defaultQueueSize } from '../lib/utility-types.cjs' describe('Fixed priority queue test suite', () => { diff --git a/tests/fixed-queue.test.mjs b/tests/fixed-queue.test.mjs index 941b7916..e99e7566 100644 --- a/tests/fixed-queue.test.mjs +++ b/tests/fixed-queue.test.mjs @@ -1,8 +1,6 @@ import { expect } from 'expect' -import { - FixedQueue, -} from '../lib/fixed-queue.cjs' +import { FixedQueue } from '../lib/fixed-queue.cjs' import { defaultQueueSize } from '../lib/utility-types.cjs' describe('Fixed queue test suite', () => { @@ -27,9 +25,7 @@ describe('Fixed queue test suite', () => { expect(fixedQueue.start).toBe(0) expect(fixedQueue.size).toBe(1) expect(rtSize).toBe(fixedQueue.size) - expect(fixedQueue.nodeArray).toMatchObject([ - { data: 1, priority: 0 }, - ]) + expect(fixedQueue.nodeArray).toMatchObject([{ data: 1, priority: 0 }]) expect(fixedQueue.capacity).toBe(queueSize) rtSize = fixedQueue.enqueue(2) expect(fixedQueue.start).toBe(0)