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

life-db

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

life-db - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

life-db-min.js

@@ -1,1 +0,1 @@

var LifeDB=function(){var e,n,t,i,r,o,f,s,u,a,d,c,p,y,g,m,N,h,S,v,l,b,D,O,J,E,B,q,w;this.initiate,this.insert,this.update,this.find,this.remove,this.destroy,i={dbNameNotSpecified:"Database name mast have to provide in time of initiating the database",pageNameCannotBeEmpty:"Page name required",pageDoesnotExists:"Provided page doesn't exists"},N=["@eq","@lt","@gt","@le","@ge"],O=function(e,t,i){var r,o,f,s,u,a;o=B(e),r=B(e,t),u=[];for(f in o){a=0;for(s in r)if(JSON.stringify(o[f])==JSON.stringify(r[s])){a=1;break}a?u.push(i):u.push(o[f])}return n(e,u,!0),r.length},D=function(e,t){var i,r,o,f,s,u;r=B(e),i=B(e,t),s=[];for(o in r){u=0;for(f in i)if(JSON.stringify(r[o])==JSON.stringify(i[f])){u=1;break}u||s.push(r[o])}return n(e,s,!0),i.length},h=function(e,n,t){return"undefined"==typeof e[n]?!1:JSON.stringify(e[n])==JSON.stringify(t)},S=function(e,n,t){return"undefined"==typeof e[n]?!1:isNaN(e[n])?!1:e[n]>t},l=function(e,n,t){return"undefined"==typeof e[n]?!1:isNaN(e[n])?!1:e[n]>=t},v=function(e,n,t){return"undefined"==typeof e[n]?!1:isNaN(e[n])?!1:e[n]<t},b=function(e,n,t){return"undefined"==typeof e[n]?!1:isNaN(e[n])?!1:e[n]<=t},y=function(e){return u[e]},m=function(e,n){var t,i,r;for(i in N)if(-1!==n.indexOf(N[i])){t=N[i];break}switch(r=n.split(" "+t+" "),t){case"@eq":return h(e,r[0],r[1]);case"@gt":return S(e,r[0],r[1]);case"@lt":return v(e,r[0],r[1]);case"@ge":return l(e,r[0],r[1]);case"@le":return b(e,r[0],r[1])}},g=function(e,n){var t,i,r,o;t=n.split(" || "),o=[];for(r in e)for(i in t)if(m(e[r],t[i])){o.push(e[r]);break}return o},chopDataByLimit=function(e,n){var t,i;t=[];for(i in e)if(!(i<n[0])){if(i>n[1])break;t.push(e[i])}return t},sortData=function(e,n,t){return"asc"===n?e.sort(function(e,n){return Number(e[t])-Number(n[t])}):e.sort(function(e,n){return Number(n[t])-Number(e[t])})},p=function(e,n,t,i){var r,o,f,s;if(r=y(e),"undefined"!=typeof n&&""!==n.trim()){o=n.split(" && ");for(f in o)r=g(r,o[f])}return 0!==t[1]&&(r=chopDataByLimit(r,t)),""!=i[0].trim()&&""!=i[1].trim()&&(s=i[1].trim().toLowerCase(),"asc"!=s&&"desc"!=s||r.length>=1&&!isNaN(Number(r[0][i[0].trim()]))&&(r=sortData(r,s,i[0].trim()))),r},c=function(e){return"undefined"!=typeof u[e]},d=function(){var n;!f&&o?"undefined"==typeof sessionStorage[e]||""!==sessionStorage[e].trim()&&(u=JSON.parse(sessionStorage[e])):f&&(n=require("fs"),n.statSync(e).isFile()&&(u=JSON.parse(n.readFileSync(e))))},n=function(e,n,t){var i;try{if("undefined"==typeof u&&(u={}),"undefined"==typeof u[e]&&(u[e]=[]),"undefined"!=typeof t&&t&&(u[e]=[]),Array.isArray(n)){for(i in n)u[e].push(n[i]);return i}return globallDataStorage[e].push(n),1}catch(r){return 0}},a=function(){var n;!f&&o?sessionStorage[e]=JSON.stringify(u):f&&(n=require("fs"),n.writeFileSync(e,JSON.stringify(u)))},t=function(e){console.error(i[e])},s=function(){f=this!==window},r=function(){"undefined"!=typeof sessionStorage?(o=!0,"undefined"==typeof sessionStorage[e]&&(sessionStorage[e]="")):o=!1},q=function(e,n,i){var r;return""===e.trim()?(t("pageNameCannotBeEmpty"),!1):c(e)?(r=D(e,n),("undefined"==typeof i||i)&&a(),r):(t("pageDoesnotExists"),!1)},J=function(e,t,i){var r;return r=n(e,t),("undefined"==typeof i||i)&&a(),r?r:0},B=function(e,n,i,r){return""===e.trim()?(t("pageNameCannotBeEmpty"),!1):c(e)?("undefined"!=typeof i&&Array.isArray(i)||(i=[0,0]),"undefined"!=typeof r&&Array.isArray(r)||(r=["",""]),p(e,n,i,r)):(t("pageDoesnotExists"),!1)},E=function(e,n,i,r){var o;return""===e.trim()?(t("pageNameCannotBeEmpty"),!1):c(e)?(o=O(e,n,i),("undefined"==typeof r||r)&&a(),o):(t("pageDoesnotExists"),!1)},w=function(e){var n;!f&&o?sessionStorage[e]="":f&&(n=require("fs"),n.writeFileSync(e,""))},this.initiate=function(){return"undefined"==typeof arguments[0][0]?(t("dbNameNotSpecified"),!1):(e=arguments[0][0],"object"!=typeof u&&(u={}),r(),s(),void d())}(arguments),this.insert=function(e,n,t){return J(e,n,t)},this.find=function(e,n,t,i){return B(e,n,t,i)},this.remove=function(e,n,t){return q(e,n,t)},this.update=function(e,n,t,i){return E(e,n,t,i)},this.destroy=function(e){return w(e)}};
var LifeDB=function(){var e,n,t,i,r,o,f,s,u,a,d,c,p,y,g,m,N,h,S,v,l,b,D,O,J,w,E,B,q;this.initiate,this.insert,this.update,this.find,this.remove,this.destroy,i={dbNameNotSpecified:"Database name mast have to provide in time of initiating the database",pageNameCannotBeEmpty:"Page name required",pageDoesnotExists:"Provided page doesn't exists"},N=["@eq","@lt","@gt","@le","@ge"],O=function(e,t,i){var r,o,f,s,u,a;o=E(e),r=E(e,t),u=[];for(f in o){a=0;for(s in r)if(JSON.stringify(o[f])==JSON.stringify(r[s])){a=1;break}a?u.push(i):u.push(o[f])}return n(e,u,!0),r.length},D=function(e,t){var i,r,o,f,s,u;r=E(e),i=E(e,t),s=[];for(o in r){u=0;for(f in i)if(JSON.stringify(r[o])==JSON.stringify(i[f])){u=1;break}u||s.push(r[o])}return n(e,s,!0),i.length},h=function(e,n,t){return"undefined"==typeof e[n]?!1:JSON.stringify(e[n])==JSON.stringify(t)},S=function(e,n,t){return"undefined"==typeof e[n]?!1:isNaN(e[n])?!1:e[n]>t},l=function(e,n,t){return"undefined"==typeof e[n]?!1:isNaN(e[n])?!1:e[n]>=t},v=function(e,n,t){return"undefined"==typeof e[n]?!1:isNaN(e[n])?!1:e[n]<t},b=function(e,n,t){return"undefined"==typeof e[n]?!1:isNaN(e[n])?!1:e[n]<=t},y=function(e){return u[e]},m=function(e,n){var t,i,r;for(i in N)if(-1!==n.indexOf(N[i])){t=N[i];break}switch(r=n.split(" "+t+" "),t){case"@eq":return h(e,r[0],r[1]);case"@gt":return S(e,r[0],r[1]);case"@lt":return v(e,r[0],r[1]);case"@ge":return l(e,r[0],r[1]);case"@le":return b(e,r[0],r[1])}},g=function(e,n){var t,i,r,o;t=n.split(" || "),o=[];for(r in e)for(i in t)if(m(e[r],t[i])){o.push(e[r]);break}return o},chopDataByLimit=function(e,n){var t,i;t=[];for(i in e)if(!(i<n[0])){if(i>n[1])break;t.push(e[i])}return t},sortData=function(e,n,t){return"asc"===n?e.sort(function(e,n){return Number(e[t])-Number(n[t])}):e.sort(function(e,n){return Number(n[t])-Number(e[t])})},p=function(e,n,t,i){var r,o,f,s;if(r=y(e),"undefined"!=typeof n&&""!==n.trim()){o=n.split(" && ");for(f in o)r=g(r,o[f])}return 0!==t[1]&&(r=chopDataByLimit(r,t)),""!=i[0].trim()&&""!=i[1].trim()&&(s=i[1].trim().toLowerCase(),"asc"!=s&&"desc"!=s||r.length>=1&&!isNaN(Number(r[0][i[0].trim()]))&&(r=sortData(r,s,i[0].trim()))),r},c=function(e){return"undefined"!=typeof u[e]},d=function(){var n;if(!f&&o)"undefined"==typeof sessionStorage[e]||""!==sessionStorage[e].trim()&&(u=JSON.parse(sessionStorage[e]));else if(f){n=require("fs");try{u=JSON.parse(n.readFileSync(e))}catch(t){}}},n=function(e,n,t){var i;try{if("undefined"==typeof u&&(u={}),"undefined"==typeof u[e]&&(u[e]=[]),"undefined"!=typeof t&&t&&(u[e]=[]),Array.isArray(n)){for(i in n)u[e].push(n[i]);return i}return globallDataStorage[e].push(n),1}catch(r){return 0}},a=function(){var n;!f&&o?sessionStorage[e]=JSON.stringify(u):f&&(n=require("fs"),n.writeFileSync(e,JSON.stringify(u)))},t=function(e){console.error(i[e])},s=function(){f="undefined"==typeof window||this!==window},r=function(){"undefined"!=typeof sessionStorage?(o=!0,"undefined"==typeof sessionStorage[e]&&(sessionStorage[e]="")):o=!1},B=function(e,n,i){var r;return""===e.trim()?(t("pageNameCannotBeEmpty"),!1):c(e)?(r=D(e,n),("undefined"==typeof i||i)&&a(),r):(t("pageDoesnotExists"),!1)},J=function(e,t,i){var r;return r=n(e,t),("undefined"==typeof i||i)&&a(),r?r:0},E=function(e,n,i,r){return""===e.trim()?(t("pageNameCannotBeEmpty"),!1):c(e)?("undefined"!=typeof i&&Array.isArray(i)||(i=[0,0]),"undefined"!=typeof r&&Array.isArray(r)||(r=["",""]),p(e,n,i,r)):(t("pageDoesnotExists"),!1)},w=function(e,n,i,r){var o;return""===e.trim()?(t("pageNameCannotBeEmpty"),!1):c(e)?(o=O(e,n,i),("undefined"==typeof r||r)&&a(),o):(t("pageDoesnotExists"),!1)},q=function(e){var n;!f&&o?sessionStorage[e]="":f&&(n=require("fs"),n.writeFileSync(e,""))},this.initiate=function(){return"undefined"==typeof arguments[0][0]?(t("dbNameNotSpecified"),!1):(e=arguments[0][0],"object"!=typeof u&&(u={}),r(),s(),void d())}(arguments),this.insert=function(e,n,t){return J(e,n,t)},this.find=function(e,n,t,i){return E(e,n,t,i)},this.remove=function(e,n,t){return B(e,n,t)},this.update=function(e,n,t,i){return w(e,n,t,i)},this.destroy=function(e){return q(e)}};

