Skip to content

string

Contains utility functions for string operations.

InterfaceDescription
EnsureEndsWithParamsParameters for ensureEndsWith.
EnsureStartsWithParamsParameters for ensureStartsWith.
HasSingleOccurrenceParamsParameters for hasSingleOccurrence.
IndentParamsParameters for indent.
InsertAtParamsParameters for insertAt.
ReplaceAllAsyncParamsParameters for replaceAllAsync.
ReplaceAllParamsParameters for replaceAll.
ReplaceArgsCommon arguments for the replaceAll/replaceAllAsync functions.
TrimEndParamsParameters for trimEnd.
TrimStartParamsParameters for trimStart.
UnindentParamsParameters for unindent.
FunctionDescription
ensureEndsWithEnsures that a string ends with the specified suffix, adding it if necessary.
ensureLfEndingsEnsures that a string has LF line endings. It replaces CRLF line endings with LF.
ensureStartsWithEnsures that a string starts with the specified prefix, adding it if necessary.
escapeEscapes special characters in a string.
getLfNormalizedOffsetToOriginalOffsetMapperReturns a function that maps LF-normalized offsets to original offsets.
hasSingleOccurrenceChecks if a string has a single occurrence of a search value.
indentIndents a string by adding a prefix to each line.
insertAtInserts a substring at a specified position in a string.
makeValidVariableNameConverts a string into a valid JavaScript variable name by replacing invalid characters with underscores.
normalizeStringNormalizes a string by converting it to the NFC form and replacing non-breaking spaces with regular spaces.
replaceReplaces occurrences of strings in a given string based on a replacements map.
replaceAllReplaces all occurrences of a search string or pattern with the results of an replacer function.
replaceAllAsyncAsynchronously replaces all occurrences of a search string or pattern with the results of an asynchronous replacer function.
trimEndTrims the specified suffix from the end of a string.
trimStartTrims the specified prefix from the start of a string.
unescapeUnescapes a string by replacing escape sequences with their corresponding characters.
unindentUnindents a string by removing a prefix from each line.
TypeDescription
AsyncReplacerA synchronous/asynchronous function that generates replacement strings, or a string to replace with.
ReplacerA synchronous function that generates replacement strings, or a string to replace with.
VariableDescription
EMPTYAn empty string constant. A shared sentinel for the $\{EMPTY\} prefix that silences the obsidianmd/ui/sentence-case ESLint false positive on legitimate lower-case UI text (e.g. cursor colliding with the Cursor brand). setName(${EMPTY}…at cursor…) renders byte-identical '' at runtime while the \{...\} placeholder makes the rule skip the string. Consumers import this instead of redefining a per-file const EMPTY = ''.