New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@kartjim/queue

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kartjim/queue

Queue implementation in JavaScript (based on Array)

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

queue

Queue implementation in JavaScript (based on Array)

队列:先入先出

install

npm i @kartjim/queue

export

const { Queue } = require('@kartjim/queue');

or ESM :

import { Queue } from "@kartjim/queue";

Queue API

export class Queue<A> {
    constructor(arr?: T[]);
    isEmpty(): boolean;
    size(): number;
    front(): A;
    end(): A;
    push(val: A): Queue<A>;
    pop(): A;
    toArray(): A[];
    clear(): void;
}

constructor

create a Queue from an Array.

const queue = new Queue();
// or
// new Queue([1, 2, 3]);

isEmpty

Checks if the Queue is empty.

console.log(stack.isEmpty()) // true
queue.push(1);
console.log(queue.isEmpty()) // false

size

return the number of elements in the queue.

console.log(queue.size()) // 1

push

push an element to the top of the queue.

queue.push(2)
console.log(stack.front()) // 1
console.log(stack.end()) // 2

front

return the element at the front of the queue.

queue.push(5);
console.log(stack.front()) // 1

end

return the element at the end of the queue.

queue.push(6);
console.log(stack.end()) // 6
console.log(stack.size()) // 4

pop

remove and return the top element in the queue.

console.log(queue.pop()) // 1
console.log(queue.pop()) // 2
console.log(queue.pop()) // 5
console.log(queue.pop()) // 6
console.log(queue.pop()) // undefined

toArray

return an array of elements in the queue.

queue.push(8).push(9).push(11);
console.log(queue.toArray()) // [8, 9, 11]

clear

remove all elements from the queue.

queue.clear();
console.log(queue.size()) // 0
console.log(queue.isEmpty()) // true

Coverage

🚀 grunt coverage

===================== Coverage summary =====================
Statements   : 100% ( 80/80 )
Branches     : 100% ( 6/6 )
Functions    : 100% ( 9/9 )
Lines        : 100% ( 80/80 )
============================================================

Keywords

queue

FAQs

Package last updated on 18 Jan 2023

Did you know?

Socket

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.

Install

Related posts