From ba13007dce63d211eb6a168f502f58af01a6ca1f Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Wed, 28 Feb 2024 11:30:33 -0300 Subject: src/utils.mjs: Define strSortFn() and use it on all files --- src/accretion.mjs | 3 +-- src/hero.mjs | 4 ++-- src/utils.mjs | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/accretion.mjs b/src/accretion.mjs index 1c70162..dd3372c 100644 --- a/src/accretion.mjs +++ b/src/accretion.mjs @@ -26,8 +26,7 @@ export const runMigrations = async (logFn, db) => { .map(row => row.filename); const allFiles = fs.readdirSync(MIGRATIONS_DIR, "UTF-8"); const pending = u.difference(new Set(allFiles), new Set(done)); - const sortedPending = [...pending] - .sort((a, b) => a.localeCompare(b, "POSIX")); + const sortedPending = [...pending].sort(u.strSortFn); for (const filename of sortedPending) { logFn({ log: "exec-migration", filename }); diff --git a/src/hero.mjs b/src/hero.mjs index 268136f..c249d4f 100644 --- a/src/hero.mjs +++ b/src/hero.mjs @@ -31,7 +31,7 @@ const HTTP_METHODS = new Set([ "OPTIONS", ]); -const HTTP_METHODS_ARR = [...HTTP_METHODS.keys()].sort(); +const HTTP_METHODS_ARR = [...HTTP_METHODS.keys()].sort(u.strSortFn); export const addRoute = (table, methods, path, handlerFn) => { if (methods === "*") { @@ -88,7 +88,7 @@ export const firstParamMatch = (tree, segments, params) => { // literal matching failed, we now look for patterns that might match const paramOptions = Object.keys(tree) .filter(s => s.startsWith(":")) - .sort(); + .sort(u.strSortFn); return u.first(paramOptions, param => firstParamMatch(tree[param], nextSegments, { ...params, [param.slice(1)]: seg diff --git a/src/utils.mjs b/src/utils.mjs index c671f0f..cde6934 100644 --- a/src/utils.mjs +++ b/src/utils.mjs @@ -80,3 +80,5 @@ export const promisify = fn => (...args) => export const partial = (fn, ...startArgs) => (...endArgs) => fn(...startArgs, ...endArgs); + +export const strSortFn = (a, b) => a.localeCompare(b, "POSIX"); -- cgit v1.2.3