https://github.com/sbsoftware/node-capped-array
Simple Array modification to have a fixed-length array that automatically drops the last entry when pushing over the size.
https://github.com/sbsoftware/node-capped-array
Last synced: 7 months ago
JSON representation
Simple Array modification to have a fixed-length array that automatically drops the last entry when pushing over the size.
- Host: GitHub
- URL: https://github.com/sbsoftware/node-capped-array
- Owner: sbsoftware
- License: mit
- Created: 2013-11-30T11:08:03.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-04T20:44:41.000Z (over 11 years ago)
- Last Synced: 2025-08-09T02:52:56.205Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 145 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
node-capped-array
=================
Simple Array modification to have a fixed-length array that automatically drops the last entry when pushing over the size.
CappedArrays inherit the prototype methods of Array and override the push and unshift methods, so in principle you can
use them as usual arrays.
Unfortunately I couldn't manage to make util.isArray() return true for CappedArrays. I guess that's the reason why
console.log won't display them like normal arrays, but like objects. That's what the toArray() method is for,
which returns a real array containing the same entries as the CappedArray.
Installation
------------
`npm install capped-array`
Usage
-----
var CappedArray = require('capped-array');
var cArr = new CappedArray(5);
console.log(cArr.toArray()); // []
cArr.push('test');
console.log(cArr.toArray()); // ['test']
cArr.forEach(function (el) {
console.log(el);
}); // test