npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ssibrahimbas/core

v0.0.9

Published

Contains helpful Type-Java-Script constructs.

Downloads

7

Readme

Maintainers

| Maintainer | GitHub | Web | |-----------------------|-------------------------------------------------|---------------------------------------------------------| | Sami Salih İbrahimbaş | ssibrahimbas | @ssibrahimbas |

Installation

With npm

$ npm install @ssibrahimbas/core

Or with yarn:

$ yarn add @ssibrahimbas/core

Usage

For TypeScript


import {Queue, PriorityQueue, Stack} from "@ssibrahimbas/core";

interface IQueueType {
    name: string;
}
const myQueue = new Queue<IQueueType>();

interface IPriorityQueueType {
    priority: number;
    name: string;
}
const myPriorityQueue = new PriorityQueue<IPriorityQueue>((a, b) => a.priority - b.priority);

interface IstackType {
    url: string;
}
const pageHistoryStack = new Stack<IstackType>();

for JavaScript


// import {Queue, PriorityQueue, Stack} from "@ssibrahimbas/core"; // for module
const {Queue, PriorityQueue, Stack} = require("@ssibrahimbas/core"); // for commonjs

const myQueue = new Queue();
const myPriorityQueue = new PriorityQueue((a,b) => a - b);
const myStack = new Stack();

API

Queue

Description:

The feature of queue is FIFO. That is, fist in, first out.

Type-Java-Script itself has no queue structure. However, we may want to queue some transactions for various reasons. We can even process according to the importance of these queses, see: PriorityQueue.

That's why this post and you are here. @ssibrahimbas/core It, gives the queue structure to Type-Java-Script.

PriorityQueue

Description

FIFO is a very nice rule, but you may not need it. Instead, the priority may need to be delisted first.

We can compare this to the fact that in any queue (for example, the hospital queue), the elderly and children get ahead of other people first.

