Socket
Socket
Sign inDemoInstall

@denox/buffer

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @denox/buffer

Buffer, backed by a Circular Singly Linked List.


Version published
Weekly downloads
8
increased by166.67%
Maintainers
1
Install size
16.9 kB
Created
Weekly downloads
 

Readme

Source

Buffer

This is buffer based on a circular singly linked list implementation that follows the itterator interface, being a drop in replacement for iterable structure when you need a list. When used unbound, it acts like a queue, when used bound, will start evicting once it hits the maxSize.

Usage Deno

import Buffer from "https://deno.land/x/buffer/mod.ts";

Usage Node

npm install --save @denox/buffer
import Buffer from "@denox/Buffer";

API

Initialization

The only argument is entries and it is optional, allowing prepopulating the buffer.

const queue = new Buffer(); // Creates an empty queue
const queueWithData = new Buffer(Infinity, ["value1", "value2"]); // Creates a queue with 2 entries

const buffer = new Buffer(100); // Creates an empty buffer
const bufferWithData = new Buffer(100, ["value1", "value2"]); // Creates a buffer with 2 entries

Push

Add a value to end of the buffer.

buffer.push("value");

Pop

Retrieve a value from begining of the buffer.

buffer.pop(); // "value"

Peek

Retrieve a value from begining of the buffer, similar with pop but without changing the buffer.

buffer.peek("key");

Clear

Clear everything from the buffer, leaving the queue empty.

buffer.clear();

Size

Get the current size of the buffer.

buffer.size; // Number

MaxSize

Get the capacity of the buffer.

buffer.maxSize; // Number

Keys, Values, Entries

Get the iterators for keys, values or entries ordered based on the insetion.

Array.from(buffer.keys()); // [value1, value2, ...]
Array.from(buffer.values()); // [value1, value2, ...]
Array.from(buffer.entries()); // [[value1, value1], [value2, value2], ...]

ForEach

Iterate over the values in the insersion order.

buffer.forEach((value, key, buffer) => {
	//...
});

License

MIT

Keywords

FAQs

Last updated on 07 Nov 2022

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc