Registry / serialization / linked-list-typescript

linked-list-typescript

JSON →
library1.0.15jsnpmunverified

The `linked-list-typescript` package provides a straightforward, type-safe implementation of a doubly linked list in TypeScript. Currently stable at version 1.0.15, it emphasizes simplicity and strong typing through TypeScript generics. The library supports the JavaScript `Iterator` and `Iterable` protocols, enabling native iteration via `for...of` loops, spread syntax (`...`), and array destructuring. Key operations like retrieving head/tail elements, and removing head/tail are available. Unlike some data structures, it stores references to values rather than copies, which is important for understanding its behavior with mutable objects. The project appears to be in an active maintenance phase, with a focus on a stable 1.x release line.

npm install linked-list-typescript
INSTALL
IMPORT
SIG · LINKED-LIST-TYPESC
L
linked-list-typescript
serializationjavascriptv1.0.15
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LinkedList
import { LinkedList } from 'linked-list-typescript';
import LinkedList from 'linked-list-typescript';
LinkedList is a named export. Ensure to use destructuring in the import statement. Both ESM and CommonJS named imports are supported.
LinkedList (CommonJS)
const { LinkedList } = require('linked-list-typescript');
const LinkedList = require('linked-list-typescript');
For CommonJS environments, LinkedList is exported as a named property of the module object.
LinkedList<T> (Generics)
const list = new LinkedList<string>();
const list = new LinkedList();
While `new LinkedList()` might work in some contexts, explicitly defining the generic type `T` (e.g., `<string>`) provides strong type checking and is recommended for TypeScript projects. Use `LinkedList<any>` for mixed types.

Demonstrates how to create a generic linked list, initialize it with values, iterate over its elements, deconstruct, and perform basic operations like removing the head, including usage with custom types.

import { LinkedList } from 'linked-list-typescript'; // Create a new linked list initialized with number values let numberList = new LinkedList<number>(10, 20, 30); console.log(`List length: ${numberList.length}`); console.log(`Head value: ${numberList.head}`); console.log(`Tail value: ${numberList.tail}`); console.log("Iterating through the list using for...of:"); for (const item of numberList) { console.log(item); } // Deconstruct elements let [first, second] = numberList; console.log(`Destructured: first=${first}, second=${second}`); // Remove an element from the head const removed = numberList.removeHead(); console.log(`Removed head: ${removed}`); console.log(`New head: ${numberList.head}`); // Example with a custom type class Item { constructor(public id: number, public name: string) {} } let item1 = new Item(1, "Apple"); let item2 = new Item(2, "Banana"); let itemList = new LinkedList<Item>(item1, item2); console.log(`Custom type list head: ${itemList.head?.name}`); // Accessing property safely
Debug
Known issues
gotchaIncorrect type arguments for `LinkedList<T>` constructor will result in TypeScript compilation errors due to type inference or direct type checking.
fix
Ensure all initial values passed to the `LinkedList` constructor conform to the specified generic type `T`. Use `LinkedList<any>` if heterogeneous types are intentionally required.
affects: >=1.0.0
gotchaAccessing `head` or `tail` properties on an empty `LinkedList` instance will return `undefined` instead of throwing an error. This can lead to runtime issues if not checked.
fix
Always check if the list is empty (e.g., `list.length === 0` or `list.head !== undefined`) before attempting to access `head` or `tail` and their properties.
affects: >=1.0.0
gotchaThe `LinkedList` stores values by reference, not by copy. Modifying objects after they have been added to the list will affect the values within the list.
fix
Be aware that changes to referenced objects will be reflected in the list. If immutable values are desired, ensure objects are not modified after insertion or create defensive copies before adding them.
affects: >=1.0.0
Errors
Common errors & fixes
Argument of type 'string | number' is not assignable to parameter of type 'string'.
Attempting to initialize a `LinkedList<string>` with values that include numbers, or vice-versa, leading to a TypeScript type mismatch.
fix
Ensure all initial values match the generic type `T` specified for the `LinkedList`. For mixed types, explicitly use `new LinkedList<any>(...)`.
TypeError: Cannot read properties of undefined (reading 'property_name')
Attempting to access a property on `list.head` or `list.tail` when the list is empty, causing `head`/`tail` to return `undefined` and subsequent property access to fail.
fix
Before accessing properties on `list.head` or `list.tail`, verify that `list.head` (or `list.tail`) is not `undefined`, typically by checking `list.length > 0` or using optional chaining (`list.head?.property_name`).
TypeError: linked_list_typescript_1.default is not a constructor
Attempting to import `LinkedList` as a default export (`import LinkedList from 'linked-list-typescript'`) when it is provided as a named export.
fix
Correct the import statement to use named exports: `import { LinkedList } from 'linked-list-typescript';`
Upgrade
Version history
1.0.15latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
Amazon
1
Resources
linked-list-typescript — npm install linked-list-typescript · libregistry