@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
17 lines (16 loc) • 953 B
TypeScript
/**
* 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.
* @example
* ```typescript
* 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)
* ```
*/
export declare function findByPrefixIfUnique(prefix: string, keys: readonly string[] | MapIterator<string>): string | undefined;