1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 19:04:46 +00:00

feat(monorepo): migrate vue packages and apply oxlint refactors

This commit is contained in:
2026-03-07 18:07:22 +07:00
parent abd6605db3
commit 41d5e18f6b
286 changed files with 10295 additions and 5028 deletions

View File

@@ -112,8 +112,8 @@ describe('stack', () => {
for await (const element of stack) {
elements.push(element);
}
expect(elements).toEqual([3, 2, 1]);
});
});
});
});

View File

@@ -5,7 +5,7 @@ import type { StackLike } from './types';
export type { StackLike } from './types';
export interface StackOptions {
maxSize?: number;
maxSize?: number;
}
/**
@@ -18,138 +18,138 @@ export interface StackOptions {
* @template T The type of elements stored in the stack
*/
export class Stack<T> implements StackLike<T> {
/**
/**
* The maximum number of elements that the stack can hold
*
*
* @private
* @type {number}
*/
private readonly maxSize: number;
private readonly maxSize: number;
/**
/**
* The stack data structure
*
*
* @private
* @type {T[]}
*/
private readonly stack: T[];
private readonly stack: T[];
/**
/**
* Creates an instance of Stack
*
*
* @param {(T[] | T)} [initialValues] The initial values to add to the stack
* @param {StackOptions} [options] The options for the stack
* @memberof Stack
*/
constructor(initialValues?: T[] | T, options?: StackOptions) {
this.maxSize = options?.maxSize ?? Infinity;
this.stack = isArray(initialValues) ? initialValues : initialValues ? [initialValues] : [];
}
/**
constructor(initialValues?: T[] | T, options?: StackOptions) {
this.maxSize = options?.maxSize ?? Infinity;
this.stack = isArray(initialValues) ? initialValues : initialValues ? [initialValues] : [];
}
/**
* Gets the number of elements in the stack
* @returns {number} The number of elements in the stack
*/
public get length() {
return this.stack.length;
}
public get length() {
return this.stack.length;
}
/**
/**
* Checks if the stack is empty
* @returns {boolean} `true` if the stack is empty, `false` otherwise
*/
public get isEmpty() {
return this.stack.length === 0;
}
public get isEmpty() {
return this.stack.length === 0;
}
/**
/**
* Checks if the stack is full
* @returns {boolean} `true` if the stack is full, `false` otherwise
*/
public get isFull() {
return this.stack.length === this.maxSize;
}
public get isFull() {
return this.stack.length === this.maxSize;
}
/**
/**
* Pushes an element onto the stack
* @param {T} element The element to push onto the stack
* @returns {this}
* @throws {RangeError} If the stack is full
*/
public push(element: T) {
if (this.isFull)
throw new RangeError('Stack is full');
this.stack.push(element);
public push(element: T) {
if (this.isFull)
throw new RangeError('Stack is full');
return this;
}
this.stack.push(element);
/**
return this;
}
/**
* Pops an element from the stack
* @returns {T | undefined} The element popped from the stack
*/
public pop() {
return this.stack.pop();
}
public pop() {
return this.stack.pop();
}
/**
/**
* Peeks at the top element of the stack
* @returns {T | undefined} The top element of the stack
*/
public peek() {
if (this.isEmpty)
return undefined;
return last(this.stack);
}
public peek() {
if (this.isEmpty)
return undefined;
/**
return last(this.stack);
}
/**
* Clears the stack
*
*
* @returns {this}
*/
public clear() {
this.stack.length = 0;
public clear() {
this.stack.length = 0;
return this;
}
return this;
}
/**
/**
* Converts the stack to an array
*
*
* @returns {T[]}
*/
public toArray() {
return this.stack.toReversed();
}
public toArray() {
return this.stack.toReversed();
}
/**
/**
* Returns a string representation of the stack
*
*
* @returns {string}
*/
public toString() {
return this.toArray().toString();
}
public toString() {
return this.toArray().toString();
}
/**
/**
* Returns an iterator for the stack
*
*
* @returns {IterableIterator<T>}
*/
public [Symbol.iterator]() {
return this.toArray()[Symbol.iterator]();
}
public [Symbol.iterator]() {
return this.toArray()[Symbol.iterator]();
}
/**
/**
* Returns an async iterator for the stack
*
*
* @returns {AsyncIterableIterator<T>}
*/
public async *[Symbol.asyncIterator]() {
for (const element of this.toArray()) {
yield element;
}
public async* [Symbol.asyncIterator]() {
for (const element of this.toArray()) {
yield element;
}
}
}