While this is a very nice feature, it requires more performance than the Queue itself. Because the list must be reordered every time an element is added. You may have some peace of mind about this. We do the sorting on the insertion with BubbleSort, and it has a total O(logn) performance complexity. If we had used the ``sort``` method instead, this complexity would have increased to O(n log n).

Its usage is exactly the same as Queue except for deletion and cloning. The structure running in the background changes.

Stack

Description:

Another data type not in JavaScript itself is Stack. The feature of stacks is LIFO. That is, last in, first out.

Thanks to this package, you can use the Stack data type on JavaScript.

QueueSize


type User = {
    name: string;
}
const userQueue = new Queue<User>();
userQueue.size; // return 0
userQueue.enqueue({name: "sami"}); // enqueue sami
userQueue.size // return 1

Returns the size of the queue

Returns: number

QueueEnqueue


type User = {
    name: string;
}
const userQueue = new Queue<User>();
userQueue.enqueue({name: "sami"}); // enqueue sami

Add element to queue

| Param | Type | |---------------|---------------| | element | T - your type |

Returns: void

QueueDequeue


type User = {
    name: string;
}
const userQueue = new Queue<User>();
userQueue.enqueue({name: "sami"}); // enqueue sami
userQueue.dequeue(); // remove first element

Remove first element this queue - cf. FIFO

Returns: void

QueueDequeueByIndex


type User = {
    name: string;
}
const userQueue = new Queue<User>();
userQueue.enqueue({name: "sami"});
userQueue.enqueue({name: "john"});
userQueue.enqueue({name: "evan"});
userQueue.enqueue({name: "salih"});
userQueue.dequeueByIndex(2); // remove evan

remove element at specific index from this queue

Returns: boolean

QueueIsEmpty


const userQueue = new Queue<any>();
console.log(userQueue.isEmpty())

Is the queue empty?

Returns: boolean

QueuePeek


type User = {
    name: string;
}
const userQueue = new Queue<User>();
userQueue.enqueue({name: "sami"}); // enqueue sami
console.log(userQueue.peek())

// result -> {name: 'sami'}

Return first element from this queue

Returns: T

QueueLength


type User = {
    name: string;
}
const userQueue = new Queue<User>();
userQueue.enqueue({name: "sami"});
console.log(userQueue.length())

Returns the size of the queue - similar to size

Returns: number

QueueToArray


type User = {
    name: string;
}
const userQueue = new Queue<User>();
userQueue.enqueue({name: "sami"});
console.log(userQueue.toArray()) // [{name: 'sami'}]

Converts queue to array

Returns: Array<T>

QueueToString


type User = {
    name: string;
}
const userQueue = new Queue<User>();
userQueue.enqueue({name: "sami"});
console.log(userQueue.toString()) // "[{name: 'sami'}]"

QueueClone


type User = {
    name: string;
}
const userQueue = new Queue<User>();
userQueue.enqueue({name: "sami"});
const employeeQueue = userQueue.clone();
console.log(employeeQueue.toString()) // "[{name: 'sami'}]"

Clones the queue

Returns: QueueType<T>

QueuePriorityDequeue


type User = {
    name: string;
}
const userQueue = new PriorityQueue<User>((a,b) => a.priority - b.priority);
userQueue.enqueue({name: "sami", priority: 2});
userQueue.enqueue({name: "salih", priority: 3});
userQueue.enqueue({name: "mehmet", priority: 1});
userQueue.dequeue(); // remove salih
userQueue.dequeue(1); // remove mehmet

Remove first element or your index this queue - cf. FIFO

| Param | Type | |-------------|--------| | index | number |

Returns: void

QueuePriorityClone


type User = {
    name: string;
}
const userQueue = new PriorityQueue<User>((a,b) => a.priority - b.priority);
userQueue.enqueue({name: "sami", priority: 2});
userQueue.enqueue({name: "salih", priority: 3});
const employeeQueue = userQueue.clone();
console.log(employeeQueue.toString()) // "[{name: "salih", priority: 3}, {name: "sami", priority: 2}]"

Clones the queue

Returns: PriorityQueueType<T>

StackPush


type Page = {
    url: string;
}
const pageStack = new Stack<Page>();
pageStack.push({url: "www.itemsatis.com"});

Add element to stack

| Param | Type | |---------------|---------------| | element | T - your type |

Returns: void

StackLength


type Page = {
    url: string;
}
const pageStack = new Stack<Page>();
pageStack.push({url: "www.itemsatis.com"});
console.log(pageStack.length())

Returns the size of the stack

Returns: number

StackPeek


type Page = {
    url: string;
}
const pageStack = new Stack<Page>();
pageStack.push({url: "www.itemsatis.com"});
console.log(pageStack.peek())

// result -> {url: 'www.itemsatis.com'}

Return first element from this stack

Returns: T

StackIsEmpty

const pageStack = new Stack<any>();
console.log(pageStack.isEmpty())

Is the stack empty?

Returns: boolean

StackPop


type Page = {
    url: string;
}
const pageStack = new Stack<Page>();
pageStack.push({url: "www.itemsatis.com"});
pageStack.push({url: "www.itempazar.com"});
const last = pageStack.pop(); // return last element and remove

Remove last element this stack - cf. LIFO

Returns: T

StackReverse


type Page = {
    url: string;
}
const pageStack = new Stack<Page>();
pageStack.push({url: "www.itemsatis.com"});
pageStack.push({url: "www.itempazar.com"});
const last = pageStack.pop(); // return last element and remove

reverses the stack.

For the above example: the first element declared 'www.itemsatis.com' will be the last element and will appear first in a possible pop call.

Returns: void

StackToArray


type Page = {
    url: string;
}
const pageStack = new Stack<Page>();
pageStack.push({url: "www.itemsatis.com"});
console.log(pageStack.toArray()) // [{url: 'www.itemsatis.com'}]

Converts queue to stack

Returns: Array<T>

StackToString


type Page = {
    url: string;
}
const pageStack = new Stack<Page>();
pageStack.push({url: "www.itemsatis.com"});
console.log(pageStack.toString()) // "[{url: "www.itemsatis.com"}]"

Converts queue to string

Returns: string

StackClone


type Page = {
    url: string;
}
const pageStack = new Stack<Page>();
pageStack.push({url: "www.itemsatis.com"});
const pageStackClone = pageStack.clone();
console.log(pageStackClone.toString()) // "[{url: "www.itemsatis.com"}]"

Clones the queue

Returns: StackType<T>