Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Solved problem with webpack uglify #12

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
**********************************************************************************/
'use strict';

const FileSystemAccess = require('file-system/file-system-access').FileSystemAccess;
var FileSystemAccess = require('file-system/file-system-access').FileSystemAccess;

// So that code that is looking for the "Storage" object will pass its check
if (!global.Storage) {
global.Storage = function Storage() { }
}

if (!global.localStorage) {
let localStorageData = {};
let localStorageTimeout = null;
var localStorageData = {};
var localStorageTimeout = null;

const internalSaveData = function() {
let fsa = new FileSystemAccess();
let fileName = fsa.getDocumentsFolderPath() + "/localStorage.db";
var internalSaveData = function() {
var fsa = new FileSystemAccess();
var fileName = fsa.getDocumentsFolderPath() + "/localStorage.db";
try {
fsa.writeText(fileName, JSON.stringify(localStorageData));
} catch (err) {
Expand All @@ -29,23 +29,23 @@ if (!global.localStorage) {

};

const saveData = function() {
var saveData = function() {
if (localStorageTimeout !== null) {
clearTimeout(localStorageTimeout);
}
localStorageTimeout = setTimeout(internalSaveData, 250);
};

const loadData = function() {
let fsa = new FileSystemAccess();
let fileName = fsa.getDocumentsFolderPath() + "/localStorage.db";
var loadData = function() {
var fsa = new FileSystemAccess();
var fileName = fsa.getDocumentsFolderPath() + "/localStorage.db";
if (!fsa.fileExists(fileName)) {
return;
}
}

let data;
var data;
try {
let textData = fsa.readText(fileName);
var textData = fsa.readText(fileName);
data = JSON.parse(textData);
localStorageData = data;
}
Expand All @@ -65,7 +65,7 @@ if (!global.localStorage) {
return null;
},
key: function(id) {
const keys = Object.keys(localStorageData);
var keys = Object.keys(localStorageData);
if (id >= keys.length) { return null; }
return keys[id];
},
Expand Down Expand Up @@ -95,7 +95,7 @@ if (!global.localStorage) {


if (!global.sessionStorage) {
let sessionStorageData = {};
var sessionStorageData = {};

global.sessionStorage = {
getItem: function (name) {
Expand All @@ -105,7 +105,7 @@ if (!global.sessionStorage) {
return null;
},
key: function(id) {
const keys = Object.keys(sessionStorageData);
var keys = Object.keys(sessionStorageData);
if (id >= keys.length) { return null; }
return keys[id];
},
Expand All @@ -130,7 +130,4 @@ if (!global.sessionStorage) {
});
}




module.exports = global.localStorage;