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 | ||||
| === | ||||
| 
 | ||||
| | **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. | ||||
|  | ||||
							
								
								
									
										15
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								lib/index.js
									
									
									
									
									
								
							| @ -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 () { | ||||
|   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) { | ||||
|  | ||||
							
								
								
									
										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", | ||||
|   "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": {} | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user