Registry / database / CBuffer

CBuffer

JSON →
library2.2.0jsnpmunverified

A circular buffer (ring buffer) implementation for JavaScript that aims to replicate the full Array.prototype API. Version 2.2.0 is the latest stable release; the project appears to be in maintenance mode with infrequent updates. Key differentiators: provides overflow callback, rotation methods (rotateLeft/rotateRight), sortedIndex, and get/set methods. Includes TypeScript definitions. Lightweight with no external dependencies.

npm install CBuffer
INSTALL
IMPORT
SIG · CBUFFER
C
CBuffer
databasejavascriptv2.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

CBuffer
import CBuffer from 'cbuffer'
const CBuffer = require('cbuffer')
Default import works with both CJS and ESM, but TypeScript may require esModuleInterop for CJS require.
CBuffer
const CBuffer = require('cbuffer').default
const CBuffer = require('cbuffer')
When using CommonJS with TypeScript or strict ESM, the default export is under .default.
CBuffer as CBufferType
import type CBuffer from 'cbuffer'
import { CBuffer } from 'cbuffer'
TypeScript users should use default import for types; named import is not available.

Creates a circular buffer, demonstrates push with auto-overwrite, overflow callback, rotateLeft, and sorting.

import CBuffer from 'cbuffer'; // Create a buffer of size 5 const buffer = new CBuffer(5); // Add elements buffer.push(1, 2, 3); console.log(buffer.toArray()); // [1, 2, 3] // Auto-overwrite oldest when full buffer.push(4, 5, 6); console.log(buffer.toArray()); // [2, 3, 4, 5, 6] // Overflow callback buffer.overflow = (data: number) => console.log('Overwritten:', data); buffer.push(7); // logs: Overwritten: 2 // Rotate buffer.rotateLeft(1); console.log(buffer.toArray()); // [3, 4, 5, 6, 7] // Sort (default comparator: a > b) buffer.sort(); console.log(buffer.toArray()); // [3, 4, 5, 6, 7] // Get length console.log(buffer.length); // 5
Debug
Known issues
gotchaCBuffer does not implement all Array.prototype methods; missing methods like map, filter, reduce, concat, etc.
fix
Check the documentation for the implemented API before relying on a standard array method.
affects: >=2.0
gotchaThe sort() method uses a default comparator a > b (numeric descending), not the standard string comparison of Array.prototype.sort().
fix
Always pass a custom comparator to sort() for predictable behavior.
affects: >=2.0
gotchaUsing new CBuffer(singleNumber) creates an empty buffer of that size, not a buffer with one element. For a single element buffer, use new CBuffer([value]) or similar.
fix
Pass multiple arguments to initialize with values, or use a CBuffer with size then push.
affects: >=2.0
deprecatedThe npm package name is 'cbuffer' (lowercase), but the README uses 'CBuffer'. This inconsistency may cause confusion when importing.
fix
Always use lowercase 'cbuffer' when installing or importing.
affects: >=2.0
Errors
Common errors & fixes
TypeError: CBuffer is not a constructor
Using require() without .default in CommonJS environments with esModuleInterop disabled.
fix
Use const CBuffer = require('cbuffer').default; or switch to import statement.
Cannot find module 'CBuffer' or 'cbuffer'
Mixing up case in package name; npm package is lowercase 'cbuffer'.
fix
npm install cbuffer and import from 'cbuffer' (lowercase).
Property 'map' does not exist on type 'CBuffer<number>'
CBuffer does not implement Array.prototype.map.
fix
Use toArray() to convert to a regular array first: buffer.toArray().map(...).
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
64 hits · last 30 days
node
56
Perplexity
1
OpenAI (training)
1
Resources
CBuffer — npm install CBuffer · libregistry