summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hero.mjs2
-rw-r--r--src/utils.mjs2
-rw-r--r--tests/js/utils.mjs16
3 files changed, 10 insertions, 10 deletions
diff --git a/src/hero.mjs b/src/hero.mjs
index fcbdc17..53f3086 100644
--- a/src/hero.mjs
+++ b/src/hero.mjs
@@ -89,7 +89,7 @@ export const firstParamMatch = (tree, segments, params) => {
const paramOptions = Object.keys(tree)
.filter(s => s.startsWith(":"))
.sort(u.strSortFn);
- return u.first(paramOptions, param => firstParamMatch(tree[param], nextSegments, {
+ return u.findFirst(paramOptions, param => firstParamMatch(tree[param], nextSegments, {
...params,
[param.slice(1)]: seg
}));
diff --git a/src/utils.mjs b/src/utils.mjs
index cb0c116..7d27c0d 100644
--- a/src/utils.mjs
+++ b/src/utils.mjs
@@ -29,7 +29,7 @@ export const getIn = (obj, path) =>
path.length === 0 ? obj :
getIn(obj?.[path[0]], path.slice(1));
-export const first = (arr, fn) => {
+export const findFirst = (arr, fn) => {
for (const x of arr) {
const ret = fn(x);
if (ret) {
diff --git a/tests/js/utils.mjs b/tests/js/utils.mjs
index 12b444b..ea5f4eb 100644
--- a/tests/js/utils.mjs
+++ b/tests/js/utils.mjs
@@ -6,7 +6,7 @@ import {
difference,
assocIn,
getIn,
- first,
+ findFirst,
partial,
strSortFn,
undefinedAsNull,
@@ -139,20 +139,20 @@ const test_getIn = t => {
});
};
-const test_first = t => {
- t.start("first()");
+const test_findFirst = t => {
+ t.start("findFirst()");
t.test("empty values", () => {
- assert.equal(first([], () => {}), null);
+ assert.equal(findFirst([], () => {}), null);
});
t.test("when function doesn't transform, it behaves similarly to [].find()", () => {
const arr1 = [ 0, null, undefined, "", 1, 2 ];
- assert.equal(first(arr1, x => x), 1);
+ assert.equal(findFirst(arr1, x => x), 1);
assert.equal(arr1.find(x => x), 1);
const arr2 = [ 0, null, undefined, "", false ];
- assert.equal(first(arr2, x => x), null);
+ assert.equal(findFirst(arr2, x => x), null);
assert.equal(arr2.find(x => x), undefined);
});
@@ -160,7 +160,7 @@ const test_first = t => {
const arr = [ 1, 3, 5, 6 ];
assert.equal(
- first(arr, x => x % 2 === 0 && "a brand new value"),
+ findFirst(arr, x => x % 2 === 0 && "a brand new value"),
"a brand new value",
);
});
@@ -274,7 +274,7 @@ await runner.runTests([
test_difference,
test_assocIn,
test_getIn,
- test_first,
+ test_findFirst,
test_partial,
test_strSortFn,
test_undefinedAsNull,