Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export function initRouter(root) {
renderPageTransition(root, `<section class="py-24 text-center">\n <h1 class="text-3xl font-semibold">Tool not found.</h1>\n <p class="mt-4 text-zinc-200/80">Double-check the URL or explore the tools hub.</p>\n </section>`);
return;
}
const module = await import(`./tools/${slug}.js`);
const toolModulePath = `./tools/${slug}.js`;
const module = await import(toolModulePath);
const view = module.default(tool);
renderPageTransition(root, view);
currentRoute = hash;
Expand Down
3 changes: 2 additions & 1 deletion js/tools/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function atobUrlSafe(value) {
const decoder = new TextDecoder('utf-8', { fatal: true });
return decoder.decode(bytes);
} catch (error) {
throw new Error(`Invalid base64url encoding: ${error.message}`);
const message = `Invalid base64url encoding: ${error.message}`;
throw new Error(message);
}
}
12 changes: 8 additions & 4 deletions js/tools/md.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,22 @@ function parseMarkdown(text) {
lines.forEach((line) => {
if (line.startsWith('# ')) {
flushList();
html.push(`<h1>${escapeHtml(line.slice(2))}</h1>`);
const heading = escapeHtml(line.slice(2));
html.push(`<h1>${heading}</h1>`);
} else if (line.startsWith('## ')) {
flushList();
html.push(`<h2>${escapeHtml(line.slice(3))}</h2>`);
const subheading = escapeHtml(line.slice(3));
html.push(`<h2>${subheading}</h2>`);
} else if (line.startsWith('- ')) {
list.push(`<li>${escapeHtml(line.slice(2))}</li>`);
const item = escapeHtml(line.slice(2));
list.push(`<li>${item}</li>`);
} else if (line.trim() === '') {
flushList();
html.push('<p class="h-4"></p>');
} else {
flushList();
html.push(`<p>${escapeHtml(line)}</p>`);
const paragraph = escapeHtml(line);
html.push(`<p>${paragraph}</p>`);
}
});
flushList();
Expand Down
16 changes: 10 additions & 6 deletions js/tools/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,18 @@ async function init() {
function validateData(schema, data, path) {
const errors = [];
if (schema.type) {
const typeError = (expected) => `${path} should be ${expected}`;
if (schema.type === 'object') {
if (typeof data !== 'object' || data === null || Array.isArray(data)) {
errors.push(`${path} should be an object`);
errors.push(typeError('an object'));
return errors;
}
if (schema.required) {
schema.required.forEach((key) => {
if (!(key in data)) errors.push(`${path} missing required property ${key}`);
if (!(key in data)) {
const missingPropertyMessage = `${path} missing required property ${key}`;
errors.push(missingPropertyMessage);
}
});
}
if (schema.properties) {
Expand All @@ -95,18 +99,18 @@ function validateData(schema, data, path) {
}
} else if (schema.type === 'array') {
if (!Array.isArray(data)) {
errors.push(`${path} should be an array`);
errors.push(typeError('an array'));
} else if (schema.items) {
data.forEach((item, index) => {
errors.push(...validateData(schema.items, item, `${path}/${index}`));
});
}
} else if (schema.type === 'string') {
if (typeof data !== 'string') errors.push(`${path} should be a string`);
if (typeof data !== 'string') errors.push(typeError('a string'));
} else if (schema.type === 'number') {
if (typeof data !== 'number') errors.push(`${path} should be a number`);
if (typeof data !== 'number') errors.push(typeError('a number'));
} else if (schema.type === 'boolean') {
if (typeof data !== 'boolean') errors.push(`${path} should be a boolean`);
if (typeof data !== 'boolean') errors.push(typeError('a boolean'));
}
}
return errors;
Expand Down
3 changes: 2 additions & 1 deletion js/tools/sqlfmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ function formatSql(sql) {
} else if (token === 'BY') {
current.push(token);
} else if (token === 'AND' || token === 'OR') {
current.push(`\n ${token}`);
const clauseToken = `\n ${token}`;
current.push(clauseToken);
} else {
current.push(token);
}
Expand Down
3 changes: 2 additions & 1 deletion js/utils/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export function convertToZone(date, zone = 'UTC') {
second: '2-digit'
}).format(safeDate);
} catch (error) {
throw new Error(`Unsupported time zone: ${zone}`);
const message = `Unsupported time zone: ${zone}`;
throw new Error(message);
}
}

Expand Down