Compare commits

...

8 Commits

Author SHA1 Message Date
AJ ONeal 2dedfc50e6 update urls and license 2018-03-27 23:15:41 -06:00
AJ ONeal 9c5ae4a36f v2.1.0 2018-03-27 23:12:55 -06:00
AJ ONeal a13644945f
Merge pull request #5 from omphalos/defineProperty
Use Object.defineProperty not __defineGetter__
2018-03-27 22:57:05 -06:00
AJ ONeal 09b007e656
Merge pull request #3 from pdehaan/patch-1
Update license attribute
2018-03-27 22:56:50 -06:00
AJ ONeal 0c3ba0de9e
Merge pull request #7 from nloomans/patch-1
Fixed syntax error in README.md
2018-03-27 22:56:30 -06:00
Noah Loomans 0a95d2d63a Fixed syntax error in README.md 2016-03-03 16:51:10 +01:00
omphalos 4a0d9cd224 Use Object.defineProperty not __defineGetter__
This allows this library to be used in IE9/IE10.
2015-10-11 21:27:02 -05:00
Peter deHaan 21d6d62615 Update license attribute
specifying the type and URL is deprecated:

https://docs.npmjs.com/files/package.json#license
http://npm1k.org/
2015-05-20 22:52:42 -07:00
3 changed files with 39 additions and 25 deletions

View File

@ -1,6 +1,13 @@
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.
Purpose
@ -12,16 +19,15 @@ Usage
----
```javascript
var Storage = require('dom-storage')
var Storage = require('dom-storage');
// in-file, doesn't call `String(val)` on values (default)
, localStorage = new Storage('./db.json', { strict: false, ws: ' ' })
// in-file, doesn't call `String(val)` on values (default)
var localStorage = new Storage('./db.json', { strict: false, ws: ' ' });
// in-memory, does call `String(val)` on values (i.e. `{}` becomes `'[object Object]'`
, sessionStorage = new Storage(null, { strict: true })
// in-memory, does call `String(val)` on values (i.e. `{}` becomes `'[object Object]'`
var sessionStorage = new Storage(null, { strict: true });
, myValue = { foo: 'bar', baz: 'quux' }
;
var myValue = { foo: 'bar', baz: 'quux' };
localStorage.setItem('myKey', myValue);
myValue = localStorage.getItem('myKey');
@ -51,15 +57,15 @@ Tests
```javascript
0 === localStorage.length;
null === localStorage.getItem('doesn't exist');
undefined === localStorage['doesn't exist'];
null === localStorage.getItem('doesn\'t exist');
undefined === localStorage['doesn\'t exist'];
localStorage.setItem('myItem');
"undefined" === localStorage.getItem('myItem');
'undefined' === localStorage.getItem('myItem');
1 === localStorage.length;
localStorage.setItem('myItem', 0);
"0" === localStorage.getItem('myItem');
'0' === localStorage.getItem('myItem');
localStorage.removeItem('myItem', 0);
0 === localStorage.length;
@ -78,4 +84,10 @@ Notes
License
-------
* [Apache2](http://www.apache.org/licenses/LICENSE-2.0)
Code copyright 2012-2018 AJ ONeal
Dual-licensed MIT and Apache-2.0
Docs copyright 2012-2018 AJ ONeal
Docs released under Creative Commons.

View File

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

View File

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