• Given a potentially partial prefix like hell, this finds the matching name in the keys, but only if it is unique! Please note, that ... is considered special here, anything afteR ... will not be matched by prefix but only by exact name, following R's pmatch semantics.

    Parameters

    • prefix: string
    • keys: readonly string[] | MapIterator<string>

    Returns undefined | string

    findByPrefixIfUnique('hello', [ 'hello', 'bar' ]) // => 'hello'
    findByPrefixIfUnique('hell', [ 'hello', 'bar' ]) // => 'hello'
    findByPrefixIfUnique('hell', [ 'hello', 'hell' ]) // => 'hell' (full/exact match)
    findByPrefixIfUnique('hell', [ 'bar', '...', 'hello' ]) // => undefined (not matched due to being after `...`)
    findByPrefixIfUnique('h', [ 'hello', 'hell' ]) // => undefined (not unique)
    findByPrefixIfUnique('', [ 'hello', 'hell' ]) // => undefined (empty prefix)