forked from commenthol/serialize-to-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d84b383
commit 9302c75
Showing
12 changed files
with
1,914 additions
and
1,816 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
coverage/* | ||
dist/* | ||
*.bundle.js | ||
tmp | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "serialize-to-js", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "serialize objects to javascript", | ||
"keywords": [ | ||
"javascript", | ||
|
@@ -16,7 +16,7 @@ | |
"url": "git+https://github.com/commenthol/serialize-to-js.git" | ||
}, | ||
"license": "MIT", | ||
"author": "commenthol <[email protected]>", | ||
"author": "EmileSonneveld <[email protected]>", | ||
"main": "lib", | ||
"module": "src", | ||
"directories": { | ||
|
@@ -39,15 +39,15 @@ | |
] | ||
}, | ||
"eslintConfig": { | ||
"parserOptions": { | ||
"ecmaVersion": 2019 | ||
}, | ||
"env": { | ||
"mocha": true | ||
}, | ||
"extends": "standard", | ||
"plugins": [ | ||
"standard" | ||
], | ||
"rules": { | ||
"key-spacing": 0 | ||
"key-spacing": 0, | ||
"indent": ["error", 2, { "SwitchCase": 1 }] | ||
} | ||
}, | ||
"dependencies": {}, | ||
|
@@ -56,12 +56,7 @@ | |
"@babel/core": "^7.8.3", | ||
"@babel/preset-env": "^7.8.3", | ||
"chai": "^4.1.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-standard": "^14.1.0", | ||
"eslint-plugin-import": "^2.20.0", | ||
"eslint-plugin-node": "^11.0.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"eslint": "^8.19.0", | ||
"mocha": "^7.0.1", | ||
"nyc": "^15.0.0", | ||
"rimraf": "^3.0.0", | ||
|
@@ -72,7 +67,8 @@ | |
"node": ">=4.0.0" | ||
}, | ||
"maintainers": [ | ||
"commenthol <[email protected]>" | ||
"commenthol <[email protected]>", | ||
"EmileSonneveld <[email protected]>" | ||
], | ||
"mocha": { | ||
"check-leaks": true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
/** | ||
* Wrapper around indexedDB. (It has a pretty usly API) | ||
* If you use <5Mb of data, I reccomend localStorage. It has a nice sync API. | ||
* Wrapper around indexedDB. (It has a pretty ugly API) | ||
* If you use <5Mb of data, I recommend localStorage. It has a nice sync API. | ||
*/ | ||
function IndexedDbStorageConstructor(dbName) { | ||
let db = null; | ||
let db = null; | ||
|
||
async function getIdValueobjectStore() { | ||
return new Promise((resolve, reject) => { | ||
if (db) { | ||
const customerObjectStore = db.transaction("idValueobjectStore", "readwrite") | ||
.objectStore("idValueobjectStore"); | ||
resolve(customerObjectStore) | ||
} | ||
async function getIdValueObjectStore() { | ||
return new Promise((resolve, reject) => { | ||
if (db) { | ||
const customerObjectStore = db.transaction("idValueObjectStore", "readwrite") | ||
.objectStore("idValueObjectStore"); | ||
resolve(customerObjectStore) | ||
} | ||
|
||
const request = indexedDB.open(dbName, 1); | ||
const request = indexedDB.open(dbName, 1); | ||
|
||
request.onupgradeneeded = event => { | ||
db = event.target.result; | ||
request.onupgradeneeded = event => { | ||
db = event.target.result; | ||
|
||
const objectStore = db.createObjectStore("idValueobjectStore", {keyPath: "id", autoIncrement: false}); | ||
objectStore.createIndex("id", "id", {unique: true}); | ||
// objectStore.createIndex("value", "value", {unique: false}); // could be performance burden? Not tested | ||
const objectStore = db.createObjectStore("idValueObjectStore", {keyPath: "id", autoIncrement: false}); | ||
objectStore.createIndex("id", "id", {unique: true}); | ||
// objectStore.createIndex("value", "value", {unique: false}); // could be performance burden? Not tested | ||
|
||
// objectStore.transaction.oncomplete = event => { | ||
// // 'request.onsuccess' gets called after this, so no need to wait | ||
// }; | ||
}; | ||
// objectStore.transaction.oncomplete = event => { | ||
// // 'request.onsuccess' gets called after this, so no need to wait | ||
// }; | ||
}; | ||
|
||
request.onsuccess = event => { | ||
try { | ||
db = event.target.result; | ||
const customerObjectStore = db.transaction("idValueobjectStore", "readwrite") | ||
.objectStore("idValueobjectStore"); | ||
resolve(customerObjectStore) | ||
} catch (e) { | ||
// Example of possible errors: | ||
// NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found. | ||
reject(e) | ||
} | ||
}; | ||
request.onsuccess = event => { | ||
try { | ||
db = event.target.result; | ||
const customerObjectStore = db.transaction("idValueObjectStore", "readwrite") | ||
.objectStore("idValueObjectStore"); | ||
resolve(customerObjectStore) | ||
} catch (e) { | ||
// Example of possible errors: | ||
// NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found. | ||
reject(e); | ||
} | ||
}; | ||
|
||
// Example of possible errors: | ||
// "AbortError: Version change transaction was aborted in upgradeneeded event handler." | ||
// "VersionError: The requested version (1) is less than the existing version (2)." | ||
request.onerror = (e) => reject(e.target.error) | ||
}); | ||
} | ||
// Example of possible errors: | ||
// "AbortError: Version change transaction was aborted in upgradeneeded event handler." | ||
// "VersionError: The requested version (1) is less than the existing version (2)." | ||
request.onerror = (e) => reject(e.target.error) | ||
}); | ||
} | ||
|
||
async function setItem(id, value) { | ||
return new Promise((resolve, reject) => { | ||
// Can't make executor async, because async errors don't trigger 'reject' in promise. | ||
getIdValueobjectStore().then(store => { | ||
const request = store.put({id, value}) | ||
request.onsuccess = () => { | ||
resolve(request.result ? request.result.value : null) | ||
}; | ||
request.onerror = reject | ||
}).catch(reject); | ||
}) | ||
} | ||
async function setItem(id, value) { | ||
return new Promise((resolve, reject) => { | ||
// Can't make executor async, because async errors don't trigger 'reject' in promise. | ||
getIdValueObjectStore().then(store => { | ||
const request = store.put({id, value}) | ||
request.onsuccess = () => { | ||
resolve(request.result ? request.result.value : null) | ||
}; | ||
request.onerror = reject | ||
}).catch(reject); | ||
}) | ||
} | ||
|
||
function getItem(id) { | ||
return new Promise((resolve, reject) => { | ||
// Can't make executor async, because async errors don't trigger 'reject' in promise. | ||
getIdValueobjectStore().then(store => { | ||
const request = store.get(id) | ||
request.onsuccess = () => { | ||
resolve(request.result ? request.result.value : null) | ||
}; | ||
request.onerror = reject | ||
}).catch(reject); | ||
}) | ||
} | ||
function getItem(id) { | ||
return new Promise((resolve, reject) => { | ||
// Can't make executor async, because async errors don't trigger 'reject' in promise. | ||
getIdValueObjectStore().then(store => { | ||
const request = store.get(id) | ||
request.onsuccess = () => { | ||
resolve(request.result ? request.result.value : null) | ||
}; | ||
request.onerror = reject | ||
}).catch(reject); | ||
}) | ||
} | ||
|
||
return {getIdValueobjectStore, setItem, getItem} | ||
return {getIdValueObjectStore, setItem, getItem} | ||
} | ||
|
||
indexedDbStorage = IndexedDbStorageConstructor("dbStj") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.