开发者社区> 镜像站> NPM> @emilbayes/capped-array
@emilbayes/capped-array
> CappedArray inherited from Array
Last updated 10 months ago by emilbayes .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @emilbayes/capped-array 
SYNC missed versions from official npm registry.

@emilbayes/capped-array

CappedArray inherited from Array

Usage

var CappedArray = require('@emilbayes/capped-array')

var arr = new CappedArray(2) // max 100 elements

arr.push('foo')
arr.deleted // === 0
arr.length // === 1
arr.size // === 2

arr.push('bar')
arr.deleted // === 0
arr.length // === 2
arr.size // === 2

arr.push('baz')
arr.deleted // === 1
arr.length // === 2
arr.size // === 2
// arr is now ['bar', 'baz']

API

const arr = new CappedArray(size)

Create a new CappedArray with a maximum size of size

arr.deleted

This property is updated on each mutation (push, unshift) that might have delete elements

arr.size

The maximum size of the capped array

Inherited

Otherwise this module just inherits all methods and properties from Array. Eg. .length will give you the current number of elements in the array, maxed at the size

Install

npm install @emilbayes/capped-array

License

ISC

Current Tags

  • 1.0.0                                ...           latest (10 months ago)

1 Versions

  • 1.0.0                                ...           10 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None