
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
circular-stack
Advanced tools
A fixed-size auto-overwriting stack implementation.
npm install circular-stack --save
Import the script:
<script src="https://joker876.github.io/circular-stack/circular-stack.min.js">
And import the class from a global object:
new CircularStack.CircularStack(/* capacity */);
import CircularStack from 'circular-stack';
new CircularStack<T = any>(capacity: number);
CircularStack constructor takes the stack's maximum capacity as its only argument. Capacity is optional, and defaults to 100.
The type of the elements can also be specified explicitly. The default type is any.
const stack = new CircularStack(50);
// or with specified type
const stack = new CircularStack<number>(50);
size - the amount of elements on the stack.capacity - the meximum number of elements on the stack. Exceeding this value will cause the elements to be overwritten when pushed.stack.push(item: T): void
Pushes a new item onto the stack.
If the size of the stack reaches the capacity, it overwrites the oldest item.
stack.push(5);
stack.pop(): T | undefined
Removes the top element on the stack, and returns it.
If the stack is empty, returns undefined.
stack.push(1);
stack.push(2);
stack.push(3);
stack.pop(); // >>>>> 3
stack.pop(); // >>>>> 2
stack.pop(); // >>>>> 1
stack.pop(); // >>>>> undefined
stack.peek(): T | undefined
Returns the top element of the stack without removing it.
If the stack is empty, returns undefined.
stack.push(1);
stack.peek(); // >>>>> 1
stack.peek(); // >>>>> 1
stack.clear(): void
Clears all elements from the stack.
stack.push(1);
stack.push(2);
stack.push(3);
stack.clear();
stack.peek(); // >>>>> undefined
FAQs
A fixed-size auto-overwriting stack.
We found that circular-stack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.