Adam S
06/21/2023, 8:35 AMMap<String, String?>
?
export default class Match {
getNamedCaptures(): NamedCaptures;
}
export type Capture = string | null;
export type NamedCaptures = { [key: string]: Capture };
Adam S
06/21/2023, 9:01 AMinternal external class Match {
/**
* Fetches all named captures, without their indices.
*/
fun getNamedCaptures(): NamedCaptures
}
/** `export type NamedCaptures = { [key: string]: string | null };` */
external interface NamedCaptures
private fun entriesOf(obj: dynamic): Map<String, Any?> {
return (js("Object.entries") as (dynamic) -> Array<Array<Any?>>)
.invoke(obj)
.associate { (name, entry) -> name as String to entry }
}
fun NamedCaptures.toMap(): Map<Any?, Any?> {
return entriesOf(this)
.mapValues { (_, v) -> v as String? }
}