Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

CBuffer

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

CBuffer - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

6

cbuffer.js

@@ -223,9 +223,9 @@ (function(global) {

},
// fill all used places with passed value
// fill all places with passed value or function
fill : function(arg) {
var i = 0;
if (typeof arg === 'function') {
while(this.data[i] = arg(), ++i < this.size);
while(this.data[i] = arg(), ++i < this.length);
} else {
while(this.data[i] = arg, ++i < this.size);
while(this.data[i] = arg, ++i < this.length);
}

@@ -232,0 +232,0 @@ // reposition start/end

{
"name" : "CBuffer",
"version" : "0.1.1",
"version" : "0.1.2",
"description" : "Circular Buffer JavaScript implementation",
"homepage" : "http://github.com/trevnorris/cbuffer",
"homepage" : "https://github.com/trevnorris/cbuffer",
"main" : "./cbuffer.js",

@@ -17,8 +17,8 @@ "author" : {

"devDependencies" : {
"vows" : "0.6.x"
"vows" : "latest"
},
"repository" : {
"type" : "git",
"url" : "http ://github.com/trevnoris/cbuffer.git"
"url" : "https://github.com/trevnoris/cbuffer.git"
}
}

@@ -6,2 +6,5 @@ ## JavaScript [Circular Buffer](http://en.wikipedia.org/wiki/Circular_buffer) Utility

Note: This is called a circular buffer because of what this library accomplishes, but is implemented
as an Array. This may be confusing for Node users, which may want to use a true Buffer.
As JavaScript is used for more and more computationally intensive tasks, it's important to reduce

@@ -18,2 +21,27 @@ execution and garbage collection time. By using a circular buffer instead of a native array less

### Usage
It's simple. Just use it like you would use an Array.
```javascript
new CBuffer(10); // empty buffer with length of 10
new CBuffer(1,2,3,4); // buffer with length 4
CBuffer(5); // For those who are really lazy, new is optional
```
Included are several non-standard niceties. Like if you want to catch when data is overwritten,
just assign a function to the `overflow` variable and it will be called whenever a value is about
to be overwritten and it will pass the value as the first argument:
```javascript
var myBuff = CBuffer(4);
myBuff.overflow = function(data) {
console.log(data);
};
myBuff.push(1,2,3,4); // nothing shows up yet
myBuff.push(5); // log: 1
```
### API

@@ -23,31 +51,31 @@

* pop()
* push()
* reverse()
* rotateLeft(x)
* rotateRight(x)
* shift()
* sort()
* unshift()
* pop - Removes the last element from a circular buffer and returns that element.
* push - Adds one or more elements to the end of a circular buffer and returns the new size.
* reverse - Reverses the order of the elements of a circular buffer.
* rotateLeft - Rotates all elements left 1, or n, times.
* rotateRight - Rotates all elements right 1, or n, times.
* shift - Removes the first element from a circular buffer and returns that element.
* sort - Sorts the elements of a circular buffer.
* unshift - Adds one or more elements to the front of a circular buffer and returns the new size.
#### Accessor Methods
* indexOf()
* lastIndexOf()
* indexOf - Returns the first (least) index of an element within the circular buffer equal to the specified value, or -1 if none is found.
* lastIndexOf - Returns the last (greatest) index of an element within the circular buffer equal to the specified value, or -1 if none is found.
#### Iteration Methods
* every()
* forEach()
* some()
* every - Returns true if every element in the circular buffer satisfies the provided testing function.
* forEach - Calls a function for each element in the circular buffer.
* some - Returns true if at least one element in the circular buffer satisfies the provided testing function.
#### Utility Methods
* empty()
* fill()
* first()
* last()
* get()
* set()
* toArray() - Return clean ordered array of buffer
* overflow - Set to function and will be called when data is about to be overwritten
* empty - Equivalent to setting `Array.length = 0`.
* fill - Fill all set values with passed argument. Also supports functions.
* first - Returns first value in circular buffer.
* last - Returns last value in circular buffer.
* get - Get value at specific index.
* set - Set value as specific index.
* toArray - Return clean ordered array of buffer.
* overflow - Set to function and will be called when data is about to be overwritten.

@@ -21,3 +21,3 @@ var vows = require( 'vows' ),

'data' : function( CBuffer ) {
assert.deepEqual( CBuffer( 3 ).data, [ und, und, und ]);
assert.deepEqual( CBuffer( 3 ).data, [,,]);
assert.deepEqual( CBuffer( 1, 2, 3 ).data, [ 1, 2, 3 ]);

@@ -24,0 +24,0 @@ },

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc