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

lokijs

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lokijs - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

benchmark/benchmark.js

62

examples/example.js

@@ -8,3 +8,3 @@ window.runExample = function(){

// create two example collections
var users = db.addCollection('users','User', ['email']);
var users = db.addCollection('users','User', ['email'], true);
var projects = db.addCollection('projects', 'Project', ['name']);

@@ -16,9 +16,9 @@

// create two users
var odin = users.document( { name : 'odin', email: 'odin.soap@lokijs.com', age: 38 } );
var thor = users.document( { name : 'thor', email : 'thor.soap@lokijs.com', age: 25 } );
var stan = users.document( { name : 'stan', email : 'stan.soap@lokijs.com', age: 29 } );
var oliver = users.document( { name : 'oliver', email : 'oliver.soap@lokijs.com', age: 31 } );
var hector = users.document( { name : 'hector', email : 'hector.soap@lokijs.com', age: 15} );
var achilles = users.document( { name : 'achilles', email : 'achilles.soap@lokijs.com', age: 31 } );
// create six users
var odin = users.document( { name : 'odin', email: 'odin.soap@lokijs.org', age: 38 } );
var thor = users.document( { name : 'thor', email : 'thor.soap@lokijs.org', age: 25 } );
var stan = users.document( { name : 'stan', email : 'stan.soap@lokijs.org', age: 29 } );
var oliver = users.document( { name : 'oliver', email : 'oliver.soap@lokijs.org', age: 31 } );
var hector = users.document( { name : 'hector', email : 'hector.soap@lokijs.org', age: 15} );
var achilles = users.document( { name : 'achilles', email : 'achilles.soap@lokijs.org', age: 31 } );

@@ -32,3 +32,3 @@

stan.name = 'Joe Minichino';
stan.name = 'Stan Laurel';

@@ -49,12 +49,14 @@ // update object (this really only syncs the index)

// test the filters
trace('View test');
trace('Example: View "Age" test');
trace(users.view(ageView));
trace('End view test');
sep();
trace('Custom filter');
trace('Example: Custom filter test');
trace(users.view(aCustomFilter));
trace('End of custom filter');
sep();
// example of map reduce
trace('Map-reduce...');
trace('Example: Map-reduce');
function mapFun(obj){

@@ -64,15 +66,33 @@ return obj.age;

function reduceFun(array){
var len = array.length >>> 0;
var i = len;
var cumulator = 0;
while(i--){
cumulator += array[i];
}
return cumulator / len;
var len = array.length >>> 0;
var i = len;
var cumulator = 0;
while(i--){
cumulator += array[i];
}
return cumulator / len;
}
trace('Average age is : ' + users.mapReduce( mapFun, reduceFun).toFixed(2) );
trace('End of map-reduce');
sep();
trace('End of map-reduce...');
trace('Example: stringify');
trace('String representation : ' + db.serialize());
trace('End stringify example');
sep();
trace('Example: findAndModify');
function updateAge(obj){
obj.age *= 2;
return obj;
}
users.findAndModify(ageView, updateAge);
trace(users.find());
trace('End findAndModify example');
function sep(){
trace('//---------------------------------------------//');
}
} catch(err){

@@ -79,0 +99,0 @@ console.log(err);

{
"name": "lokijs",
"version": "0.0.1",
"version": "0.0.2",
"description": "A document oriented javascript client side database",
"main": "src/LokiJS.js",
"main": "src/lokijs.js",
"directories": {

@@ -7,0 +7,0 @@ "example": "examples"

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