diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/find.js | 19 | ||||
-rw-r--r-- | src/util/html.js | 2 | ||||
-rw-r--r-- | src/util/io.js | 8 | ||||
-rw-r--r-- | src/util/replacer.js | 20 | ||||
-rw-r--r-- | src/util/sugar.js | 13 | ||||
-rw-r--r-- | src/util/urls.js | 6 | ||||
-rw-r--r-- | src/util/wiki-data.js | 2 |
7 files changed, 31 insertions, 39 deletions
diff --git a/src/util/find.js b/src/util/find.js index 460a4fad..71026fa2 100644 --- a/src/util/find.js +++ b/src/util/find.js @@ -1,18 +1,19 @@ /** @format */ -import {color, logError, logWarn} from './cli.js'; +import {color, logWarn} from './cli.js'; import {inspect} from 'util'; function warnOrThrow(mode, message) { - switch (mode) { - case 'error': - throw new Error(message); - case 'warn': - logWarn(message); - default: - return null; + if (mode === 'error') { + throw new Error(message); } + + if (mode === 'warn') { + logWarn(message); + } + + return null; } function findHelper(keys, findFns = {}) { @@ -80,7 +81,7 @@ function findHelper(keys, findFns = {}) { }; } -function matchDirectory(ref, data, mode) { +function matchDirectory(ref, data) { return data.find(({directory}) => directory === ref); } diff --git a/src/util/html.js b/src/util/html.js index f5b7bdcc..0ba923b3 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -102,7 +102,7 @@ export function attributes(attribs) { `Attribute value for ${key} should be primitive or array, got ${typeof val}` ); }) - .filter(([key, val, keep]) => keep) + .filter(([_key, _val, keep]) => keep) .map(([key, val]) => typeof val === 'boolean' ? `${key}` diff --git a/src/util/io.js b/src/util/io.js index 5c1ab240..4a6e95f3 100644 --- a/src/util/io.js +++ b/src/util/io.js @@ -6,10 +6,10 @@ import {readdir} from 'fs/promises'; import * as path from 'path'; -export async function findFiles( - dataPath, - {filter = (f) => true, joinParentDirectory = true} = {} -) { +export async function findFiles(dataPath, { + filter = () => true, + joinParentDirectory = true, +} = {}) { return (await readdir(dataPath)) .filter((file) => filter(file)) .map((file) => (joinParentDirectory ? path.join(dataPath, file) : file)); diff --git a/src/util/replacer.js b/src/util/replacer.js index 6f4d0e9b..70c17e5f 100644 --- a/src/util/replacer.js +++ b/src/util/replacer.js @@ -1,5 +1,7 @@ /** @format */ +import fixWS from 'fix-whitespace'; + import {logError, logWarn} from './cli.js'; import {escapeRegex} from './sugar.js'; @@ -8,7 +10,7 @@ export function validateReplacerSpec(replacerSpec, {find, link}) { for (const [ key, - {link: linkKey, find: findKey, value, html}, + {link: linkKey, find: findKey, html}, ] of Object.entries(replacerSpec)) { if (!html && !link[linkKey]) { logError`The replacer spec ${key} has invalid link key ${linkKey}! Specify it in link specs or fix typo.`; @@ -58,7 +60,7 @@ const endOfInput = (i, comment) => // These are 8asically stored on the glo8al scope, which might seem odd // for a recursive function, 8ut the values are only ever used immediately // after they're set. -let stopped, stop_iMatch, stop_iParse, stop_literal; +let stopped, stop_iParse, stop_literal; function parseOneTextNode(input, i, stopAt) { return parseNodes(input, i, stopAt, true)[0]; @@ -66,7 +68,6 @@ function parseOneTextNode(input, i, stopAt) { function parseNodes(input, i, stopAt, textOnly) { let nodes = []; - let escapeNext = false; let string = ''; let iString = 0; @@ -103,7 +104,7 @@ function parseNodes(input, i, stopAt, textOnly) { // 8ut it's a pain to hard-code them all, so we dynamically gener8te // and cache them for reuse instead. let regexp; - if (regexpCache.hasOwnProperty(regexpSource)) { + if (Object.hasOwn(regexpCache, regexpSource)) { regexp = regexpCache[regexpSource]; } else { regexp = new RegExp(regexpSource); @@ -151,7 +152,6 @@ function parseNodes(input, i, stopAt, textOnly) { if (stopHere) { stopped = true; - stop_iMatch = closestMatchIndex; stop_iParse = i; stop_literal = closestMatch; break; @@ -332,15 +332,15 @@ export function parseInput(input) { const cursor = i - lineStart; throw new SyntaxError(fixWS` - Parse error (at pos ${i}): ${message} - ${line} - ${'-'.repeat(cursor) + '^'} - `); + Parse error (at pos ${i}): ${message} + ${line} + ${'-'.repeat(cursor) + '^'} + `); } } function evaluateTag(node, opts) { - const {find, input, language, link, replacerSpec, to, wikiData} = opts; + const {find, input, language, link, replacerSpec, to} = opts; const source = input.slice(node.i, node.iEnd); diff --git a/src/util/sugar.js b/src/util/sugar.js index 0a5de482..2883d949 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -90,7 +90,7 @@ export function delay(ms) { // There's a proposal for a native JS function like this, 8ut it's not even // past stage 1 yet: https://github.com/tc39/proposal-regex-escaping export function escapeRegex(string) { - return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); } export function bindOpts(fn, bind) { @@ -319,13 +319,6 @@ function _filterAggregate(mode, promiseAll, array, fn, aggregateOpts) { return value === aggregateOpts.returnOnFail ? value : value.input; } - function wrapperFunction(x, ...rest) { - return { - input: x, - output: fn(x, ...rest), - }; - } - if (mode === 'sync') { const result = array .map( @@ -426,9 +419,7 @@ export function showAggregate( error.errors .map((error) => recursive(error, {level: level + 1})) .flatMap((str) => str.split('\n')) - .map((line, i, lines) => - i === 0 ? ` ${head} ${line}` : ` ${bar} ${line}` - ) + .map((line, i) => i === 0 ? ` ${head} ${line}` : ` ${bar} ${line}`) .join('\n') ); } else { diff --git a/src/util/urls.js b/src/util/urls.js index ce747df2..45ec4c85 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -14,19 +14,19 @@ import * as path from 'path'; import {withEntries} from './sugar.js'; export function generateURLs(urlSpec) { - const getValueForFullKey = (obj, fullKey, prop = null) => { + const getValueForFullKey = (obj, fullKey) => { const [groupKey, subKey] = fullKey.split('.'); if (!groupKey || !subKey) { throw new Error(`Expected group key and subkey (got ${fullKey})`); } - if (!obj.hasOwnProperty(groupKey)) { + if (!Object.hasOwn(obj, groupKey)) { throw new Error(`Expected valid group key (got ${groupKey})`); } const group = obj[groupKey]; - if (!group.hasOwnProperty(subKey)) { + if (!Object.hasOwn(group, subKey)) { throw new Error( `Expected valid subkey (got ${subKey} for group ${groupKey})` ); diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 65eb7d7c..3e564b96 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -9,7 +9,7 @@ export function getKebabCase(name) { .split(' ') .join('-') .replace(/&/g, 'and') - .replace(/[^a-zA-Z0-9\-]/g, '') + .replace(/[^a-zA-Z0-9-]/g, '') .replace(/-{2,}/g, '-') .replace(/^-+|-+$/g, '') .toLowerCase(); |