Compare commits

..

No commits in common. "master" and "v2.0.2" have entirely different histories.

3 changed files with 25 additions and 39 deletions

View File

@ -1,13 +1,6 @@
sessionStorage & localStorage for NodeJS sessionStorage & localStorage for NodeJS
=== ===
| **dom-storage**
| [atob](https://git.coolaj86.com/coolaj86/atob.js)
| [btoa](https://git.coolaj86.com/coolaj86/btoa.js)
| [unibabel.js](https://git.coolaj86.com/coolaj86/unibabel.js)
| Sponsored by [ppl](https://ppl.family)
An inefficient, but as W3C-compliant as possible using only pure JavaScript, `DOMStorage` implementation. An inefficient, but as W3C-compliant as possible using only pure JavaScript, `DOMStorage` implementation.
Purpose Purpose
@ -19,15 +12,16 @@ Usage
---- ----
```javascript ```javascript
var Storage = require('dom-storage'); var Storage = require('dom-storage')
// in-file, doesn't call `String(val)` on values (default) // in-file, doesn't call `String(val)` on values (default)
var localStorage = new Storage('./db.json', { strict: false, ws: ' ' }); , localStorage = new Storage('./db.json', { strict: false, ws: ' ' })
// in-memory, does call `String(val)` on values (i.e. `{}` becomes `'[object Object]'` // in-memory, does call `String(val)` on values (i.e. `{}` becomes `'[object Object]'`
var sessionStorage = new Storage(null, { strict: true }); , sessionStorage = new Storage(null, { strict: true })
var myValue = { foo: 'bar', baz: 'quux' }; , myValue = { foo: 'bar', baz: 'quux' }
;
localStorage.setItem('myKey', myValue); localStorage.setItem('myKey', myValue);
myValue = localStorage.getItem('myKey'); myValue = localStorage.getItem('myKey');
@ -57,15 +51,15 @@ Tests
```javascript ```javascript
0 === localStorage.length; 0 === localStorage.length;
null === localStorage.getItem('doesn\'t exist'); null === localStorage.getItem('doesn't exist');
undefined === localStorage['doesn\'t exist']; undefined === localStorage['doesn't exist'];
localStorage.setItem('myItem'); localStorage.setItem('myItem');
'undefined' === localStorage.getItem('myItem'); "undefined" === localStorage.getItem('myItem');
1 === localStorage.length; 1 === localStorage.length;
localStorage.setItem('myItem', 0); localStorage.setItem('myItem', 0);
'0' === localStorage.getItem('myItem'); "0" === localStorage.getItem('myItem');
localStorage.removeItem('myItem', 0); localStorage.removeItem('myItem', 0);
0 === localStorage.length; 0 === localStorage.length;
@ -84,10 +78,4 @@ Notes
License License
------- -------
Code copyright 2012-2018 AJ ONeal * [Apache2](http://www.apache.org/licenses/LICENSE-2.0)
Dual-licensed MIT and Apache-2.0
Docs copyright 2012-2018 AJ ONeal
Docs released under Creative Commons.

View File

@ -8,11 +8,13 @@
(function () { (function () {
"use strict"; "use strict";
var fs = require('fs'); var fs = require('fs')
;
function Storage(path, opts) { function Storage(path, opts) {
opts = opts || {}; opts = opts || {};
var db; var db
;
Object.defineProperty(this, '___priv_bk___', { Object.defineProperty(this, '___priv_bk___', {
value: { value: {
@ -86,14 +88,13 @@
return Object.keys(this)[i]; return Object.keys(this)[i];
}; };
Object.defineProperty(Storage.prototype, 'length', { Storage.prototype.__defineGetter__('length', function () {
get: function() { return Object.keys(this).length;
return Object.keys(this).length;
}
}); });
Storage.prototype.___save___ = function () { Storage.prototype.___save___ = function () {
var self = this; var self = this
;
if (!this.___priv_bk___.path) { if (!this.___priv_bk___.path) {
return; return;
@ -112,8 +113,6 @@
, function (e) { , function (e) {
self.___priv_bk___.lock = false; self.___priv_bk___.lock = false;
if (e) { if (e) {
console.error('Could not write to database', self.___priv_bk___.path);
console.error(e);
return; return;
} }
if (self.___priv_bk___.wait) { if (self.___priv_bk___.wait) {

View File

@ -1,18 +1,17 @@
{ {
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)", "author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)",
"homepage": "https://git.coolaj86.com/coolaj86/dom-storage.js",
"name": "dom-storage", "name": "dom-storage",
"description": "W3C DOM Storage (localStorage and sessionStorage) for node.js", "description": "W3C DOM Storage (localStorage and sessionStorage) for Node.JS",
"version": "2.1.0", "version": "2.0.2",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://git.coolaj86.com/coolaj86/dom-storage.js.git" "url": "git://github.com/coolaj86/node-dom-storage.git"
}, },
"engines": { "engines": {
"node": "*" "node": "*"
}, },
"main": "lib/index.js", "main": "lib/index.js",
"dependencies": {}, "dependencies": {},
"license": "(MIT or Apache-2.0)", "license": "Apache2",
"devDependencies": {} "devDependencies": {}
} }