From d262cfaa6102189cfef7ccb8582604f57ffd41bd Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 27 Aug 2011 20:44:20 -0600 Subject: [PATCH] clarification --- README.md | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8010727..16263c7 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,20 @@ jsonStorage A light abstraction for DOMStorage (such as localStorage). +Installation +=== + +Ender.JS (Browser) + + ender build json-storage + +Node.JS (Server) + + npm install localStorage json-storage + +Usage +=== + Made fo for Node.JS and Ender.JS (browser-side). var localStorage = require('localStorage') @@ -30,12 +44,29 @@ API null vs undefined in JSON === -Since it is not valid to set `undefined` in JSON, calling `db.set('x')` is the same as `db.remove('x')`. +These notes do not reflect a bugs or defects in this library, +they're simply to inform you of a few 'gotchas' inherent in JSON / DOMStorage conversion. -However, `null`, and `"null"` both parse as `null` the "object", but the string (which would be `"\"null\""`). +99.999% of the time these gotchas shouldn't effect you in any way. +If they do, you're probably doing something wrong in the first place. -Therefore, setting a key to `undefined` will remove it from the db, but setting it to `null` will save it. -Yet both values that exist as `null` and values that don't exist will return `null`. +It is not valid to set `undefined` in JSON. So setting a key to `undefined` will remove it from the db. -Also `{ "foo": null, "bar": "null" }` will parse as `foo` being `null` but `bar` being `"null"`, much unlike the value `"null"` being parsed on its own. +This means that `db.set('x')` is the same as `db.remove('x')`. + +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`. + + db.set('existing-key', null); + null === db.get('existing-key'); + null === db.get('non-existant-key'); + + +The special case of `null` as `"null"`, aka `"\"null\""`: + +`null`, and `"null"` both parse as `null` the "object", instead of one being the string (which would be `"\"null\""`). + +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. \ No newline at end of file