stream-chat
Version:
JS SDK for the Stream Chat API
74 lines (70 loc) • 2.27 kB
TypeScript
import type { TextSelection } from './types';
/**
* For commands, we want to match all patterns except:
* 1. Text not starting with trigger
* 2. Trigger in middle of text
*/
export declare const getTriggerCharWithToken: ({ trigger, text, isCommand, acceptTrailingSpaces, }: {
trigger: string;
text: string;
isCommand?: boolean;
acceptTrailingSpaces?: boolean;
}) => string | null;
export declare const getCompleteCommandInString: (text: string) => string | null;
export declare const insertItemWithTrigger: ({ insertText, selection, text, trigger, }: {
insertText: string;
selection: TextSelection;
text: string;
trigger: string;
}) => {
text: string;
selection: {
start: number;
end: number;
};
};
export declare const replaceWordWithEntity: ({ caretPosition, getEntityString, text, }: {
caretPosition: number;
getEntityString: (word: string) => Promise<string | null> | string | null;
text: string;
}) => Promise<string>;
/**
* Escapes a string for use in a regular expression
* @param text - The string to escape
* @returns The escaped string
* What does this regex do?
The regex escapes special regex characters by adding a backslash before them. Here's what it matches:
- dash
[ ] square brackets
{ } curly braces
( ) parentheses
* asterisk
+ plus
? question mark
. period
, comma
/ forward slash
\ backslash
^ caret
$ dollar sign
| pipe
# hash
The \\$& replacement adds a backslash before any matched character.
This is needed when you want to use these characters literally
in a regex pattern instead of their special regex meanings.
For example:
escapeRegExp("hello.world") // Returns: "hello\.world"
escapeRegExp("[test]") // Returns: "\[test\]"
This is commonly used when building dynamic regex patterns from user input to prevent special characters from being interpreted as regex syntax.
*/
export declare function escapeRegExp(text: string): string;
export type TokenizationPayload = {
tokenizedDisplayName: {
token: string;
parts: string[];
};
};
export declare const getTokenizedSuggestionDisplayName: ({ displayName, searchToken, }: {
displayName: string;
searchToken: string;
}) => TokenizationPayload;