Commit bca52a01 authored by Tristan Cavelier's avatar Tristan Cavelier

localstorage description creator redesigned

parent 09252852
...@@ -671,26 +671,49 @@ ...@@ -671,26 +671,49 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tools // Tools
function createLocalDescription(username, application_name) {
if (typeof username !== 'string') {
throw new TypeError("LocalStorage username must be a string");
}
var description = {
"type": "local",
"username": username
};
if (typeof application_name === 'string') {
description.application_name = application_name;
}
return description;
}
function createMemoryDescription(username, application_name) {
var description = createLocalDescription(username, application_name);
description.mode = "memory";
return description;
}
/** /**
* Tool to help users to create local storage description for JIO * Tool to help users to create local storage description for JIO
* *
* @param {String} username The username * @param {String} username The username
* @param {String} [application_name] The application_name * @param {String} [application_name] The application_name
* @param {String} [mode="localStorage"] Use localStorage or memory
* @return {Object} The storage description * @return {Object} The storage description
*/ */
function createDescription(username, application_name) { function createDescription(username, application_name, mode) {
var description = { if (mode === undefined || mode.toString() === 'localStorage') {
"type": "local", return createLocalDescription(username, application_name);
"username": username.toString()
};
if (application_name !== undefined) {
description.application_name = application_name.toString();
} }
return description; if (mode.toString() === 'memory') {
return createMemoryDescription(username, application_name);
}
throw new TypeError("Unknown LocalStorage '" + mode.toString() + "' mode");
} }
exports.createDescription = createDescription; exports.createDescription = createDescription;
exports.createLocalDescription = createLocalDescription;
exports.createMemoryDescription = createMemoryDescription;
function clear() { function clearLocalStorage() {
var k; var k;
for (k in localStorage) { for (k in localStorage) {
if (localStorage.hasOwnProperty(k)) { if (localStorage.hasOwnProperty(k)) {
...@@ -700,12 +723,13 @@ ...@@ -700,12 +723,13 @@
} }
} }
} }
exports.clear = clear;
exports.clearLocalStorage = clear;
function clearMemoryStorage() { function clearMemoryStorage() {
jIO.util.dictClear(ram); jIO.util.dictClear(ram);
} }
exports.clear = clearLocalStorage;
exports.clearLocalStorage = clearLocalStorage;
exports.clearMemoryStorage = clearMemoryStorage; exports.clearMemoryStorage = clearMemoryStorage;
})); }));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment