@cowwoc/requirements
Version:
A fluent API for enforcing design contracts with automatic message generation.
57 lines (56 loc) • 2.22 kB
text/typescript
import { Type, type StringMapper } from "../internal.mjs";
declare class SearchResult {
/**
* The start index (inclusive) of the matched text.
*/
readonly start: number;
/**
* The end index (exclusive) of the matched text.
*/
readonly end: number;
constructor(start: number, end: number);
}
/**
* Returns the last consecutive occurrence of `target` within `source`.
* The last occurrence of the empty string `""` is considered to occur at the index value
* `source.length()`.
* <p>
* The returned index is the largest value `k` for which
* `source.startsWith(target, k)` consecutively. If no such value of `k` exists, then
* `-1` is returned.
*
* @param source - the string to search within
* @param target - the string to search for
* @returns the index of the last consecutive occurrence of `target` in `source`,
* or `-1` if there is no such occurrence.
*/
declare function lastConsecutiveIndexOf(source: string, target: string): number;
/**
* Returns the last occurrence of `target` in `source`.
*
* @param source - the string to search within
* @param target - the regular expression to search for
* @returns null if no match was found
*/
declare function lastIndexOf(source: string, target: RegExp): SearchResult | null;
/**
* @param source - the string to search within
* @param target - the string to search for
* @returns true if `source` only contains (potentially multiple) occurrences of
* `target` or if `source` is empty
*/
declare function containsOnly(source: string, target: string): boolean;
/**
* Returns a StringMapper for a value or the closest ancestor that has an associated mapper.
*
* @param value - a value
* @param typeToMapper - a mapping from the name of a type to the string representation of its values
* @returns the StringMapper for the value
*/
declare function getMapper(value: unknown, typeToMapper: Map<Type, StringMapper>): StringMapper;
/**
* @param value - a string
* @returns true if the string does not contain any leading or trailing whitespace
*/
declare function valueIsStripped(value: string): boolean;
export { lastConsecutiveIndexOf, lastIndexOf, containsOnly, getMapper, valueIsStripped };