Skip to content

Commit

Permalink
Formatted code with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom committed Jul 1, 2021
1 parent dd3566c commit 7a5b6ae
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 130 deletions.
6 changes: 3 additions & 3 deletions .webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const package = require("./package.json");
module.exports = {
entry: {
StormDB: "./src/stormdb.js",
BrowserEngine: "./src/engine/browser.js"
BrowserEngine: "./src/engine/browser.js",
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].min.js",
library: "[name]"
library: "[name]",
},
plugins: [new Webpack.BannerPlugin(`StormDB ${package.version}`)]
plugins: [new Webpack.BannerPlugin(`StormDB ${package.version}`)],
};
10 changes: 5 additions & 5 deletions docs/web/demos.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ const mapItemCode = `db.set("newList", [1, 2, 3]);\ndb.get("newList").map(x => x
const demos = {
setItem: {
code: setItemCode,
name: "Set Item"
name: "Set Item",
},
setItemPair: {
code: setItemPair,
name: "Set Item Pair"
name: "Set Item Pair",
},
deleteItem: {
code: deleteItemCode,
name: "Delete Item"
name: "Delete Item",
},
mapItem: {
code: mapItemCode,
name: "Map List"
}
name: "Map List",
},
};
34 changes: 17 additions & 17 deletions docs/web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function getQueryVariable(variable) {
return new URLSearchParams(window.location.search).get(variable);
}

var displayOutput = function(msg, colour = "black") {
var displayOutput = function (msg, colour = "black") {
const p = document.createElement("p");
p.textContent = msg;
p.classList += " output";
Expand Down Expand Up @@ -47,7 +47,7 @@ function syntaxHighlight(json) {
.replace(/>/g, ">");
return json.replace(
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
function(match) {
function (match) {
var cls = "number";
if (/^"/.test(match)) {
if (/:$/.test(match)) {
Expand All @@ -65,11 +65,11 @@ function syntaxHighlight(json) {
);
}

const getDBData = function() {
const getDBData = function () {
return JSON.stringify(db.value(), null, 4);
};

const updateDatabaseState = function() {
const updateDatabaseState = function () {
const dbData = getDBData();
stateContents.innerHTML = "";

Expand All @@ -83,7 +83,7 @@ function clearError() {
// update database state on load
updateDatabaseState();

runButton.addEventListener("click", function() {
runButton.addEventListener("click", function () {
clearError();
try {
let codeToRun = editor.getCode();
Expand All @@ -94,7 +94,7 @@ runButton.addEventListener("click", function() {
}
});

reloadButton.addEventListener("click", function() {
reloadButton.addEventListener("click", function () {
clearError();
try {
let loadedData = JSON.parse(localStorage.getItem("db"));
Expand All @@ -118,19 +118,19 @@ reloadButton.addEventListener("click", function() {
updateDatabaseState();
});

saveButton.addEventListener("click", function() {
saveButton.addEventListener("click", function () {
db.save();
});

resetButton.addEventListener("click", function() {
resetButton.addEventListener("click", function () {
clearError();
db.state = {};
localStorage.setItem("db", "{}");
updateDatabaseState();
});

const editor = new CodeFlask("#editor", {
lineNumbers: true
lineNumbers: true,
});

// demo selector logic
Expand All @@ -145,20 +145,20 @@ db.default({
string: "test",
numbers: 123,
objects: {
property: "test property"
}
property: "test property",
},
});
db.save();

demoKeys.forEach(key => {
demoKeys.forEach((key) => {
let demo = demos[key];
const option = document.createElement("option");
option.textContent = demo["name"];
option.value = key;
demoSelector.appendChild(option);
});

demoSelector.addEventListener("change", function() {
demoSelector.addEventListener("change", function () {
loadDemo(demoSelector.value);
});

Expand All @@ -171,22 +171,22 @@ if (queryCode !== null) {

async function loadVersion() {
fetch("https://unpkg.com/stormdb/package.json")
.then(function(response) {
.then(function (response) {
return response.json();
})
.then(function(data) {
.then(function (data) {
let versionNumber = data.version;

document.getElementById(
"versionNumber"
).innerText = `StormDB v${versionNumber}`;
})
.catch(function(error) {});
.catch(function (error) {});
}
loadVersion();

// copy URL function
copyButton.addEventListener("click", function() {
copyButton.addEventListener("click", function () {
let url = new URL(window.location.href);
url.searchParams.set("code", encodeURI(editor.getCode()));
navigator.clipboard.writeText(url);
Expand Down
4 changes: 2 additions & 2 deletions src/engine/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ module.exports = class LocalEngine {
// if async, return promise wrapper around async writefile
if (this.async) {
return new Promise(
function(resolve, reject) {
fs.writeFile(this.path, this.serialize(data), function(error) {
function (resolve, reject) {
fs.writeFile(this.path, this.serialize(data), function (error) {
if (error) return reject(error);
else resolve();
});
Expand Down
Loading

0 comments on commit 7a5b6ae

Please sign in to comment.