Compare commits
	
		
			8 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 2dedfc50e6 | ||
|  | 9c5ae4a36f | ||
|  | a13644945f | ||
|  | 09b007e656 | ||
|  | 0c3ba0de9e | ||
|  | 0a95d2d63a | ||
|  | 4a0d9cd224 | ||
|  | 21d6d62615 | 
							
								
								
									
										36
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								README.md
									
									
									
									
									
								
							| @ -1,6 +1,13 @@ | |||||||
| 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 | ||||||
| @ -12,16 +19,15 @@ 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) | ||||||
|   , localStorage = new Storage('./db.json', { strict: false, ws: '  ' }) | var 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]'` | ||||||
|   , sessionStorage = new Storage(null, { strict: true }) | var sessionStorage = new Storage(null, { strict: true }); | ||||||
| 
 | 
 | ||||||
|   , myValue = { foo: 'bar', baz: 'quux' } | var myValue = { foo: 'bar', baz: 'quux' }; | ||||||
|   ; |  | ||||||
| 
 | 
 | ||||||
| localStorage.setItem('myKey', myValue); | localStorage.setItem('myKey', myValue); | ||||||
| myValue = localStorage.getItem('myKey'); | myValue = localStorage.getItem('myKey'); | ||||||
| @ -51,15 +57,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; | ||||||
| @ -78,4 +84,10 @@ Notes | |||||||
| License | 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. | ||||||
|  | |||||||
							
								
								
									
										17
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								lib/index.js
									
									
									
									
									
								
							| @ -8,13 +8,11 @@ | |||||||
| (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: { | ||||||
| @ -88,13 +86,14 @@ | |||||||
|     return Object.keys(this)[i]; |     return Object.keys(this)[i]; | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   Storage.prototype.__defineGetter__('length', function () { |   Object.defineProperty(Storage.prototype, 'length', { | ||||||
|     return Object.keys(this).length; |     get: function() { | ||||||
|  |       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; | ||||||
| @ -113,6 +112,8 @@ | |||||||
|     , 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) { | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								package.json
									
									
									
									
									
								
							| @ -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", |   "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.0.2", |   "version": "2.1.0", | ||||||
|   "repository": { |   "repository": { | ||||||
|     "type": "git", |     "type": "git", | ||||||
|     "url": "git://github.com/coolaj86/node-dom-storage.git" |     "url": "git://git.coolaj86.com/coolaj86/dom-storage.js.git" | ||||||
|   }, |   }, | ||||||
|   "engines": { |   "engines": { | ||||||
|     "node": "*" |     "node": "*" | ||||||
|   }, |   }, | ||||||
|   "main": "lib/index.js", |   "main": "lib/index.js", | ||||||
|   "dependencies": {}, |   "dependencies": {}, | ||||||
|   "license": "Apache2", |   "license": "(MIT or Apache-2.0)", | ||||||
|   "devDependencies": {} |   "devDependencies": {} | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user