diff --git a/js/router.js b/js/router.js index 402d20e..588df1c 100644 --- a/js/router.js +++ b/js/router.js @@ -48,7 +48,8 @@ export function initRouter(root) { renderPageTransition(root, `
\n

Tool not found.

\n

Double-check the URL or explore the tools hub.

\n
`); 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; diff --git a/js/tools/jwt.js b/js/tools/jwt.js index a52a949..b14fbae 100644 --- a/js/tools/jwt.js +++ b/js/tools/jwt.js @@ -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); } } diff --git a/js/tools/md.js b/js/tools/md.js index 91bc356..ce054df 100644 --- a/js/tools/md.js +++ b/js/tools/md.js @@ -56,18 +56,22 @@ function parseMarkdown(text) { lines.forEach((line) => { if (line.startsWith('# ')) { flushList(); - html.push(`

${escapeHtml(line.slice(2))}

`); + const heading = escapeHtml(line.slice(2)); + html.push(`

${heading}

`); } else if (line.startsWith('## ')) { flushList(); - html.push(`

${escapeHtml(line.slice(3))}

`); + const subheading = escapeHtml(line.slice(3)); + html.push(`

${subheading}

`); } else if (line.startsWith('- ')) { - list.push(`
  • ${escapeHtml(line.slice(2))}
  • `); + const item = escapeHtml(line.slice(2)); + list.push(`
  • ${item}
  • `); } else if (line.trim() === '') { flushList(); html.push('

    '); } else { flushList(); - html.push(`

    ${escapeHtml(line)}

    `); + const paragraph = escapeHtml(line); + html.push(`

    ${paragraph}

    `); } }); flushList(); diff --git a/js/tools/schema.js b/js/tools/schema.js index 44255b3..e721869 100644 --- a/js/tools/schema.js +++ b/js/tools/schema.js @@ -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) { @@ -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; diff --git a/js/tools/sqlfmt.js b/js/tools/sqlfmt.js index 9a6f82f..6e7da97 100644 --- a/js/tools/sqlfmt.js +++ b/js/tools/sqlfmt.js @@ -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); } diff --git a/js/utils/dates.js b/js/utils/dates.js index df739e2..850f22f 100644 --- a/js/utils/dates.js +++ b/js/utils/dates.js @@ -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); } }