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

refactor(packages/stdlib): update dir names and imports

This commit is contained in:
2024-10-24 07:29:37 +07:00
parent 85eb28a5dc
commit 29d8aa086c
6 changed files with 43 additions and 36 deletions

View File

@@ -1,3 +1,6 @@
import { last } from '../../arrays';
import { isArray } from '../../types';
export type StackOptions = {
maxSize?: number;
};
@@ -37,7 +40,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
*/
constructor(initialValues?: T[] | T, options?: StackOptions) {
this.maxSize = options?.maxSize ?? Infinity;
this.stack = Array.isArray(initialValues) ? initialValues : initialValues ? [initialValues] : [];
this.stack = isArray(initialValues) ? initialValues : initialValues ? [initialValues] : [];
}
/**
@@ -95,7 +98,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
if (this.isEmpty)
throw new RangeError('Stack is empty');
return this.stack[this.stack.length - 1];
return last(this.stack);
}
/**