pax_global_header00006660000000000000000000000064127032233220014506gustar00rootroot0000000000000052 comment=ec50d720c0917a853824e1a06e575bdbbb687a24 node-localstorage-1.3.0/000077500000000000000000000000001270322332200151115ustar00rootroot00000000000000node-localstorage-1.3.0/.coveralls.yml000066400000000000000000000001071270322332200177020ustar00rootroot00000000000000service_name: travis-pro repo_token: R1SoJjU5njYQYWAsEaKr47EdkI4zOW3om node-localstorage-1.3.0/.gitignore000066400000000000000000000000571270322332200171030ustar00rootroot00000000000000.DS_Store scratch node_modules .idea *.js *.mapnode-localstorage-1.3.0/.npmignore000066400000000000000000000000451270322332200171070ustar00rootroot00000000000000 .idea/ node_modules/ *.coffee *.map node-localstorage-1.3.0/.play/000077500000000000000000000000001270322332200161345ustar00rootroot00000000000000node-localstorage-1.3.0/.play/es6Proxy.coffee000066400000000000000000000007671270322332200210560ustar00rootroot00000000000000# This now works on at least npm v5.x, but still requires harmony-proxies flag # To run `coffee --nodejs --harmony-proxies .play/es6Proxy.coffee` class ObjectLike constructor: (obj) -> unless obj? obj = {} @dummy = obj interceptor = set: (receiver, key, value) => @dummy[key] = value get: (receiver, key) => return @dummy[key] return Proxy.create(interceptor, @dummy) a = new ObjectLike() a['something long'] = 10 console.log(a['something long'])node-localstorage-1.3.0/.play/es6ProxyTest.coffee000066400000000000000000000006601270322332200217060ustar00rootroot00000000000000class ObjectLike constructor: (obj) -> unless obj? obj = {} @dummy = obj interceptor = set: (receiver, key, value) => @dummy[key] = value get: (receiver, key) => return @dummy[key] return Proxy.create(interceptor, @dummy) exports.es6ProxyTest = theTest: (test) -> a = new ObjectLike() a['something long'] = 10 test.equal(a['something long'], 11) test.done()node-localstorage-1.3.0/.play/es6ProxyTest2.coffee000066400000000000000000000006601270322332200217700ustar00rootroot00000000000000class ObjectLike constructor: (obj) -> unless obj? obj = {} @dummy = obj interceptor = set: (receiver, key, value) => @dummy[key] = value get: (receiver, key) => return @dummy[key] return Proxy.create(interceptor, @dummy) exports.es6ProxyTest = theTest: (test) -> a = new ObjectLike() a['something long'] = 10 test.equal(a['something long'], 11) test.done()node-localstorage-1.3.0/.play/statSize.coffee000066400000000000000000000002461270322332200211150ustar00rootroot00000000000000fs = require('fs') filename = '/Users/larry/.bash_history' console.log(fs.statSync(filename).size) file = fs.readFileSync(filename, 'utf8') console.log(file.length) node-localstorage-1.3.0/.travis.yml000066400000000000000000000000721270322332200172210ustar00rootroot00000000000000language: node_js node_js: - "0.12" - "4.0" - "5.1" node-localstorage-1.3.0/Cakefile000066400000000000000000000055001270322332200165370ustar00rootroot00000000000000fs = require('fs') spawnSync = require('child_process').spawnSync path = require('path') _ = require('lodash') isWindows = (process.platform.lastIndexOf('win') == 0) runSync = (command) -> # Spawn things in a sub-shell so things like io redirection and gsutil work if isWindows shell = 'cmd.exe' args = ['/c', command] else shell = 'sh' args = ['-c', command] {status, stdout, stderr} = spawnSync(shell, args, {encoding: 'utf8'}) if stderr?.length > 0 or status > 0 console.error("Error running: '#{command}'\n#{stderr}\n#{stdout}\n") process.exit(status) else console.log("Output of running '#{command}'\n#{stdout}\n") return stdout task('clean', 'Deletes .js and .map files', () -> folders = ['.'] for folder in folders pathToClean = path.join(__dirname, folder) contents = fs.readdirSync(pathToClean) for file in contents when (_.endsWith(file, '.js') or _.endsWith(file, '.map')) fs.unlinkSync(path.join(pathToClean, file)) ) task('compile', 'Compile CoffeeScript source files to JavaScript', () -> process.chdir(__dirname) fs.readdir('./', (err, contents) -> files = ("#{file}" for file in contents when (file.indexOf('.coffee') > 0)) command = ['coffee', '-c'].concat(files).join(' ') runSync(command) ) ) task('test', 'Run the CoffeeScript test suite with nodeunit', () -> invoke('testES6') {reporters} = require('nodeunit') process.chdir(__dirname) reporters.default.run(['test'], undefined, (failure) -> if failure? console.log(failure) process.exit(1) ) ) task('testES6', 'Run tests in testES6 folder with --harmony-proxies flag', () -> runSync("node --harmony-proxies $(which nodeunit) testES6/*.coffee") ) task('publish', 'Publish to npm and add git tags', () -> process.chdir(__dirname) runSync('cake test') # Doing this externally to make it synchronous process.chdir(__dirname) runSync('cake compile') console.log('checking git status --porcelain') stdout = runSync('git status --porcelain') if stdout.length > 0 console.error('`git status --porcelain` was not clean. Not publishing.') else console.log('checking origin/master') stdout = runSync('git rev-parse origin/master') console.log('checking master') stdoutOrigin = stdout stdout = runSync('git rev-parse master') stdoutMaster = stdout if stdoutOrigin == stdoutMaster console.log('running npm publish') runSync('npm publish .') try stat = fs.statSync('npm-debug.log') console.error('`npm publish` failed. See npm-debug.log for details.') process.exit(1) console.log('creating git tag') runSync("git tag v#{require('./package.json').version}") runSync("git push --tags") invoke("clean") else console.error('Origin and master out of sync. Not publishing.') ) node-localstorage-1.3.0/LocalStorage.coffee000066400000000000000000000137401270322332200206460ustar00rootroot00000000000000path = require('path') fs = require('fs') events = require('events') writeSync = require('write-file-atomic').sync KEY_FOR_EMPTY_STRING = '---.EMPTY_STRING.---' # Chose something that no one is likely to ever use _emptyDirectory = (target) -> _rm(path.join(target, p)) for p in fs.readdirSync(target) _rm = (target) -> if fs.statSync(target).isDirectory() _emptyDirectory(target) fs.rmdirSync(target) else fs.unlinkSync(target) _escapeKey = (key) -> if key is '' newKey = KEY_FOR_EMPTY_STRING else newKey = key.toString() return newKey class QUOTA_EXCEEDED_ERR extends Error constructor: (@message = 'Unknown error.') -> if Error.captureStackTrace? Error.captureStackTrace(this, @constructor) @name = @constructor.name toString: () -> return "#{@name}: #{@message}" class StorageEvent constructor: (@key, @oldValue, @newValue, @url, @storageArea = 'localStorage') -> class MetaKey # MetaKey contains key and size constructor: (@key, @index) -> unless this instanceof MetaKey return new MetaKey(@key, @index) createMap = -> # createMap contains Metakeys as properties Map = -> return Map.prototype = Object.create(null); return new Map() class LocalStorage extends events.EventEmitter instanceMap = {} constructor: (@_location, @quota = 5 * 1024 * 1024) -> unless this instanceof LocalStorage return new LocalStorage(@_location, @quota) @_location = path.resolve(@_location) if instanceMap[@_location]? return instanceMap[@_location] @length = 0 # !TODO: Maybe change this to a property with __defineProperty__ @_bytesInUse = 0 @_keys = [] @_metaKeyMap = createMap() @_eventUrl = "pid:" + process.pid @_init() @_QUOTA_EXCEEDED_ERR = QUOTA_EXCEEDED_ERR # if Proxy? # handler = # set: (receiver, key, value) => # if @[key]? # return @[key] = value # else # @setItem(key, value) # # get: (receiver, key) => # if @[key]? # return @[key] # else # return @getItem(key) # # instanceMap[@_location] = Proxy.create(handler, this) # return instanceMap[@_location] instanceMap[@_location] = this return instanceMap[@_location] # else it'll return this _init: () -> try stat = fs.statSync(@_location) if stat? and not stat.isDirectory() throw new Error("A file exists at the location '#{@_location}' when trying to create/open localStorage") # At this point, it exists and is definitely a directory. So read it. @_bytesInUse = 0 @length = 0 _keys = fs.readdirSync(@_location) for k, index in _keys _decodedKey = decodeURIComponent(k) @_keys.push(_decodedKey) _MetaKey = new MetaKey(k, index) @_metaKeyMap[_decodedKey] = _MetaKey stat = @_getStat(k) if stat?.size? _MetaKey.size = stat.size @_bytesInUse += stat.size @length = _keys.length return catch # If it errors, that means it didn't exist, so create it fs.mkdirSync(@_location) return setItem: (key, value) -> hasListeners = events.EventEmitter.listenerCount(this, 'storage') oldValue = null if hasListeners oldValue = this.getItem(key) key = _escapeKey(key) encodedKey = encodeURIComponent(key) filename = path.join(@_location, encodedKey) valueString = value.toString() valueStringLength = valueString.length metaKey = @_metaKeyMap[key] existsBeforeSet = !!metaKey if existsBeforeSet oldLength = metaKey.size else oldLength = 0 if @_bytesInUse - oldLength + valueStringLength > @quota throw new QUOTA_EXCEEDED_ERR() writeSync(filename, valueString, 'utf8') unless existsBeforeSet metaKey = new MetaKey(encodedKey, (@_keys.push(key)) - 1) metaKey.size = valueStringLength @_metaKeyMap[key] = metaKey @length += 1 @_bytesInUse += valueStringLength if hasListeners evnt = new StorageEvent(key, oldValue, value, @_eventUrl) this.emit('storage', evnt) getItem: (key) -> key = _escapeKey(key) metaKey = @_metaKeyMap[key] if !!metaKey filename = path.join(@_location, metaKey.key) return fs.readFileSync(filename, 'utf8') else return null _getStat: (key) -> key = _escapeKey(key) filename = path.join(@_location, encodeURIComponent(key)) try return fs.statSync(filename) catch return null removeItem: (key) -> key = _escapeKey(key) metaKey = @_metaKeyMap[key] if (!!metaKey) hasListeners = events.EventEmitter.listenerCount(this, 'storage') oldValue = null if hasListeners oldValue = this.getItem(key) delete @_metaKeyMap[key] @length -= 1 @_bytesInUse -= metaKey.size filename = path.join(@_location, metaKey.key) @_keys.splice(metaKey.index,1) for k,v of @_metaKeyMap meta = @_metaKeyMap[k] if meta.index > metaKey.index meta.index -= 1 _rm(filename) if hasListeners evnt = new StorageEvent(key, oldValue, null, @_eventUrl) this.emit('storage', evnt) key: (n) -> return @_keys[n] clear: () -> _emptyDirectory(@_location) @_metaKeyMap = createMap() @_keys = [] @length = 0 @_bytesInUse = 0 if events.EventEmitter.listenerCount(this, 'storage') evnt = new StorageEvent(null, null, null, @_eventUrl) this.emit('storage', evnt) _getBytesInUse: () -> return @_bytesInUse _deleteLocation: () -> delete instanceMap[@_location] _rm(@_location) @_metaKeyMap = {} @_keys = [] @length = 0 @_bytesInUse = 0 class JSONStorage extends LocalStorage setItem: (key, value) -> newValue = JSON.stringify(value) super(key, newValue) getItem: (key) -> return JSON.parse(super(key)) exports.LocalStorage = LocalStorage exports.JSONStorage = JSONStorage exports.QUOTA_EXCEEDED_ERR = QUOTA_EXCEEDED_ERR node-localstorage-1.3.0/README.md000066400000000000000000000141701270322332200163730ustar00rootroot00000000000000[![build status](https://secure.travis-ci.org/lmaccherone/node-localstorage.png)](http://travis-ci.org/lmaccherone/node-localstorage) [![bitHound Score](https://www.bithound.io/github/lmaccherone/node-localstorage/badges/score.svg)](https://www.bithound.io/github/lmaccherone/node-localstorage) # node-localstorage # Copyright (c) 2012, Lawrence S. Maccherone, Jr. _A drop-in substitute for the browser native localStorage API that runs on node.js._ ### Fully implements the localStorage specfication including: ### * All methods in the [localStorage spec](http://www.w3.org/TR/webstorage/#storage) interface including: * length * setItem(key, value) * getItem(key) * removeItem(key) * key(n) * clear() * Serializes to disk in the location specified during instantiation * Supports the setting of a quota (default 5MB) * Events. This doesn't exactly follow the spec which states that events are NOT supposed to be emitted to the browser window that took the action that triggered the event in the first place. They are are only to be emitted to listners in other browser windows. Early browser implementations actually did it this way and we don't really have the equivalent of a browser window in node.js, so we choose to implement them in the current process. We did, however, include the pid information in place of the window uri, so if we later wanted to say think of other node.js processes accessing the same file system, we could actually implement it correctly. That would involve file watchers though and was more than we wanted to implement for now. Maybe later. * (experimental) Associative array `localStorage['myKey'] = 'myValue'` and dot property `localStorage.myKey = 'myValue'` syntax. This only works if you use the --harmony-proxies flag. It senses the existence of the Proxy object in the root scope. If you have added your own Proxy object, then you could have a problem. Another potential risk is around the "private", underscore preceded methods and properties. I had to reserve those in addition to the standard ones, so you won't be able to use keys that overlap with those underscore preceded properties and methods in a harmony-proxies environment. ## Credits ## Author: [Larry Maccherone](http://maccherone.com) ## Usage ## ### CoffeeScript ### unless localStorage? {LocalStorage} = require('../') # require('node-localstorage') for you localStorage = new LocalStorage('./scratch') localStorage.setItem('myFirstKey', 'myFirstValue') console.log(localStorage.getItem('myFirstKey')) # myFirstValue localStorage._deleteLocation() # cleans up ./scratch created during doctest ### JavaScript ### ```JavaScript if (typeof localStorage === "undefined" || localStorage === null) { var LocalStorage = require('node-localstorage').LocalStorage; localStorage = new LocalStorage('./scratch'); } localStorage.setItem('myFirstKey', 'myFirstValue'); console.log(localStorage.getItem('myFirstKey')); ``` ## Installation ## `npm install node-localstorage` ## Changelog ## * 1.3.0 - 2016-04-09 - **Possibly backward breaking if you were using experimental syntax** Reverted experimental associative array and dot-property syntax. The API for Proxy changed with node.js v6.x which broke it. Then when I switched to the new syntax, it broke the EventEmitter functionality. Will restore once I know how to fix that. * 1.2.0 - 2016-04-09 - Atomic writes (thanks, mvayngrib) * 1.1.2 - 2016-01-08 - Resolves issue #17 (thanks, evilaliv3) * 1.1.1 - 2016-01-04 - Smarter associative array and dot-property syntax support * 1.1.0 - 2016-01-03 - **Backward breaking** if you used any of the non-standard methods. They are now all preceded with an underscore. Big upgrade for this version is experimental support for associative array and dot-property syntax. * 1.0.0 - 2016-01-03 - Fixed bug with empty string key (thanks, tinybike) * 0.6.0 - 2015-09-11 - Removed references to deprecated fs.existsSync() (thanks, josephbosire) * 0.5.2 - 2015-08-01 - Fixed defect where keys were not being updated correctly by removeItem() (thanks, ed69140) * 0.5.1 - 2015-06-01 - Added support for events * 0.5.0 - 2015-02-02 - Added JSONStorage class which allows you set and get native JSON * 0.4.1 - 2015-02-02 - More robust publishing/tagging (like Lumenize) * 0.4.0 - 2015-02-02 - Uses more efficient fs.statSync to set initial size (thanks, sudheer594) * 0.3.6 - 2014-12-24 - Allows usage without `new` * 0.3.5 - 2014-12-23 - Fixed toString() for QuotaExceededError * 0.3.4 - 2013-07-07 - Moved CoffeeScript to devDependencies * 0.3.3 - 2013-04-05 - Added support for '/' in keys by escaping before creating file names * 0.3.2 - 2013-01-19 - Renamed QuotaExceededError to QUOTA_EXCEEDED_ERR to match most browsers * 0.3.1 - 2013-01-19 - Fixed bug where it threw plain old Error instead of new QuotaExceededError * 0.3.0 - 2013-01-19 - Added QuotaExceededError support * 0.2.0 - 2013-01-03 - Added quota support * 0.1.2 - 2012-11-02 - Finally got Travis CI working * 0.1.1 - 2012-10-29 - Update to support Travis CI * 0.1.0 - 2012-10-29 - Original version ## MIT License ## Copyright (c) 2011, 2012, Lawrence S. Maccherone, Jr. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. node-localstorage-1.3.0/package.json000066400000000000000000000017161270322332200174040ustar00rootroot00000000000000{ "name": "node-localstorage", "version": "1.3.0", "main": "./LocalStorage", "description": "A drop-in substitute for the browser native localStorage API that runs on node.js.", "keywords": [ "localStorage", "Web Storage", "node.js" ], "author": { "name": "Larry Maccherone", "url": "http://maccherone.com" }, "homepage": "https://github.com/lmaccherone/node-localstorage", "engines": { "node": ">=0.12" }, "repository": { "type": "git", "url": "http://github.com/lmaccherone/node-localstorage.git" }, "preferGlobal": false, "devDependencies": { "coffee-script": "^1.10.0", "lodash": "^3.10.1", "nodeunit": "~0.9.0" }, "scripts": { "test": "cake test", "docompile": "cake compile", "prepublish": "cake compile" }, "licenses": [ { "type": "MIT", "url": "http://www.opensource.org/licenses/MIT" } ], "dependencies": { "write-file-atomic": "^1.1.4" } } node-localstorage-1.3.0/test/000077500000000000000000000000001270322332200160705ustar00rootroot00000000000000node-localstorage-1.3.0/test/ErrorTest.coffee000066400000000000000000000004601270322332200211720ustar00rootroot00000000000000{LocalStorage} = require('../') fs = require('fs') exports.LocalStorageTest = testFileExists: (test) -> fs.writeFileSync('./scratchFile', 'hello', 'utf8') f = () -> ls2 = new LocalStorage('./scratchFile') test.throws(f, Error) fs.unlinkSync('./scratchFile') test.done() node-localstorage-1.3.0/test/JSONStorageTest.coffee000066400000000000000000000025351270322332200222040ustar00rootroot00000000000000{JSONStorage} = require('../') path = require('path') exports.JSONStorageTest = testJSONStorage: (test) -> localStorage = new JSONStorage('./scratch') test.equal(localStorage._location, path.resolve('./scratch')) localStorage.setItem('/', 'something') test.equal(localStorage.getItem('/'), 'something') o = {a:1, b:'some string', c:{x: 1, y: 2}} localStorage.setItem('2', o) test.deepEqual(localStorage.getItem('2'), o) a = [1, 'some string', {a:1, b:'some string', c:{x: 1, y: 2}}] localStorage.setItem('2', a) test.deepEqual(localStorage.getItem('2'), a) test.deepEqual(localStorage._keys, ['/', '2']) test.equal(localStorage.length, 2) localStorage.removeItem('2') test.equal(localStorage.getItem('2'), null) test.deepEqual(localStorage._keys, ['/']) test.equal(localStorage.length, 1) test.equal(localStorage.key(0), '/') localStorage.clear() test.equal(localStorage.length, 0) localStorage._deleteLocation() test.done() testNoNewKeyword: (test) -> local = JSONStorage('./scratch3') local.setItem('Hello', ' world!') test.equals(local.getItem('Hello'), ' world!') local._deleteLocation() test.done() testNull: (test) -> local = JSONStorage('./scratch4') test.equals(local.getItem('junk'), null) local._deleteLocation() test.done() node-localstorage-1.3.0/test/LocalStorageTest.coffee000066400000000000000000000113731270322332200224650ustar00rootroot00000000000000{LocalStorage} = require('../') path = require('path') repeat = (string, count) -> a = [] while count-- a.push(string) return a.join('') exports.LocalStorageTest = testLocalStorage: (test) -> localStorage = new LocalStorage('./scratch') test.equal(localStorage._location, path.resolve('./scratch')) localStorage.setItem('/', 'something') test.equal(localStorage.getItem('/'), 'something') o = {a:1, b:'some string', c:{x: 1, y: 2}} localStorage.setItem('2', o) test.deepEqual(localStorage.getItem('2'), o.toString()) a = [1, 'some string', {a:1, b:'some string', c:{x: 1, y: 2}}] localStorage.setItem('2', a) test.deepEqual(localStorage.getItem('2'), a.toString()) test.deepEqual(localStorage._keys, ['/', '2']) test.equal(localStorage.length, 2) localStorage.removeItem('2') test.equal(localStorage.getItem('2'), null) test.deepEqual(localStorage._keys, ['/']) test.equal(localStorage.length, 1) test.equal(localStorage.key(0), '/') localStorage.clear() test.equal(localStorage.length, 0) localStorage._deleteLocation() test.done() testQuota: (test) -> n10 = '01234567890' n100 = repeat('0123456789', 10) n1000 = repeat(n100, 10) n10000 = repeat(n1000, 10) ls = new LocalStorage('./scratch2', 3000) ls.setItem(1, n1000) ls.setItem(2, n1000) ls.setItem(3, n1000) test.equal(ls._getBytesInUse(), 3000) f = () -> ls.setItem(6, n10) test.throws(f, Error) ls.setItem(2, n1000) # Should not throw because it replaces one of equal size ls.removeItem(3) ls.setItem(7, n100) f2 = () -> ls.setitem(8, n1000) test.throws(f2, Error) ls._deleteLocation() test.done() testNoNewKeyword: (test) -> local = LocalStorage('./scratch3') local.setItem('Hello', ' world!') test.equals(local.getItem('Hello'), ' world!') local._deleteLocation() test.done() testNull: (test) -> local = LocalStorage('./scratch4') test.equals(local.getItem('junk'), null) local._deleteLocation() test.done() testRemoveKeys: (test) -> localStorage = new LocalStorage('./scratch6'); localStorage.setItem('a', 'hello') localStorage.setItem('b', 'hello') localStorage.setItem('c', 'hello') localStorage.setItem('d', 'hello') test.deepEqual(localStorage._keys, ['a', 'b', 'c', 'd']) localStorage.removeItem('c') test.deepEqual(localStorage._keys, ['a', 'b', 'd']) localStorage.removeItem('a'); test.deepEqual(localStorage._keys, ['b', 'd']) localStorage.removeItem('b') test.deepEqual(localStorage._keys, ['d']) localStorage.removeItem('d') test.deepEqual(localStorage._keys, []) localStorage._deleteLocation() test.done() testEvents: (test) -> localStorage = new LocalStorage('./scratch5') expectedUrl = "pid:" + process.pid key = null; oldVal = null; newVal = null; url = null handleEvent = (evnt) -> key = evnt.key oldVal = evnt.oldValue newVal = evnt.newValue url = evnt.url localStorage.on('storage', handleEvent) localStorage.setItem('a', 'something') test.equal(localStorage.getItem('a'), 'something') test.equal(key, 'a') test.equal(oldVal, null) test.equal(newVal, 'something') test.equal(url, expectedUrl) key = null; oldVal = null; newVal = null; url = null localStorage.setItem('a', 'somethingnew') test.equal(localStorage.getItem('a'), 'somethingnew') test.equal(key, 'a') test.equal(oldVal, 'something') test.equal(newVal, 'somethingnew') test.equal(url, expectedUrl) key = null; oldVal = null; newVal = null; url = null localStorage.removeItem('a') test.equal(localStorage.getItem('a'), null) test.equal(key, 'a') test.equal(oldVal, 'somethingnew') test.equal(newVal, null) test.equal(url, expectedUrl) key = null; oldVal = null; newVal = null; url = null localStorage.clear(); test.equal(localStorage.getItem('a'), null) test.equal(key, null) test.equal(oldVal, null) test.equal(newVal, null) test.equal(url, expectedUrl) localStorage._deleteLocation() test.done() testGetStat: (test) -> localStorage = new LocalStorage('./scratch7') o = {a:1, b:'some string', c:{x: 1, y: 2}} localStorage.setItem('stat', o) test.deepEqual(localStorage.getItem('stat'), o.toString()) test.ok(localStorage._getStat('stat')?) test.equal(localStorage._getStat('not there'), null) localStorage._deleteLocation() test.done() testEmptyString: (test) -> localStorage = new LocalStorage('./scratch8') localStorage.setItem('', 'something') test.equal(localStorage.getItem(''), 'something') localStorage._deleteLocation() test.done() node-localstorage-1.3.0/test/SameDirectoryTwiceTest.coffee000066400000000000000000000005711270322332200236520ustar00rootroot00000000000000{LocalStorage} = require('../') exports.SameDirectoryTwiceTest = theTest: (test) -> localStorage1 = new LocalStorage('./scratch10') localStorage2 = new LocalStorage('./scratch10') localStorage1.setItem("key1", "value1") test.equal(localStorage1.getItem('key1'), localStorage2.getItem('key1')) localStorage1._deleteLocation() test.done() node-localstorage-1.3.0/test/test.html000066400000000000000000000032141270322332200177350ustar00rootroot00000000000000 node-localstorage-1.3.0/testES6/000077500000000000000000000000001270322332200164065ustar00rootroot00000000000000node-localstorage-1.3.0/testES6/es6Test.coffee000066400000000000000000000010321270322332200211100ustar00rootroot00000000000000{LocalStorage} = require('../') exports.es6Test = theTest: (test) -> # TODO: These tests are inadequate in that it will pass even when there is no Proxy object. Need to check for file existence. localStorage = new LocalStorage('./scratch9') localStorage['a'] = 'something' test.equal(localStorage['a'], 'something') localStorage[''] = 'something else' test.equal(localStorage[''], 'something else') localStorage.b = 1 test.equal(localStorage['b'], 1) localStorage._deleteLocation() test.done()