@@ -465,6 +465,6 @@ var LifeDB = (function() {

fs = require('fs');
if(fs.statSync(databaseName).isFile()) {
globalDataStorage = JSON.parse(fs.readFileSync(databaseName));
} else {
// file not exists so Restore process ignored
try {
globalDataStorage = JSON.parse(fs.readFileSync(databaseName));
} catch(ex) {
// file not exists so ignoring restoration
}

@@ -538,3 +538,3 @@ } else {

checkIfNodeEnvironment = (function() {
if(this===window) {
if(typeof window!="undefined" && this===window) {
isNodeEnvironment = false;

@@ -752,2 +752,2 @@ } else {

});
});
});
{
"name": "life-db",
"version": "0.0.1",
"version": "0.0.2",
"description": "Flat file JSON based database",
"main": "life-db.js",
"main": "life-db-node.js",
"scripts": {

@@ -7,0 +7,0 @@ "test": "echo \"Error: no test specified\" && exit 1"

# LifeDB
### What is LifeDB??
It is a lighweight, JSON based, no-sql formatted data base for browser. The program is intelligent enough to detect the environment where it is running and modify itself for performence.
It is a lighweight, JSON based, no-sql formatted data base for browser and also for node environment. The program is intelligent enough to detect the environment where it is running and modify itself for performence.

@@ -9,5 +9,11 @@ ### How does the DB work??

In node environment the DB works as a flat file database. i.e. the data will be stored in a text file, also user can avoid the storing of data by not backing up the database. If the data file already exists then the data will be restored autometically in time of initiation of the datbase
### Version
0.0.1
0.0.2
### Change log
* Bug fix for node environment
* Bug fix in initiating the database
* Documentation for using in node-environment
### Requirements

@@ -21,3 +27,8 @@ #### For browser environment

#### For node environment
* fs (>=0.0.2)
* node (>=0.10.37) (Developped in this version)
### Installation
#### For browser environment
* Download the **[`Life-db files`](https://github.com/sguha-work/life-db-js/archive/production.zip)**

@@ -27,4 +38,14 @@ * Unzip the archive and copy the file "life-db-min.js"

* Prepare the object of LifeDB (Check **[the usage guide](#usage-guide)** for details).
* Start using the methods and classes available under the **LifeDB** class to generate charts in your project..
* Start using the methods and classes available under the **LifeDB** class to generate charts in your project.
#### For node environment
* Type the following command in your console inside your project folder. **Note: Super user authentication may be needed**
```
npm install life-db
```
* Include life-db in your project's page wher you are going to use life-db (Check **[the usage guide](#usage-guide)** for details).
* Prepare the object of LifeDB (Check **[the usage guide](#usage-guide)** for details).
* Start using the metholds and classes available under the **LifeDB** class to generate charts in your project..
### Usage Guide

@@ -43,2 +64,13 @@ #### For browser environment

#### For node environment
* **Step 1:** Include LifeDB inside your page
```javascript
var ldb = require('life-db');
```
* **Step 2:** Prepare the object of LifeDB with database name
```javascript
var obj = new ldb.LifeDB("my-db");
```
* **Step 4:** Start using methods of LifeDB from the object "obj"
### Function Description

@@ -55,7 +87,12 @@ This section contains the description of the public methods availeble in LifeDB class.

**Usage**
**Usage "Browser"**
```javascript
var ldb = new LifeDB("my-db"); // my-db is the database name
```
**Note:** If previous backed up data exists in sessionStorage the data will be restored autometically in time of initializing the database
**Usage "node"**
```javascript
var ldb = require('life-db'),
obj = new ldb.LifeDB("my-db"); // my-db is the database name
```
**Note:** If previous backed up data exists in sessionStorage or in data file(for Node environment) the data will be restored autometically in time of initializing the database
* **2> insert**

@@ -72,3 +109,3 @@

**Usage**
**Usage "Browser"**
```javascript

@@ -81,2 +118,11 @@ var ldb = new LifeDB("my-db"); // my-db is the database name

```
**Usage "node"**
```javascript
var ldb = require('life-db'),
obj = new ldb.LifeDB("my-db"); // my-db is the database name
// inserting list of records
obj.insert("student", [{name: "angshu", age: 27}, {name: "shyamol", age: 20}, {name: "uttam", age: 30}], true);
// inserting a single record
obj.insert("student", {name: "angshu", age: 27}, true);
```

@@ -98,3 +144,3 @@ **Note:** You can use a insert method from inside a loop to insert multiple data as record format

**Usage**
**Usage "Browser"**
```javascript

@@ -120,3 +166,25 @@ /*

ldb.find("student", "","",["age", "asc"]);
```
```
**Usage "Node"**
```javascript
/*
* Assume that the database "my-db" is created and it holds 1 page named "student" and 3 records as follows
* {name: "angshu", age: 27}, {name: "shyamol", age: 20}, {name: "uttam", age: 30}
*/
// the following query will return all of the records of "student" page
result = obj.find("student", "");
// Following query will return [{name: "angshu", age: 27}]
obj.find("student", "age @eq 27");
// Following query will return []
obj.find("student", "age @gt 27 && age @lt 30");
// Following query will return [{"name":"shyamol","age":20},{"name":"uttam","age":30}]
obj.find("student", "",[1,2]);
// Following query will return ["name":"shyamol","age":20}, {"name":"angshu","age":27}, {"name":"uttam","age":30}]
obj.find("student", "","",["age", "asc"]);
```
**Note:** Check the [operator description](#operator-description) for the supported logical and comparison operators.

@@ -135,3 +203,3 @@

**Usage**
**Usage "Browser"**
```javascript

@@ -146,3 +214,14 @@ /*

```
```
**Usage "Node"**
```javascript
/*
* Assume that the database "my-db" is created and it holds 1 page named "student" and 3 records as follows
* {name: "angshu", age: 27}, {name: "shyamol", age: 20}, {name: "uttam", age: 30}
*/
// the following query will return 1 as 1 record is deleted from the "student" page
obj.remove("student", "name @eq angshu");
```
* **5> update**

@@ -215,1 +294,2 @@

| `life-db.js` | With lots of comment indented code |
| `life-db-node.js` | The main file for node environment |
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