From 77b48303843916511b6b993686df81e2f438efae Mon Sep 17 00:00:00 2001 From: Vincent Bortone Date: Fri, 25 Jan 2013 02:53:31 -0500 Subject: [PATCH] Finish code and tests. --- storejs/storejs-tests.ts | 24 +++++++++++++++++++++++- storejs/storejs.d.ts | 17 ++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/storejs/storejs-tests.ts b/storejs/storejs-tests.ts index 9ef1b0f178..06387a728d 100644 --- a/storejs/storejs-tests.ts +++ b/storejs/storejs-tests.ts @@ -1 +1,23 @@ -// Tests for storagejs.d.ts \ No newline at end of file +// Tests for storagejs.d.ts +/// + +// Store 'marcus' at 'username' +store.set('username', 'marcus'); + +// Get 'username' +var userName:any = store.get('username'); + +var all: Object = store.getAll(); + +// Remove 'username' +store.remove('username'); + +// Clear all keys +store.clear(); + +// Store an object literal - store.js uses JSON.stringify under the hood +store.set('user', { name: 'marcus', likes: 'javascript' }); + +// Get the stored object - store.js uses JSON.parse under the hood +var user: any = store.get('user'); +alert(user.name + ' likes ' + user.likes); \ No newline at end of file diff --git a/storejs/storejs.d.ts b/storejs/storejs.d.ts index bb84cd646a..3c14a99ca5 100644 --- a/storejs/storejs.d.ts +++ b/storejs/storejs.d.ts @@ -2,4 +2,19 @@ // store.js exposes a simple API for cross browser local storage // Project: https://github.com/marcuswestin/store.js/ // Definitions by: Vincent Bortone -// Definitions: https://github.com/borisyankov/DefinitelyTyped \ No newline at end of file +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface StoreJSStatic { + set(key: string, value: any): any; + get(key: string): any; + remove(key: string): void; + clear(): void; + enabled: bool; + disabled: bool; + transact(key: string, defaultValue: any, transactionFn?: (val: any) => void): void; + getAll(): any; + serialize(value: any): string; + deserialize(value: string): any; +} + +declare var store: StoreJSStatic; \ No newline at end of file