Socket
Socket
Sign inDemoInstall

bx

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bx - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

6

lib/bx.js

@@ -61,3 +61,3 @@ var tv = require('tv4');

'| | |',
'| | Bx |',
'| | bx |',
'~_ | |',

@@ -140,3 +140,3 @@ ' ~_ | __|',

*
* @param {array} keys Keys
* @param {Array} keys Keys
*/

@@ -169,3 +169,3 @@ Bx.prototype.mget = function(keys) {

*
* @param {array} keys Keys
* @param {Array} keys Keys
*/

@@ -172,0 +172,0 @@ Bx.prototype.mdel = function(keys) {

{
"name": "bx",
"version": "0.2.0",
"version": "0.2.1",
"description": "in-memory storage for node",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -45,17 +45,267 @@ # bx

The code is pretty simple and well-commented, but here's an overview and example use for each function. All examples assume that a bx has
been required as 'bx'.
The code is pretty simple and well-commented, but here's an overview and example usage for each function. All examples assume that a bx has
been required as 'bx'. For more, feel free to look through the test suite as well.
#### *Bx(opts)*
Create a new data store.
*Arguments*
* opts {object} - options
* debug {boolean} - enable / disable logging
* schema {object} - JSON schema to check against
*Example*
var box = new bx(); //no debug & no schema
var people = new bx({ //debug & schema
debug: true,
schema: {
title: "people",
type: "object",
required: ["name", "age", "job"],
properties: {
name: {
type: "string"
},
age: {
type: "number"
},
job: {
type: "string"
}
}
}
});
var stuff = new bx({ debug: true }); //debug & no schema
#### *put(key, val, time)*
Add an object to the data store and specify how long it will live.
*Arguments*
* key {string} - key
* val {?} - value
* time {number=} - optional expiration time (in ms)
*Example*
var box = new bx();
box.put('bob', {
name: "Bob Johnson",
hometown: "Boston, MA",
age: 24
}, 2000); //will die in 2 seconds
box.put('color', 'red'); //this will live until manually deleted
setTimeout(function() {
console.log(box.get('bob')); //object
console.log(box.get('color')); //"red"
}, 1000);
setTimeout(function() {
console.log(box.get('bob')); //undefined
console.log(box.get('color')); //"red"
}, 3000);
#### *get(key)*
Retrieve data from the data store if the key exists.
*Arguments*
* key {string} - key
*Example*
var box = new bx();
box.put('name', 'Ty');
box.get('name'); //"Ty"
box.get(); //undefined
box.get('oops'); //undefined
#### *mget(keys)*
Get multiple values from the data store.
*Arguments*
* keys {Array} - Array of keys
*Example*
var box = new bx();
box.put('apple1', 'gala');
box.put('apple2', 'granny smith');
var food = box.mget([
'apple1',
'apple2'
]);
console.log(food); //{ 'apple1': 'gala', 'apple2': 'granny smith' }
#### *del(key)*
Delete a key from the data store.
*Arguments*
* key {string} - Key to delete
*Example*
var box = new bx();
box.put('salary', 0);
var a = box.get('salary'); //0
box.del('salary');
var b = box.get('salary'); //undefined
#### *mdel(keys)*
Delete keys from the data store.
*Arguments*
* keys {Array} - Keys to delete
*Example*
var box = new bx();
var keys = ['a', 'b', 'c'];
for (var i in keys) {
box.put(keys[i], i);
}
box.mdel(['a', 'b', 'c']);
var all = box.mget(['a', 'b', 'c']); //{}
#### *clear*
Clear the data store.
*Example*
var box = new bx({
schema: {
"title": "fruits",
"type": "array"
}
});
box.put('apples', ['gala', 'granny smith', 'red delicious']);
box.put('berries', ['blueberries', 'strawberries']);
box.clear();
var blah = box.get('apples'); //undefined
#### *all*
Get entire data store.
*Example*
var box = new bx();
box.put('a', 'a'.charCodeAt(0));
box.put('b', 'banana');
box.put('me', {
'name': 'Ty',
'age': 19
});
var all = box.all(); //{object (a, b, me)}
#### *keys*
Get an array of the keys in the data store.
*Example*
var box = new bx();
box.put('snoop', 'dogg');
box.put('kanye', 'west');
box.put('dr', 'dre');
var k = box.keys(); //['snoop', 'kanye', 'dr']
#### *vals*
Get an array of the values in the data store.
*Example*
var box = new bx();
box.put('snoop', 'dogg');
box.put('kanye', 'west');
box.put('dr', 'dre');
var v = box.vals(); //['dogg', 'west', 'dre']
#### *len*
Get the number of items stored.
*Example*
var box = new bx();
console.log(box.len()); //0
box.put('a', 0);
console.log(box.len()); //1
#### *size*
Get the length in bytes of the data store.
*Example*
var box = new bx();
console.log(box.size()); //2
box.put('a', 'b');
console.log(box.size()); //19
box.clear();
console.log(box.size()); //2
#### *exp(key)*
Get the time of deletion for a key.
*Arguments*
* key {string} - Key to check
*Example*
var box = new bx();
box.put('a', 0);
box.put('b', 1, 2000);
console.log(box.exp('a')); //undefined
console.log(box.exp('b')); //{2000 + time of creation}

@@ -7,3 +7,3 @@ # To-Do

* Fill in API docs
* Add hit and miss logging, other stats
* Better logging and more stats
* Add a "fits" function to check if an item fits the schema before a put
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