Skip to content

Commit

Permalink
Eslint. Addon update. Varia.
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileSonneveld committed Jul 3, 2022
1 parent d84b383 commit 9302c75
Show file tree
Hide file tree
Showing 12 changed files with 1,914 additions and 1,816 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
coverage/*
dist/*
*.bundle.js
tmp
lib
24 changes: 10 additions & 14 deletions package.json
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",
Expand All @@ -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": {
Expand All @@ -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": {},
Expand All @@ -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",
Expand All @@ -72,7 +67,8 @@
"node": ">=4.0.0"
},
"maintainers": [
"commenthol <[email protected]>"
"commenthol <[email protected]>",
"EmileSonneveld <[email protected]>"
],
"mocha": {
"check-leaks": true
Expand Down
7 changes: 5 additions & 2 deletions serialise-to-js-addon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ JS Search
=========
_Emile Sonneveld_

2 tools:
This addon helps to find variable paths in your JavaScript application. There are 2 ways of doing this:
- "Value search"': When you know what value the variable has, you can use this to find how to acces this variable.
- "Change search": When you want to find what variables are changed after performing an action.

Second option works by serialising all that is accessible from withing the window object in a big JavaScript string 2 times. Once before a user interaction and once after. A simple diff algorithm is used to see what variables changed. An optional 3th capture can be done to remove noisy variables from the selection that changed without user interaction.


![](screenshot.png)
![](screenshot.png)

Uploaded to chrome store here: https://chrome.google.com/webstore/detail/js-picking/jjljfhnjkinelaaagkkamlaaflhfmlpc/
126 changes: 63 additions & 63 deletions serialise-to-js-addon/indexedDbStorage.js
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")
4 changes: 2 additions & 2 deletions serialise-to-js-addon/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "JS Search",
"description": "Search how to get a certain value in JS!",
"name": "JS Picking",
"description": "Find the JavaScript variables in the midst of chaos",
"version": "1.0",
"manifest_version": 3,
"permissions": [
Expand Down
Loading

0 comments on commit 9302c75

Please sign in to comment.