Browse files

Merge remote-tracking branch 'upstream/master'

Conflicts:
	lib/eventvat.js
  • Loading branch information...
2 parents 2f27f78 + afdc7a5 commit 274e4bd153848bc4fa7a9e27c4cca4af2c1313ae @fent fent committed Mar 16, 2012
Showing with 286 additions and 112 deletions.
  1. +170 −16 README.md
  2. +115 −95 lib/eventvat.js
  3. +1 −1 package.json
View
186 README.md
@@ -18,35 +18,189 @@ $npm install eventvat
```
# Usage
-
-Instantiate EventVat with existing data or without. Methods and events are hung off of the new instance. Each method that can act on the instance will raise an event by the same name.
+Each new instance of `EventVat` is a hash. There are lots of convenient methods attached to each new instance.
## events
EventVat uses <a href="https://github.com/hij1nx/EventEmitter2">EventEmitter</a>. Listeners can attached to an EventVat object. An EventVat object can emit and event and a listener will respond. An event has three characteristics, the event name, a listener and an associated data key or wildcard.
-### Key based events
-
```javascript
var vat = EventVat();
- vat.on('get foo', function(key, value) {
- console.log('getting: ', key, value);
+ vat.on('get foo', function(key, value)
+
+
+ console.log('`' + key + '` has the value: `' + value + '`');
});
- demo.get('foo');
+ vat.set('foo', 'hello, world');
+ vat.get('foo');
```
-### Wildcard events
+# API
-```javascript
- var vat = EventVat();
+## instance methods
- vat.on('get foo', function(key, value) {
- console.log('getting: ', key, value);
- });
+### publish()
+Synonymous with `EventEmitter2.prototype.emit`
- vat.get('foo');
-```
+### subscribe()
+Synonymous with `EventEmitter2.prototype.on`
+
+### unsubscribe()
+Synonymous with `EventEmitter2.prototype.removeListener`
+
+### die(key)
+Expire a key
+
+### del(key /* ... */)
+Delete a key
+
+### exists(key)
+Determine if a key exists
+
+### expire(key, ttl)
+Set a key's time to live in seconds
+
+### expireat(key, dueDate)
+Set the expiration for a key as a UNIX timestamp
+
+### keys(regex)
+Find all keys matching the given pattern
+
+### move(key, db)
+Move a key to another database
+
+### object(subcommend /* ... */)
+Inspect the internals of an object
+
+### persist(key)
+Remove the expiration from a key
+
+### randomkey()
+Return a random key from the keyspace
+
+### rename(oldKey, newKey)
+Rename a key
+
+### renamenx(oldKey, newKey)
+Rename a key, only if the new key does not exist
+
+### sort()
+Sort the elements in a list, set or sorted set
+
+### type(key)
+Determine the type stored at key
+
+### ttl(key)
+Get the time to live for a key
+
+### append(key, value)
+Append a value to a key
+
+### decr(key)
+Decrement the integer value of a key by one
+
+### decrby(key, value)
+Decrement the integer value of a key by the given number
+
+### get(key)
+Get the value of a key
+
+### getbit(key)
+Returns the bit value at offset in the string value stored at key
+
+### getrange(key, start, end)
+Get a substring of the string stored at a key
+
+### getset(key, value)
+Set the string value of a key and return its old value
+
+### incr(key)
+Increment the integer value of a key by one
+
+### incrby(key, value)
+Increment the integer value of a key by the given number
+
+### mget(key /* ... */)
+Get the values of all the given keys
+
+### mset(keys /* ... */, values /* ... */)
+Set multiple keys to multiple values
+
+### msetnx(keys /* ... */, values /* ... */)
+Set multiple keys to multiple values, only if none of the keys exist
+
+### set(key, value, ttl)
+Set the string value of a key
+
+### setbit(key, offset, value)
+Sets or clears the bit at offset in the string value stored at key
+
+### setex(key, seconds, value)
+Set the value and expiration of a key
+
+### setnx(key, value, ttl)
+Set the value of a key, only if the key does not exist
+
+### setrange(key, offset, value)
+Overwrite part of a string at key starting at the specified offset
+
+### strlen(key)
+Get the length of the value stored in a key
+
+### hdel(key, field /* ... */)
+Delete one or more hash fields
+
+### hexists(key, field)
+Determine if a hash field exists
+
+### hget(key, field)
+Get the value of a hash field
+
+### hgetall(key)
+Get all the fields and values in a hash
+
+### hincr(key, field)
+Increment the integer value of a hash field by one
+
+### hincrby(key, field, value)
+Increment the integer value of a hash field by the given number
+
+### hdecr(key, field)
+Decrement the integer value of a hash field by one
+
+### hdecrby(key, field, value)
+Decrement the integer value of a hash field by the given number
+
+### hkeys(key)
+Get all the fields in a hash
+
+### hlen(key)
+Get the number of fields in a hash
+
+### hmget(key, field /* ... */)
+Get the values of all the given hash fields
+
+### hmset(key, fields /* ... */, values /* ... */)
+Set multiple hash fields to multiple values
+
+### hset(key, field, value)
+Set the string value of a hash field
+
+### hsetnx(key, field, value /* ... */)
+Set the value of a hash field, only if the field does not exist
+
+### hvals(key)
+Get all the values in a hash
+
+### dump(stringify)
+Dump the current data store into a string
+
+### swap(a, b, depth)
+Swap two values
+
+### findin(key, value)
+Search within the value of a key
# Tests
@@ -62,4 +216,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE DBSIZEORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
210 lib/eventvat.js
@@ -21,7 +21,7 @@
//
function has(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
- };
+ }
EventVat = module.exports = function EventVat(conf) {
@@ -32,19 +32,21 @@
this.hash = conf && conf.data || {};
};
+ var p = EventVat.prototype;
+
for (var member in EventEmitter2.prototype) {
- EventVat.prototype[member] = EventEmitter2.prototype[member];
+ p[member] = EventEmitter2.prototype[member];
}
- EventVat.prototype.publish = EventEmitter2.prototype.emit;
- EventVat.prototype.subscribe = EventEmitter2.prototype.on;
- EventVat.prototype.unsubscribe = EventEmitter2.prototype.removeListener;
+ p.publish = EventEmitter2.prototype.emit;
+ p.subscribe = EventEmitter2.prototype.on;
+ p.unsubscribe = EventEmitter2.prototype.removeListener;
- EventVat.prototype.die = function(key) {
- for (var key in this.hash) {
- if (has(this.hash, key)) {
- if (this.hash[key].tid) {
- clearTimeout(this.hash[key].tid);
+ p.die = function(key) {
+ for (var k in this.hash) {
+ if (has(this.hash, k)) {
+ if (this.hash[k].tid) {
+ clearTimeout(this.hash[k].tid);
}
}
}
@@ -56,7 +58,7 @@
//
// Delete a key
//
- EventVat.prototype.del = function(key /* ... */) {
+ p.del = function(key /* ... */) {
var n = 0;
for (var i = 0, l = arguments.length; i < l; i++) {
@@ -76,7 +78,7 @@
//
// Determine if a key exists
//
- EventVat.prototype.exists = function(key) {
+ p.exists = function(key) {
var exists = has(this.hash, key);
this.emit('exists ' + key, exists);
this.emit('exists', key, exists);
@@ -86,7 +88,7 @@
//
// Set a key's time to live in seconds
//
- EventVat.prototype.expire = function(key, ttl) {
+ p.expire = function(key, ttl) {
if (has(this.hash, key) && typeof ttl === 'number' && ttl > -1) {
if (this.hash[key].tid) {
@@ -113,7 +115,7 @@
//
// Set the expiration for a key as a UNIX timestamp
//
- EventVat.prototype.expireat = function(key, dueDate) {
+ p.expireat = function(key, dueDate) {
var ttl = dueDate - (Math.round(new Date() / 1000));
var rs = this.expire(key, ttl);
@@ -128,7 +130,7 @@
//
// Find all keys matching the given pattern
//
- EventVat.prototype.keys = function(regex) {
+ p.keys = function(regex) {
var keys = [];
for(var k in this.hash) {
@@ -144,7 +146,7 @@
//
// Move a key to another database
//
- EventVat.prototype.move = function(key, db) {
+ p.move = function(key, db) {
if(db && db.hash) {
this.persist(key);
db.hash[key] = this.hash[key];
@@ -154,19 +156,19 @@
return true;
}
return false;
- }
+ };
//
// Inspect the internals of EventVat objects
//
- EventVat.prototype.object = function(subcommend /* ... */) {
+ p.object = function(subcommend /* ... */) {
throw new Error('Not implemented.');
};
//
// Remove the expiration from a key
//
- EventVat.prototype.persist = function(key) {
+ p.persist = function(key) {
if(has(this.hash, key) && this.hash[key].tid) {
clearTimeout(this.hash[key].tid);
delete this.hash[key].tid;
@@ -183,7 +185,7 @@
//
// Return a random key from the keyspace
//
- EventVat.prototype.randomkey = function() {
+ p.randomkey = function() {
var keys = this.keys(/^/);
var index = Math.floor(Math.random()*keys.length);
var key = keys[index] || null;
@@ -194,7 +196,7 @@
//
// Rename a key
//
- EventVat.prototype.rename = function(oldKey, newKey) {
+ p.rename = function(oldKey, newKey) {
if(has(this.hash, oldKey)) {
this.persist(oldKey);
this.persist(newKey);
@@ -212,7 +214,7 @@
//
// Rename a key, only if the new key does not exist
//
- EventVat.prototype.renamenx = function(oldKey, newKey) {
+ p.renamenx = function(oldKey, newKey) {
if(has(this.hash, oldKey) && !has(this.hash, newKey)) {
this.persist(oldKey);
this.hash[newKey] = this.hash[oldKey];
@@ -228,7 +230,7 @@
//
// Sort key by pattern
//
- EventVat.prototype.sort = function() {
+ p.sort = function() {
throw new Error('Not implemented.');
// fast javascript sort...
@@ -242,7 +244,7 @@
//
// Determine the type stored at key
//
- EventVat.prototype.type = function(key) {
+ p.type = function(key) {
if (has(this.hash, key)) {
var value = this.hash[key].value;
var type = typeof value;
@@ -262,7 +264,7 @@
//
// Get the time to live for a key
//
- EventVat.prototype.ttl = function(key) {
+ p.ttl = function(key) {
var ttl = has(this.hash, key) && this.hash[key].tid
? Math.round((this.hash[key].tend - new Date()) / 1000)
: -1;
@@ -278,7 +280,7 @@
//
// Append a value to a key
//
- EventVat.prototype.append = function(key, value) {
+ p.append = function(key, value) {
var type = this.type(key);
if (type === 'none') {
this.hash[key] = { value: '' };
@@ -298,7 +300,7 @@
//
// Decrement the integer value of a key by one
//
- EventVat.prototype.decr = function(key) {
+ p.decr = function(key) {
var value = this.decrby(key, 1);
if (value !== false) {
this.emit('decr ' + key, value);
@@ -310,7 +312,7 @@
//
// Decrement the integer value of a key by N
//
- EventVat.prototype.decrby = function(key, value) {
+ p.decrby = function(key, value) {
if (!has(this.hash, key)) {
this.hash[key] = { value: 0 };
} else if (this.type(key) !== 'number') {
@@ -327,32 +329,52 @@
//
// Get the value of a key
//
- EventVat.prototype.get = function(key) {
+ p.get = function(key) {
- var newValue;
+ var newValue = null;
if(has(this.hash, key)) {
- var newValue = this.hash[key].value;
+ newValue = this.hash[key].value;
this.emit('get ' + key, newValue);
this.emit('get', key, newValue);
- return newValue;
}
- else {
- return null;
+
+ return newValue;
+
+ };
+
+ p.getDel = function (key) {
+ var newValue = p.get(key);
+ p.del(key);
+ this.emit('getdel ' + key, newValue);
+ this.emit('getdel', key, newValue);
+ };
+
+ p.gettime = function() {
+
+ var newValue = null;
+
+ if(has(this.hash, key)) {
+ newValue = this.hash[key].time;
+ this.emit('gettime ' + key, newValue);
+ this.emit('gettime', key, newValue);
}
+
+ return newValue;
+
};
//
// Returns the bit value at offset in the string value stored at key
//
- EventVat.prototype.getbit = function(key) {
+ p.getbit = function(key) {
throw new Error('Not implemented.');
};
//
// Get a substring of the string stored at a key
//
- EventVat.prototype.getrange = function(key, start, end) {
+ p.getrange = function(key, start, end) {
if (this.type(key) === 'string') {
var value = this.hash[key].value.slice(start, end);
this.emit('getrange ' + key, start, end, value);
@@ -366,7 +388,7 @@
//
// Set the string value of a key and return its old value
//
- EventVat.prototype.getset = function(key, value) {
+ p.getset = function(key, value) {
var old = this.get(key);
this.set(key, value);
this.emit('getset ' + key, value, old);
@@ -377,7 +399,7 @@
//
// Increment the integer value of a key by one
//
- EventVat.prototype.incr = function(key) {
+ p.incr = function(key) {
var value = this.incrby(key, 1);
if (value !== false) {
this.emit('incr ' + key, value);
@@ -389,7 +411,7 @@
//
// Increment the integer value of a key by the given number
//
- EventVat.prototype.incrby = function(key, value) {
+ p.incrby = function(key, value) {
value = +value;
if (!has(this.hash, key)) {
@@ -408,7 +430,7 @@
//
// Get the values of all the given keys
//
- EventVat.prototype.mget = function(key /* ... */) {
+ p.mget = function(key /* ... */) {
var keys = Array.prototype.slice.call(arguments);
var values = [];
@@ -425,7 +447,7 @@
//
// Set multiple keys to multiple values
//
- EventVat.prototype.mset = function(keys /* ... */, values /* ... */) {
+ p.mset = function(keys /* ... */, values /* ... */) {
var key, value;
for(var i=0, l=arguments.length; i < l; i += 2) {
@@ -442,15 +464,15 @@
}
// set events must be emitted after keys are updated
- for(var i=0, l=arguments.length; i < l; i += 2) {
+ for(i=0, l=arguments.length; i < l; i += 2) {
key = arguments[i];
value = arguments[i + 1];
this.emit('set ' + key, value);
this.emit('set', key, value);
}
- var args = Array.prototype.slice.call(arguments)
+ var args = Array.prototype.slice.call(arguments);
args.unshift('mset');
this.emit.apply(this, args);
return true;
@@ -459,7 +481,7 @@
//
// Set multiple keys to multiple values, only if none of the keys exist
//
- EventVat.prototype.msetnx = function(keys /* ... */, values /* ... */) {
+ p.msetnx = function(keys /* ... */, values /* ... */) {
var key, value;
for(var i=0, l=arguments.length; i < l; i += 2) {
@@ -468,7 +490,7 @@
}
}
- for(var i=0, l=arguments.length; i < l; i += 2) {
+ for(i=0, l=arguments.length; i < l; i += 2) {
key = arguments[i];
value = arguments[i + 1];
@@ -477,7 +499,7 @@
}
}
- for(var i=0, l=arguments.length; i < l; i += 2) {
+ for(i=0, l=arguments.length; i < l; i += 2) {
key = arguments[i];
value = arguments[i + 1];
@@ -487,7 +509,7 @@
this.emit('setnx', key, value);
}
- var args = Array.prototype.slice.call(arguments)
+ var args = Array.prototype.slice.call(arguments);
args.unshift('msetnx');
this.emit.apply(this, args);
return true;
@@ -496,7 +518,7 @@
//
// Set the string value of a key
//
- EventVat.prototype.set = function(key, value, ttl) {
+ p.set = function(key, value, ttl) {
var that = this;
if(has(this.hash, key)) {
@@ -507,6 +529,8 @@
this.hash[key] = { value: value };
}
+ this.hash[key].time = Date.now().toString();
+
this.persist(key);
this.expire(key, ttl);
this.emit('set ' + key, value);
@@ -517,21 +541,21 @@
//
// Sets or clears the bit at offset in the string value stored at key
//
- EventVat.prototype.setbit = function(key, offset, value) {
+ p.setbit = function(key, offset, value) {
throw new Error('Not implemented.');
};
//
// Set the value and expiration of a key
//
- EventVat.prototype.setex = function(key, seconds, value) {
+ p.setex = function(key, seconds, value) {
throw new Error('Not implemented.');
};
//
// Set the value of a key, only if the key does not exist
//
- EventVat.prototype.setnx = function(key, value, ttl) {
+ p.setnx = function(key, value, ttl) {
if(!has(this.hash, key)) {
this.set(key, value, ttl);
this.emit('setnx ' + key, value);
@@ -546,7 +570,7 @@
//
// Set the value of a string within the given range
//
- EventVat.prototype.setrange = function(key, offset, value) {
+ p.setrange = function(key, offset, value) {
if (this.type(key) === 'string') {
var p1 = this.hash[key].value.slice(0, offset);
var p2 = this.hash[key].value.slice(offset + value.length);
@@ -567,7 +591,7 @@
//
// Get the length of the value stored in a key
//
- EventVat.prototype.strlen = function(key) {
+ p.strlen = function(key) {
if(this.type(key) === 'string') {
var l = this.hash[key].value.length;
this.emit('strlen ' + key, l);
@@ -585,7 +609,7 @@
//
// delete one or more hash fields
//
- EventVat.prototype.hdel = function(key, field /* ... */) {
+ p.hdel = function(key, field /* ... */) {
var n = 0;
if (this.type(key) === 'hash') {
@@ -608,7 +632,7 @@
//
// determine if a hash field exists
//
- EventVat.prototype.hexists = function(key, field) {
+ p.hexists = function(key, field) {
var e = this.type(key) === 'hash' && has(this.hash[key].value, field);
this.emit('hexists ' + key, field, e);
this.emit('hexists', key, field, e);
@@ -618,7 +642,7 @@
//
// get the value of a hash field.
//
- EventVat.prototype.hget = function(key, field) {
+ p.hget = function(key, field) {
if(this.type(key) === 'hash' && has(this.hash[key].value, field)) {
var value = this.hash[key].value[field];
this.emit('hget ' + key, field, value);
@@ -633,7 +657,7 @@
//
// get all the fields and values in a hash
//
- EventVat.prototype.hgetall = function(key) {
+ p.hgetall = function(key) {
var hash = this.type(key) === 'hash' ? this.hash[key].value : {};
this.emit('hgetall ' + key, hash);
this.emit('hgetall', key, hash);
@@ -643,7 +667,7 @@
//
// increment the integer value of a hash field by 1
//
- EventVat.prototype.hincr = function(key, field) {
+ p.hincr = function(key, field) {
var value = this.hincrby(key, field, 1);
if (value !== false) {
this.emit('hincr ' + key, field, value);
@@ -655,7 +679,7 @@
//
// increment the integer value of a hash field by the given number
//
- EventVat.prototype.hincrby = function(key, field, value) {
+ p.hincrby = function(key, field, value) {
value = +value;
var type = this.type(key);
@@ -680,7 +704,7 @@
//
// decrement the integer value of a hash field by 1
//
- EventVat.prototype.hdecr = function(key, field) {
+ p.hdecr = function(key, field) {
var value = this.hdecrby(key, field, 1);
if (value !== false) {
this.emit('hdecr ' + key, field, value);
@@ -692,7 +716,7 @@
//
// decrement the integer value of a hash field by the given number
//
- EventVat.prototype.hdecrby = function(key, field, value) {
+ p.hdecrby = function(key, field, value) {
value = +value;
var type = this.type(key);
@@ -719,7 +743,7 @@
//
// get all the fields in a hash
//
- EventVat.prototype.hkeys = function(key) {
+ p.hkeys = function(key) {
var fields = [];
if (this.type(key) === 'hash') {
@@ -739,7 +763,7 @@
//
// get the number of fields in a hash
//
- EventVat.prototype.hlen = function(key) {
+ p.hlen = function(key) {
var len = 0;
if (this.type(key) === 'hash') {
@@ -759,7 +783,7 @@
//
// get the values of all the given hash fields
//
- EventVat.prototype.hmget = function(key, field /* ... */) {
+ p.hmget = function(key, field /* ... */) {
var values = [];
for(var i=1, l=arguments.length; i < l; i++) {
@@ -774,7 +798,7 @@
//
// set multiple hash fields to multiple values
//
- EventVat.prototype.hmset = function(key, fields /* ... */, values /* ... */) {
+ p.hmset = function(key, fields /* ... */, values /* ... */) {
var type = this.type(key);
if (type === 'none') {
this.hash[key] = { value: {}, type: 'hash' };
@@ -790,15 +814,15 @@
// set events must be emitted after keys are updated
var field, value;
- for(var i=1, l=arguments.length; i < l; i += 2) {
+ for(i=1, l=arguments.length; i < l; i += 2) {
field = arguments[i];
value = arguments[i + 1];
this.emit('hset ' + key, field, value);
this.emit('hset', key, field, value);
}
- var args = Array.prototype.slice.call(arguments)
+ var args = Array.prototype.slice.call(arguments);
this.emit.apply(this, ['hmset ' + key].concat(args.slice(1)));
this.emit.apply(this, ['hmset'].concat(args));
return true;
@@ -807,7 +831,7 @@
//
// set the string value of a hash field
//
- EventVat.prototype.hset = function(key, field, value) {
+ p.hset = function(key, field, value) {
var update;
var type = this.type(key);
if (type === 'none') {
@@ -830,7 +854,7 @@
//
// Set the value of a hash field, only if the field does not exist
//
- EventVat.prototype.hsetnx = function(key, field, value /* ... */) {
+ p.hsetnx = function(key, field, value /* ... */) {
var type = this.type(key);
if (type === 'none') {
this.hash[key] = { value: {}, type: 'hash' };
@@ -853,7 +877,7 @@
//
// get all the values in a hash
//
- EventVat.prototype.hvals = function(key) {
+ p.hvals = function(key) {
var values = [];
if (this.type(key) === 'hash') {
@@ -878,7 +902,7 @@
//
// Get an element from a list by its index
//
- EventVat.prototype.lindex = function(key, index) {
+ p.lindex = function(key, index) {
if (this.type(key) === 'list') {
var list = this.hash[key].value;
var len = list.length;
@@ -902,14 +926,14 @@
//
// Insert an element before or after another element in a list
//
- EventVat.prototype.linsert = function(key, ba, pivot, value) {
+ p.linsert = function(key, ba, pivot, value) {
throw new Error('Not implemented.');
};
//
// Get the length of a list
//
- EventVat.prototype.llen = function(key) {
+ p.llen = function(key) {
var type = this.type(key);
if (type === 'none') {
return false;
@@ -924,7 +948,7 @@
//
// Remove and get the first element in a list
//
- EventVat.prototype.lpop = function(key) {
+ p.lpop = function(key) {
if (this.type(key) === 'list') {
this.persist(key);
var value = this.hash[key].value.shift() || null;
@@ -939,7 +963,7 @@
//
// Prepend one or multiple values to a list
//
- EventVat.prototype.lpush = function(key, value /* ... */) {
+ p.lpush = function(key, value /* ... */) {
var type = this.type(key);
var list;
if (type === 'none') {
@@ -965,7 +989,7 @@
//
// Prepend a value to a list, only if the list exists
//
- EventVat.prototype.lpushx = function(key, value) {
+ p.lpushx = function(key, value) {
if (this.type(key) === 'list') {
var len = this.hash[key].value.unshift(value);
this.emit('lpushx ' + key, value, len);
@@ -979,9 +1003,9 @@
//
// Get a range of elements from a list
//
- EventVat.prototype.lrange = function(key, start, stop) {
+ p.lrange = function(key, start, stop) {
var range = this.type(key) === 'list'
- ? this.hash[key].value.slice(start, stop) : []
+ ? this.hash[key].value.slice(start, stop) : [];
this.emit('lrange ' + key, start, stop, range);
this.emit('lrange', key, start, stop, range);
@@ -991,7 +1015,7 @@
//
// Remove elements from a list
//
- EventVat.prototype.lrem = function(key, count, value) {
+ p.lrem = function(key, count, value) {
if (this.type(key) === 'list') {
this.persist(key);
var list = this.hash[key].value;
@@ -1001,7 +1025,7 @@
// if count is positive, list will be traversed from 0 to list.length
if (ncount >= 0) {
i = 0;
- check = function() { return i < list.length };
+ check = function() { return i < list.lengthl; };
incr = function() { i++; };
cancel = function() { i--; };
@@ -1041,7 +1065,7 @@
//
// Set the value of an element in a list by its index
//
- EventVat.prototype.lset = function(key, index, value) {
+ p.lset = function(key, index, value) {
if (this.type(key) === 'list') {
this.persist(key);
var list = this.hash[key].value;
@@ -1066,7 +1090,7 @@
//
// Trim a list to the specified range
//
- EventVat.prototype.ltrim = function(key, start, stop) {
+ p.ltrim = function(key, start, stop) {
if (this.type(key) === 'list') {
this.persist(key);
this.hash[key].value = this.hash[key].value.slice(start, stop);
@@ -1081,7 +1105,7 @@
//
// Remove and get the last element in a list
//
- EventVat.prototype.rpop = function(key) {
+ p.rpop = function(key) {
if (this.type(key) === 'list') {
this.persist(key);
var value = this.hash[key].value.pop() || null;
@@ -1096,7 +1120,7 @@
//
// Remove the last element in a list, append it to another list and return it
//
- EventVat.prototype.rpoplpush = function(source, destination) {
+ p.rpoplpush = function(source, destination) {
if (this.type(source) === 'list') {
var dtype = this.type(destination);
var dest;
@@ -1129,7 +1153,7 @@
//
// Append one or multiple values to a list
//
- EventVat.prototype.rpush = function(key, value /* ... */ ) {
+ p.rpush = function(key, value /* ... */ ) {
var type = this.type(key);
var list;
if (type === 'none') {
@@ -1155,7 +1179,7 @@
//
// Append a value to a list, only if the list exists
//
- EventVat.prototype.rpushx = function(key, value) {
+ p.rpushx = function(key, value) {
if (this.type(key) === 'list') {
var len = this.hash[key].value.push(value);
this.emit('rpushx ' + key, value, len);
@@ -1171,7 +1195,7 @@
// Non stsandard methods.
//
//
- EventVat.prototype.dump = function(stringify) {
+ p.dump = function(stringify) {
var dump = {};
@@ -1190,7 +1214,7 @@
//
// swap the values of two keys
//
- EventVat.prototype.swap = function(a, b, depth) {
+ p.swap = function(a, b, depth) {
if(has(this.hash, a) && has(this.hash, b)) {
var av = this.hash[a];
@@ -1219,9 +1243,9 @@
//
// check if a value is in a key
//
- EventVat.prototype.findin = function(key, value) {
+ p.findin = function(key, value) {
if(has(this.hash, key)) {
- var index = this.hash[key].value.indexOf(value)
+ var index = this.hash[key].value.indexOf(value);
this.emit('findin ' + key, value, index);
this.emit('findin', key, value, index);
return index;
@@ -1231,9 +1255,5 @@
}
};
- //
- // set the current revision
- //
-
-}((typeof process !== 'undefined' && process.title) ? module : window));
+}((typeof process !== 'undefined' && typeof process.title !== 'undefined') ? module : window));
View
2 package.json
@@ -1,6 +1,6 @@
{
"name" : "eventvat",
- "version" : "0.1.3",
+ "version" : "0.1.8",
"description" : "Evented, in-process key/value store for Node.js and the browser",
"main" : "./lib/eventvat.js",
"directories" : {

0 comments on commit 274e4bd

Please sign in to comment.