feat(spec): add keyedBy(element, tags) identity helper

Joins element.find({testTag: tag})?.text per tag with U+001F as the
delimiter so user-visible text can never collide with the separator.
Returns empty string for an undefined element.
This commit is contained in:
pj committed 2026-04-27 00:03:45 +07:00
1 parent 4f8cb43bff
commit 6b50f2dbeb
3 files changed
+56 -2

No files matched your search

+13 -1
View File
@@ -1,5 +1,17 @@
import type { Extracted, State } from "./types.ts";
import type { AccessibilityElement, Extracted, State } from "./types.ts";
export function extract<T>(getter: (state: State) => T): Extracted<T> {
return globalThis.__sanderling__.extract(getter);
}
const KEY_DELIMITER = "\x1f";
export function keyedBy(
element: AccessibilityElement | undefined,
tags: readonly string[],
): string {
if (!element) return "";
return tags
.map(tag => element.find({ testTag: tag })?.text ?? "")
.join(KEY_DELIMITER);
}
+1 -1
View File
@@ -23,7 +23,7 @@ export type {
WeightedEntry,
} from "./types.ts";
export { extract } from "./extract.ts";
export { extract, keyedBy } from "./extract.ts";
export { always, eventually, next, now } from "./ltl.ts";
export {
InputText,