import { type Maybe } from '../value/maybe.type'; /** * A character or string that is added to the start of a string. * * Example: '-' in "-class" * * @semanticType * @semanticTopic string * @semanticTopic dereekb-util:prefix */ export type CharacterPrefix = string; /** * A character or string that is added to the end of a string. * * Example: '-' in "class-" * * @semanticType * @semanticTopic string * @semanticTopic dereekb-util:prefix */ export type CharacterSuffix = string; /** * Does not have a CharacterPrefix or CharacterSuffix. * * @semanticType * @semanticTopic string * @semanticTopic dereekb-util:prefix */ export type CharacterPrefixSuffixCleanString = string; /** * Is a combination of a prefix and suffix. */ export type CharacterPrefixSuffixString
= `${P}${T}${S}`; /** * Has a known prefix. */ export type CharacterPrefixString
= CharacterPrefixSuffixString
;
/**
* Has a known suffix.
*/
export type CharacterSuffixString = CharacterPrefixSuffixString<'', S, T>;
/**
* Configuration for creating a {@link CharacterPrefixSuffixInstance} that manages adding and removing prefix/suffix strings.
*
* @template P - The prefix string type.
* @template S - The suffix string type.
*/
export interface CharacterPrefixSuffixInstanceConfiguration
{ /** * The prefix characters to add/remove to/from the start of the string. */ readonly prefix?: Maybe
;
/**
* The suffix characters to add/remove to/from the end of the string.
*/
readonly suffix?: Maybe;
/**
* If true, the prefix will be added to empty strings.
*/
readonly prefixEmptyString?: boolean | undefined;
/**
* If true, the suffix will be added to empty strings.
*/
readonly suffixEmptyString?: boolean | undefined;
}
/**
* Instance that can add or remove a configured prefix and/or suffix from strings.
*
* @template P - The prefix string type.
* @template S - The suffix string type.
*/
export interface CharacterPrefixSuffixInstance
extends CharacterPrefixSuffixInstanceConfiguration
{
/**
* Adds the prefix and suffix to the input string. Cleans any existing prefix/suffix before adding.
*
* @param input - The string to prefix and suffix.
* @returns The string with prefix and suffix applied.
*/
prefixSuffixString(input: ''): string;
prefixSuffixString | CharacterPrefixString | CharacterSuffixString ;
prefixSuffixString(input: string): CharacterPrefixSuffixString ;
/**
* Removes the prefix and suffix from the input string, stripping repeated occurrences.
*
* @param input - The string to clean.
* @returns The string with prefix and suffix removed.
*/
cleanString | CharacterPrefixString | CharacterSuffixString (config: CharacterPrefixSuffixInstanceConfiguration ): CharacterPrefixSuffixInstance ;
/**
* Removes the given suffix from the input string when present, or
* returns `undefined` when the input does not end with the suffix.
*
* Use this when callers want to detect whether the suffix was present
* (vs. {@link removeFirstMatchingSuffix}, which silently passes the
* input through).
*
* @param input - The string to trim.
* @param suffix - The suffix to remove.
* @returns The input without the suffix, or `undefined` when the input
* does not end with the suffix.
*/
export declare function removeSuffix(input: string, suffix: string): Maybe): CharacterPrefixSuffixString): T;
cleanString(input: string): string;
}
/**
* Creates a {@link CharacterPrefixSuffixInstance} that can add or remove configured prefix/suffix strings.
*
* @param config - Configuration specifying the prefix, suffix, and empty string behavior.
* @returns A new instance for managing prefix/suffix operations on strings.
*/
export declare function characterPrefixSuffixInstance