Compare commits
	
		
			No commits in common. "master" and "v2.0.1" have entirely different histories.
		
	
	
		
	
		
							
								
								
									
										37
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								README.md
									
									
									
									
									
								
							| @ -11,7 +11,7 @@ Bower (Browser) | |||||||
| ```bash | ```bash | ||||||
| bower install json-storage | bower install json-storage | ||||||
| # or | # or | ||||||
| wget https://git.coolaj86.com/coolaj86/json-storage.js/raw/branch/master/json-storage.js | wget https://raw2.github.com/coolaj86/json-storage-js/master/json-storage.js | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Node.JS (Server) | Node.JS (Server) | ||||||
| @ -25,8 +25,7 @@ Usage | |||||||
| 
 | 
 | ||||||
| Made for Node.js and Bower (browser-side). | Made for Node.js and Bower (browser-side). | ||||||
| 
 | 
 | ||||||
| ```javascript |     var localStorage = require('localStorage') | ||||||
| var localStorage = require('localStorage') |  | ||||||
|       , JsonStorage = require('json-storage').JsonStorage |       , JsonStorage = require('json-storage').JsonStorage | ||||||
|       , store = JsonStorage.create(localStorage, 'my-widget-namespace', { stringify: true }) |       , store = JsonStorage.create(localStorage, 'my-widget-namespace', { stringify: true }) | ||||||
|       , myValue = { |       , myValue = { | ||||||
| @ -35,9 +34,8 @@ var localStorage = require('localStorage') | |||||||
|         } |         } | ||||||
|       ; |       ; | ||||||
| 
 | 
 | ||||||
| store.set('myKey', myValue); |     store.set('myKey', myValue);  | ||||||
| myValue = store.get('myKey'); |     myValue = store.get('myKey'); | ||||||
| ``` |  | ||||||
| 
 | 
 | ||||||
| NOTE: When using with Node and the `localStorage` module, | NOTE: When using with Node and the `localStorage` module, | ||||||
| you may wish to pass the `{ stringify: false }` option to prevent double stringification. | you may wish to pass the `{ stringify: false }` option to prevent double stringification. | ||||||
| @ -50,8 +48,6 @@ API | |||||||
|     * `namespace` is optional string which allows multiple non-conflicting storage containers. For example you could pass two widgets different storage containers and not worry about naming conflicts: |     * `namespace` is optional string which allows multiple non-conflicting storage containers. For example you could pass two widgets different storage containers and not worry about naming conflicts: | ||||||
|       * `Gizmos.create(JsonStorage.create(null, 'my-gizmos'))` |       * `Gizmos.create(JsonStorage.create(null, 'my-gizmos'))` | ||||||
|       * `Gadgets.create(JsonStorage.create(null, 'my-gadgets'))` |       * `Gadgets.create(JsonStorage.create(null, 'my-gadgets'))` | ||||||
|       * Namespacing can be turned off by explicitly setting `false` |  | ||||||
|         * `Gadgets.create(JsonStorage.create(null, false))` |  | ||||||
|     * `opts` |     * `opts` | ||||||
|       * `stringify` set to `false` in `node` to avoid double stringifying |       * `stringify` set to `false` in `node` to avoid double stringifying | ||||||
|   * `store.get(key)` |   * `store.get(key)` | ||||||
| @ -86,34 +82,15 @@ To save `undefined`, use `null` instead. | |||||||
| 
 | 
 | ||||||
| Note that both values that exist as `null` and values that don't exist at all will return `null`. | Note that both values that exist as `null` and values that don't exist at all will return `null`. | ||||||
| 
 | 
 | ||||||
| ```javascript |     store.set('existing-key', null); | ||||||
| store.set('existing-key', null); |     null === store.get('existing-key'); | ||||||
| null === store.get('existing-key'); |     null === store.get('non-existant-key'); | ||||||
| null === store.get('non-existant-key'); |  | ||||||
| ``` |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| ### `null` vs `"null"` | ### `null` vs `"null"` | ||||||
| 
 | 
 | ||||||
