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

@santi100/linked-list

v0.0.4

Published

Santi's Minimal Linked List: Don't be the lost link!

Downloads

3

Readme

Santi's Minimal Linked List

Build Status GitHub stars License npm homepage

This is a minimal, lightweight, and portable linked list library. It's a simple solution for people that don't like stuff like yallist. It's written in TypeScript and is compatible with any runtime that supports ES3 or higher.

Its index file is an ESM wrapper, so if you're using version 0.0.1, you'll have to import from cjs/ in order to use the CommonJS version.

Example:

const { LinkedList } = require('@santi100/linked-list/cjs'); // 0.0.1
const { LinkedList } = require('@santi100/linked-list'); // 0.0.2 and higher

Installation

  • NPM: npm install @santi100/linked-list
  • Yarn: yarn add @santi100/linked-list
  • PNPM: pnpm install @santi100/linked-list

Usage

  • interface LinkedListItem<T>: The shape of a linked list item.

    • previous: LinkedListItem<T>; The previous item in the linked list. If this is the genesis item, it's null.
    • value: T; The value of this item in the linked list.
  • class LinkedList<T = unknown>: This is the linked list class.

    • constructor LinkedList<T = unknown>(iter?: T[]): LinkedList<T>: Creates a new linked list. | Name | Type | Description | Optional? | Default | |------------|--------------|-------------------------------------------|--------------|--------------| | T | type param | The type of every item of the list. | Yes | unknown | | iter? | T[] | An optional array to initialize the list with. | Yes | [] |

    • push(...items: T[]): this; Pushes one or more items to the list. Returns the this object for chaining. | Name | Type | Description | Optional? | Default | |------------|--------------|-------------------------------------------|--------------|--------------| | ...items | T[] | The item(s) you want to add to the list. | rest param | [] |

    • pop(): this; Pops the last item out of the list (and obviously returns it).

    • close(): this; Closes the list so it can't be modified. Returns the this object for chaining.

    • getLength(): this; Retrieves the length of the list.

    • isClosed(): boolean; Returns true in case the list has been closed (with LinkedList.prototype.close()).

    • reverse(): this; (since 0.0.2) Reverses the order of the items in the linked list in-place. It throws Error if the linked list has been closed, and returns the modified linked list instance.

    • toArray(): T[]; (since 0.0.2) Returns an array containing the values of each item in the linked list in the order they appear.

    • toString(): string; (since 0.0.2) Returns a JSON representation of the linked list items.

    • peekLast(): LinkedListItem<T> | null; (since 0.0.2) Returns the last item in the linked list without removing it, or null if the list's empty.

    • peekFirst(): LinkedListItem<T> | null; (since 0.0.2) Returns the first item in the linked list without removing it, or null if the list's empty.

    • peekList(): LinkedListItem<T>[]; (since 0.0.2) Returns a new array containing the same items as the linked list in the order they appear.

    • clear(): this; (since 0.0.3) Removes all items from the linked list. Returns the current LinkedList instance.

    • insert(index: number, item: T): this; (since 0.0.3) Inserts an item at the specified index in the linked list. | Name | Type | Description | Optional? | Default | |------------|--------------|-------------------------------------------|--------------|--------------| | index | number | The index at which to insert the item. | No | N/A | | item | T | The item to insert. | No | N/A |

    • remove(value: T): boolean; (since 0.0.3) Removes the first occurrence of the specified item from the linked list. | Name | Type | Description | Optional? | Default | |------------|--------------|-------------------------------------------|--------------|--------------| | value | T | The value of the item to remove. | No | N/A |

      Returns true if the item was removed, false otherwise.

    • copy(): LinkedList<T>; (since 0.0.4) Copies this linked list. Returns a copy of this linked list.

    • forEach(cb: LinkedListForEachCb<T, R>): this; (since 0.0.4) Executes cb for every item in the list. | Name | Type | Description | Optional? | Default | |------|---------------------------|----------------------------------|--------------|--------------| | cb |LinkedListForEachCb<T, R>| The callback to be executed for every item in the list. | No | N/A |

    • map(cb: LinkedListForEachCb<T, R>): LinkedList<T>; (since 0.0.4) Maps every item of this linked list to another one in a new linked list, via cb. | Name | Type | Description | Optional? | Default | |------|---------------------------|----------------------------------|--------------|--------------| | cb |LinkedListForEachCb<T, R>| The callback to be executed for every item in the original list. | No | N/A | Returns a new linked list containing the results of calling cb for every item in the original one.

    • filter(cb: LinkedLinkedForEach<T, boolean>): LinkedList; (since 0.0.4) Executes cb for every item in the linked list, and creates a new one which contains only the items that make cb return true.

    • some(cb: LinkedLinkedForEach<T, boolean>): boolean; (since 0.0.4) Returns whether or not at least one item of the linked list makes cb return true. | Name | Type | Description | Optional? | Default | |------------|--------------|-------------------------------------------|--------------|--------------| | cb | LinkedLinkedForEach<T, boolean> | The callback function to be executed on every item of the linked list. | No | N/A |