import { type ArrayOrValue } from '../array/array'; import { type MapFunction } from '../value/map'; import { type MaybeNot, type Maybe } from '../value/maybe.type'; /** * Converts a string to a value. */ export type MapStringFunction = MapFunction; /** * Reads a string from the input value. */ export type ReadStringFunction = MapFunction; /** * Represents a string that is made up of values separated by a delimiter. * * Optional generic typing exists for communicating what values are separated within the string. */ export type SeparatedString = string; /** * Represents a string that is made up of comma-separated values. * * Optional generic typing exists for communicating what values are separated within the string. * * I.E. 0,1,2 */ export type CommaSeparatedString = SeparatedString; /** * Represents a string that is made up of space-separated values. * * Optional generic typing exists for communicating what values are separated within the string. * * I.E. 0 1 2 */ export type SpaceSeparatedString = SeparatedString; /** * Default comma joiner character used by comma-related string functions. */ export declare const COMMA_JOINER = ","; /** * Default space joiner character used by space-related string functions. */ export declare const SPACE_JOINER = " "; /** * Joins an array of strings into a single string. Trims and omits empty values. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, join, concat, combine, separator, delimiter * @dbxUtilRelated split-join-remainder, join-strings-instance, string-split-join-instance * * @param input string or array of strings * @param joiner string to join the strings with. Defaults to a comma. * @param trim whether or not to trim the strings before joining. Defaults to false. * @returns joined string, or null/undefined if the input is null/undefined */ export declare function joinStrings(input: MaybeNot, joiner?: string, trim?: boolean): MaybeNot; export declare function joinStrings(input: ArrayOrValue>, joiner?: string, trim?: boolean): string; /** * Splits a string like {@link String.prototype.split}, but joins overflow segments back together * instead of discarding them. Useful when you only want to split on the first N-1 occurrences. * * @param input - String to split. * @param separator - Delimiter to split on. * @param limit - Maximum number of resulting segments; overflow segments are rejoined with the separator. * @returns Array of string segments, with length at most equal to limit. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, split, limit, separator, parts, segments * @dbxUtilRelated join-strings, string-split-join-instance */ export declare function splitJoinRemainder(input: string, separator: string, limit: number): string[]; /** * A callable instance that joins arrays of strings using a configured delimiter. * * Can be called directly as a function or accessed for its configuration properties. * * @example * ```ts * const join = joinStringsInstance({ joiner: ',' }); * join(['a', 'b', 'c']); // 'a,b,c' * join.joiner; // ',' * ``` */ export interface JoinStringsInstance { readonly joiner: string; readonly trimByDefault: boolean; (input: MaybeNot): MaybeNot; (input: ArrayOrValue>): T; (input: Maybe>>, trim?: boolean): Maybe; } /** * Configuration for creating a {@link JoinStringsInstance}. */ export interface JoinStringsInstanceConfig { /** * The delimiter character to use for splitting and joining. */ readonly joiner: string; /** * Whether or not to trim values before joining. * * Defaults to false. */ readonly trimByDefault?: boolean; } /** * Creates a {@link JoinStringsInstance} that joins arrays of strings using the configured delimiter. * * @param config - Configuration for the delimiter and default trim behavior. * @returns A new callable {@link JoinStringsInstance} * * @example * ```ts * const joinWithPipe = joinStringsInstance({ joiner: '|' }); * joinWithPipe(['a', 'b']); // 'a|b' * joinWithPipe(null); // null * ``` */ export declare function joinStringsInstance(config: JoinStringsInstanceConfig): JoinStringsInstance; /** * An instance that provides split and join operations for strings using a configured delimiter. * * @example * ```ts * const instance = stringSplitJoinInstance({ joiner: ',' }); * instance.joinStrings(['a', 'b', 'c']); // 'a,b,c' * instance.splitStrings('a,b,c'); // ['a', 'b', 'c'] * instance.splitStringsToSet('a,b,a'); // Set {'a', 'b'} * ``` */ export interface StringSplitJoinInstance extends Pick, 'joiner' | 'trimByDefault'> { /** * Joins an array of strings into a single delimited string. Filters out null/undefined values. */ joinStrings(input: MaybeNot): MaybeNot; joinStrings(input: ArrayOrValue>): T; joinStrings(input: Maybe>>, trim?: boolean): Maybe; /** * Splits a delimited string into an array of trimmed strings, optionally mapping each value. */ splitStrings(input: T): string[]; splitStrings(input: T, mapFn: MapStringFunction): O[]; /** * Splits a delimited string into a Set of unique trimmed string values. * * Returns an empty set if the input is null/undefined. */ splitStringsToSet(input: Maybe): Set; /** * Splits the input string by the configured delimiter, joining overflow segments back together * instead of discarding them. Useful when you only want to split on the first N-1 occurrences. * * @param input - string to split * @param limit - maximum number of resulting segments; overflow segments are rejoined with the delimiter * @returns array of string segments, with length at most equal to limit */ splitJoinRemainder(input: string, limit: number): string[]; } /** * Configuration for creating a {@link StringSplitJoinInstance}. */ export type StringSplitJoinInstanceConfig = JoinStringsInstanceConfig; /** * Creates a {@link StringSplitJoinInstance} that splits and joins strings using the configured delimiter. * * @param config - Configuration for the delimiter and default trim behavior. * @returns A new {@link StringSplitJoinInstance} * * @example * ```ts * const pipeSplitJoin = stringSplitJoinInstance({ joiner: '|' }); * pipeSplitJoin.joinStrings(['a', 'b']); // 'a|b' * pipeSplitJoin.splitStrings('a|b'); // ['a', 'b'] * ``` */ export declare function stringSplitJoinInstance(config: StringSplitJoinInstanceConfig): StringSplitJoinInstance; /** * Global {@link StringSplitJoinInstance} that uses commas as the delimiter. */ export declare const COMMA_STRING_SPLIT_JOIN: StringSplitJoinInstance; /** * Global {@link StringSplitJoinInstance} that uses spaces as the delimiter, with trimming enabled by default. */ export declare const SPACE_STRING_SPLIT_JOIN: StringSplitJoinInstance; /** * Converts a string to its lowercase equivalent for case-insensitive comparison. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, lowercase, case, normalize, compare * @dbxUtilRelated capitalize-first-letter, lowercase-first-letter * * @param input - string to convert to lowercase * @returns the lowercased string, or undefined if the input is undefined */ export declare function caseInsensitiveString(input: string): string; export declare function caseInsensitiveString(input: undefined): undefined; export declare function caseInsensitiveString(input: Maybe): Maybe; /** * Adds a plus prefix to the input value and converts it to a string. If the value is negative or 0, no prefix is added. * * Undefined is returned if a null/undefined value is input. * * @param value - The number to prefix. * @param prefix - The prefix character to use for positive numbers; defaults to '+'. * @returns The prefixed string, or undefined if the input is null/undefined. */ export declare function addPlusPrefixToNumber(value?: Maybe, prefix?: string): Maybe; /** * Capitalizes the first letter of the input string. * * @param value - String to capitalize. * @returns The input string with its first character uppercased. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, capitalize, case, uppercase, first * @dbxUtilRelated lowercase-first-letter, case-insensitive-string */ export declare function capitalizeFirstLetter(value: string): string; /** * Lowercases the first letter of the input string. * * @param value - String to modify. * @returns The input string with its first character lowercased. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, lowercase, case, first, decapitalize * @dbxUtilRelated capitalize-first-letter, case-insensitive-string */ export declare function lowercaseFirstLetter(value: string): string; /** * A tuple of [firstName, lastName] where lastName may be undefined if the input has no space. */ export type FirstNameLastNameTuple = [string, Maybe]; /** * Splits the input string into a first name and last name tuple using a space as the delimiter. * If the name contains more than one space, the remainder is treated as the last name. * * @param input - Full name string to split. * @returns A tuple of [firstName, lastName], where lastName includes all text after the first space. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, name, split, first, last, person, parse * @dbxUtilRelated split-join-remainder */ export declare function splitJoinNameString(input: string): FirstNameLastNameTuple; /** * Default maximum number of initials produced by a {@link NameToInitialsFunction}. */ export declare const DEFAULT_NAME_TO_INITIALS_MAX_INITIALS = 2; /** * Default minimum number of initials produced by a {@link NameToInitialsFunction}. */ export declare const DEFAULT_NAME_TO_INITIALS_MIN_INITIALS = 1; /** * Configuration for creating a {@link NameToInitialsFunction}. */ export interface NameToInitialsConfig { /** * Maximum number of initials to produce. * * Caps the number of leading words used for multi-word inputs and the number of leading characters used for single-word inputs. Defaults to {@link DEFAULT_NAME_TO_INITIALS_MAX_INITIALS}. */ readonly maxInitials?: Maybe; /** * Minimum number of initials to produce. * * For a single-word input this many leading characters are taken (capped by `maxInitials` and the word's length). Defaults to {@link DEFAULT_NAME_TO_INITIALS_MIN_INITIALS}. */ readonly minInitials?: Maybe; } /** * Derives display initials from a name or short character string. * * Multi-word inputs use the first character of each of the first `maxInitials` words; single-word * inputs use the first `minInitials` characters verbatim. The result is always uppercased. */ export type NameToInitialsFunction = (name: string) => string; /** * Creates a {@link NameToInitialsFunction} that derives display initials from a name or short character string. * * Useful for avatar fallbacks where a name (e.g. `'Michelle B'`) or a literal token (e.g. `'BB'`) * should collapse to a compact label. By default a single-word input yields a single initial; raise * `minInitials` to pull more leading characters from a lone word. * * @param config - Configuration controlling the minimum and maximum number of initials. * @returns A reusable function that derives initials from input names. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilKind factory * @dbxUtilTags string, name, initials, avatar, abbreviate, person, factory * @dbxUtilRelated split-join-name-string, capitalize-first-letter * * @example * ```ts * const toInitials = nameToInitialsFactory(); * toInitials('Michelle B'); // 'MB' * toInitials('Michelle'); // 'M' * * const toPaddedInitials = nameToInitialsFactory({ minInitials: 2 }); * toPaddedInitials('Michelle'); // 'MI' * toPaddedInitials('BB'); // 'BB' * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function nameToInitialsFactory(config?: Maybe): NameToInitialsFunction; /** * Derives display initials from a name or short character string using the default configuration. * * Multi-word inputs use the first character of each of the first two words; single-word inputs use * the first character verbatim. The result is always uppercased. * * @param name - Name or character string to derive initials from. * @returns Uppercased initials, or an empty string when the input is blank. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, name, initials, avatar, abbreviate, person * @dbxUtilRelated name-to-initials-factory, split-join-name-string, capitalize-first-letter * * @example * ```ts * nameToInitials('Michelle B'); // 'MB' * nameToInitials('A'); // 'A' * nameToInitials('BB'); // 'B' * nameToInitials('Michelle'); // 'M' * ``` */ export declare const nameToInitials: NameToInitialsFunction; /** * Creates a string that repeats the given string a specified number of times. * * @param string - The string to repeat. * @param reapeat - Number of times to repeat the string. * @returns The repeated string concatenation. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, repeat, build, generate, fill */ export declare function repeatString(string: string, reapeat: number): string; /** * Configuration for creating a {@link CutStringFunction}. */ export interface CutStringFunctionConfig { /** * Max length of the string. */ readonly maxLength: number; /** * Whether or not the end text addition should be included in the max length computation. * * If false, then the input string will be cut at the max length. */ readonly maxLengthIncludesEndText?: Maybe; /** * The end text to add to the cut string. * * Defaults to "...". */ readonly endText?: Maybe; } /** * Default ellipsis text appended when a string is truncated by {@link cutStringFunction}. */ export declare const DEFAULT_CUT_STRING_END_TEXT = "..."; /** * Truncates a string to a configured maximum length, optionally appending end text. */ export type CutStringFunction = ((input: string) => string) & ((input: Maybe) => Maybe); /** * Creates a {@link CutStringFunction} that truncates strings exceeding the configured maximum length. * * @param config - Configuration controlling max length and end text behavior. * @returns A reusable function that truncates input strings. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilKind factory * @dbxUtilTags string, cut, truncate, ellipsis, max-length, factory, abbreviate * * @__NO_SIDE_EFFECTS__ */ export declare function cutStringFunction(config: CutStringFunctionConfig): CutStringFunction; /** * Truncates a string to the given maximum length, appending end text (defaults to "...") if truncated. * * @param input - The string to truncate, or null/undefined. * @param maxLength - Maximum allowed length for the output string. * @param endText - Text to append when truncated; defaults to "...". * @returns The truncated string, or null/undefined if the input is null/undefined. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, cut, truncate, ellipsis, max-length, abbreviate, shorten * @dbxUtilRelated cut-string-function */ export declare function cutString(input: Maybe, maxLength: number, endText?: Maybe): Maybe; /** * Collapses consecutive whitespace characters (excluding newlines) into a single space, then trims. * * Newlines are preserved. * * @param input - String to flatten. * @returns The string with collapsed whitespace. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, whitespace, flatten, collapse, normalize, trim * @dbxUtilRelated simplify-whitespace */ export declare function flattenWhitespace(input: string): string; /** * Reduces multiple consecutive newlines to a single newline and collapses multiple whitespace characters to a single space. * * @param input - String to simplify. * @returns The string with simplified whitespace and newlines. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, whitespace, simplify, normalize, newline, trim * @dbxUtilRelated flatten-whitespace */ export declare function simplifyWhitespace(input: string): string; /** * Matches CRLF and bare CR line breaks so they can be normalized to LF. */ export declare const LINE_BREAK_NORMALIZATION_REGEX: RegExp; /** * Normalizes every CRLF and bare CR line break in the input to a single LF. * * Useful ahead of any per-character transform, which would otherwise treat a single CRLF as two line breaks. * * @param input - String to normalize. * @returns The string with all line breaks rendered as LF. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, whitespace, newline, line-break, normalize, crlf * @dbxUtilRelated simplify-whitespace, flatten-whitespace */ export declare function normalizeLineBreaks(input: string): string; /** * Returns true if the input is a string with at least one non-whitespace character. * * Useful for deciding whether an optional string value is worth emitting. * * @param input - The value to test. * @returns Whether the value is a non-blank string. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, whitespace, blank, empty, predicate, type-guard * @dbxUtilRelated flatten-whitespace */ export declare function isNotBlankString(input: Maybe): input is string; /** * Joins an array of strings into a single string using commas. Does not trim empty values by default. * * Delegates to {@link COMMA_STRING_SPLIT_JOIN}. * * @param input string or array of strings * @param trim whether or not to trim the strings before joining. Defaults to false. * @returns joined string, or null/undefined if the input is null/undefined */ export declare const joinStringsWithCommas: { (input: MaybeNot): MaybeNot; (input: ArrayOrValue>): string; (input: Maybe>>, trim?: boolean): Maybe; }; /** * Splits a comma-separated string into an array of strings. * * Delegates to {@link COMMA_STRING_SPLIT_JOIN}. * * @param input string to split * @param mapFn function to map each split string to a value * @returns array of strings */ export declare const splitCommaSeparatedString: { (input: string): string[]; (input: string, mapFn: MapStringFunction): O[]; }; /** * Splits a comma-separated string into a Set of unique trimmed string values. * * Delegates to {@link COMMA_STRING_SPLIT_JOIN}. * * @param input - comma-separated string to split, or null/undefined * @returns a Set of unique string values; empty Set if input is null/undefined */ export declare const splitCommaSeparatedStringToSet: (input: Maybe) => Set; /** * Joins one or more strings together with spaces. Extra spaces are trimmed from the values. * * Delegates to {@link SPACE_STRING_SPLIT_JOIN}. * * @param input string or array of strings * @returns joined string, or null/undefined if the input is null/undefined */ export declare const joinStringsWithSpaces: { (input: MaybeNot): MaybeNot; (input: ArrayOrValue>): string; (input: Maybe>>, trim?: boolean): Maybe; };