mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-03 19:47:10 +00:00
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:
1 parent
4f8cb43bff
commit
6b50f2dbeb
3 files changed
+56
-2
No files matched your search
+13
-1
@@ -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);
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user