| The special case of `null` as `"null"`, aka `"\"null\""`: | The special case of `null` as `"null"`, aka `"\"null\""`: | ||||||
| 
 | 
 | ||||||
| ``` |  | ||||||
| typeof null        // object |  | ||||||
| typeof "null"      // string |  | ||||||
| typeof "\"null\""  // string |  | ||||||
| ``` |  | ||||||
| 
 |  | ||||||
| `null`, and `"null"` both parse as `null` the "object", instead of one being the string (which would be `"\"null\""`). | `null`, and `"null"` both parse as `null` the "object", instead of one being the string (which would be `"\"null\""`). | ||||||
| 
 | 
 | ||||||
| ``` |  | ||||||
| JSON.parse(null)       // null (object) |  | ||||||
| JSON.parse("null")     // null (object) |  | ||||||
| JSON.parse("\"null\"") // 'null' (string) |  | ||||||
| ``` |  | ||||||
| 
 |  | ||||||
| Objects containing `null`, however, parse as expected `{ "foo": null, "bar": "null" }` will parse as `foo` being `null` but `bar` being `"null"`, much unlike the value `"null"` being parsed on its own. | Objects containing `null`, however, parse as expected `{ "foo": null, "bar": "null" }` will parse as `foo` being `null` but `bar` being `"null"`, much unlike the value `"null"` being parsed on its own. | ||||||
| 
 |  | ||||||
| ``` |  | ||||||
| JSON.parse('{ "foo": null }')    // { foo: null } |  | ||||||
| JSON.parse('{ "foo": "null" }')  // { foo: 'null' } |  | ||||||
| ``` |  | ||||||
| @ -52,9 +52,6 @@ | |||||||
|     // complicated to figure it out
 |     // complicated to figure it out
 | ||||||
|     this._namespace = delim; |     this._namespace = delim; | ||||||
|     this._namespace += (namespace || 'jss'); |     this._namespace += (namespace || 'jss'); | ||||||
|     if (false === namespace) { |  | ||||||
|       this._namespace = ''; |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     this._store = w3cStorage; |     this._store = w3cStorage; | ||||||
|     this._keysAreDirty = true; |     this._keysAreDirty = true; | ||||||
| @ -110,7 +107,7 @@ | |||||||
| 
 | 
 | ||||||
|       delimAt = key.lastIndexOf(this._namespace); |       delimAt = key.lastIndexOf(this._namespace); | ||||||
|       // test if this key belongs to this widget
 |       // test if this key belongs to this widget
 | ||||||
|       if (!this._namespace || (-1 !== delimAt)) { |       if (-1 !== delimAt) { | ||||||
|         this._keys.push(key.substr(0, delimAt)); |         this._keys.push(key.substr(0, delimAt)); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -3,10 +3,10 @@ | |||||||
|   "name": "json-storage", |   "name": "json-storage", | ||||||
|   "description": "A wrapper for storage engines which use the W3C Storage API", |   "description": "A wrapper for storage engines which use the W3C Storage API", | ||||||
|   "keywords": ["dom", "storage", "json", "w3c", "localStorage", "sessionStorage", "globalStorage", "Storage"], |   "keywords": ["dom", "storage", "json", "w3c", "localStorage", "sessionStorage", "globalStorage", "Storage"], | ||||||
|   "version": "2.1.2", |   "version": "2.0.1", | ||||||
|   "repository": { |   "repository": { | ||||||
|     "type": "git", |     "type": "git", | ||||||
|     "url": "git://git.coolaj86.com/coolaj86/json-storage.js.git" |     "url": "git://github.com/coolaj86/json-storage-js.git" | ||||||
|   }, |   }, | ||||||
|   "engines": { |   "engines": { | ||||||
|     "node": ">= v0.2.0" |     "node": ">= v0.2.0" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user