@akashbabu/node-dll

中文文档
2.0.2发布于 2019/12/22MITTypeScriptESM + CJS零依赖近 30 天下载 2373

DLL(doubly linked list) library for javascript projects

原始使用文档
文档目录8 节
  1. Introduction
  2. Documentation
  3. Installation
  4. Sample usage
  5. API - DLL
  6. API - DLLItem
  7. Contribution
  8. Licence

node-dll Coverage Status Build Status Maintainability

DLL(Doubly linked list) implementation for javascript projects

Introduction

Doubly linked list(DLL) is inevitable in certain situation where performance is preferred while slicing an array (maybe there are more to it, but this is mostly my PoV). So this library was created with a simple, yet powerful interface for interacting with the underlying DLL schema.

This library is written in typescript for robust APIs and type support.

Every aspect was desgined and thought carefully to minimize introducing new bugs.

Documentation

API method name has been carefully chosen to nearly match Array methods, such that learning curve is least and adaptability is higher. But a few methods couldn't have had a different name and we had to convince ourselves with those method name.

Installation

npm i @akashbabu/node-dll -S

Sample usage

import {DLL, DLLItem} from '@akashbabu/node-dll';

const dll = new DLL<string>();

const dllItem: DLLItem<string> = dll.push('foo');
console.log(dllItem.data) // => foo

console.log(dll.length) // => 1

dll.remove(dllItem)
console.log(dll.length) // => 0

dll.push('foo')
dll.unshift('bar')

const headItem = dll.head
console.log(headItem.data) // => bar

const headData = dll.shift()
console.log(headData) // => bar

console.log(dll.head.data) // => foo

dll.clear()
console.log(dll.length) // => 0

const firstItem = dll.push('first')
dll.push('third')

dll.appendAfter(firstItem, 'second')

dll.forEach((item, i) => {
  console.log(`${i + 1}) ${item}`);
})
// => 1) first
// => 2) second
// => 3) third


console.log(dll.map((item, i) => `${i + 1}) ${item}`));
// => ["1) first", "2) second", "3) third"]

API - DLL

new DLL():

This creates a new instance of DLL.
T -> Denotes the type of data being saved in DLL

.head: DLLItem | null

Returns the first item in the list

.tail: DLLItem | null

Returns the last item in the list

.length: number

Returns the length of the list

.shift(): T | undefined

Removes and returns the first item in the list. Returns undefined if the list is empty

.unshift(data: T): void

Adds the given item to the head of DLL (same as Array.unshift logic)

.forEach(cb: (data: T, i: number) => void): void

Iterates through the entire DLL

.map(cb: (data: T, i: number) => U): U[]

Iterates through the entire DLL and returns the resultant array.
U -> Denotes the return type of cb(callback)

.push(data: T): DLLItem

Adds the given item to the tail of DLL and returns the added item

.appendAfter(dllItem: DLLItem, data: T): DLLItem

Adds the given data after the given dllItem in DLL and returns the added item

.remove(dllItem: DLLItem): boolean

Removes the given item from DLL and returns true if the removal was successful

.clear()

Removes all the items in the DLL

API - DLLItem

DLLItem has a readonly access to prev and next properties, this is to ensure that the users doesn't change them unintentionally (which can mess up with the entire DLL) and hence less surface for bugs.

.data

Set / get data value on the DLLItem via this property

.prev

Get prev value on the DLLItem via this property

.next

Get next value on the DLLItem via this property

Contribution

All contributions are welcome!!!

But before raising any issue, please check the issue-tracker in github if there is any matching issues already in the pipeline, if not then please go ahead and raise your own.

PR Guidelines:

  • Make sure to include corresponding test cases
  • Be generous on code comments
  • Write documentation if necessary
  • Wait for your approval 😜

Licence

MIT

版本与发布记录

@akashbabu/node-dll 共发布 5 个版本,首次发布于 2019/12/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.2latest2019/12/226 年前
2.0.12019/12/136 年前
2.0.02019/12/046 年前
1.1.02019/12/016 年前
1.0.02019/12/016 年前

关于 @akashbabu/node-dll 的常见问题

@akashbabu/node-dll 是什么?

DLL(doubly linked list) library for javascript projects

如何安装 @akashbabu/node-dll?

在项目目录运行 npm install @akashbabu/node-dll,或使用 pnpm add / yarn add / bun add。

@akashbabu/node-dll 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@akashbabu/node-dll 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@akashbabu/node-dll 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=8。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@akashbabu/node-dll 可以商用吗?

@akashbabu/node-dll 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@akashbabu/node-dll 的下载量有多少?

根据 npm 官方下载统计,@akashbabu/node-dll 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,373 次,日均约 79 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@akashbabu/node-dll 还在维护吗?

最新版本 2.0.2 发布于 2019/12/22(6 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/12/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。