Module: string
Table of contents
Functions
Functions
cleanPath
▸ cleanPath(pathname
): string
Cleans a given pathname by removing any directory traversal characters.
Parameters
Name | Type | Description |
---|---|---|
pathname | string | The path to be cleaned. |
Returns
string
The cleaned path.
Defined in
src/shared/string.ts:115 (opens in a new tab)
extractH1Headings
▸ extractH1Headings(markdownText
): string
[]
Extracts H1 headings from a Markdown string.
This function uses a regular expression to find lines in the Markdown text that start with '# ' (indicating an H1 heading in Markdown syntax) and returns an array of the headings found, excluding the '# ' prefix.
Parameters
Name | Type | Description |
---|---|---|
markdownText | string | The Markdown text to search for H1 headings. |
Returns
string
[]
An array of strings, each representing an H1 heading found in the input text.
Defined in
src/shared/string.ts:11 (opens in a new tab)
getActionArguments
▸ getActionArguments(action
): Object
Parses a given action string into its constituent components: command, captainId, value, and options.
The action string is structured to command actions within the application, following the format:
- "command:captainId" for actions without additional data.
- "command:captainId:value" for actions with data but without options.
- "command:captainId:value|options" for actions with both data and options.
Here, "captainId" refers to the data-captainid
attribute of an HTML element, identifying the target for the command.
Parameters
Name | Type | Description |
---|---|---|
action | string | The action string to be parsed, incorporating the command, target element's captainId, optional value, and optional options. |
Returns
Object
An object containing the parsed parts of the action.
command
: The action to perform (e.g., focus, click, type).captainId
: Identifier for the target element (matchesdata-captainid
attribute).value
: Optional data relevant to the command (e.g., text to type).options
: Additional parameters or instructions (e.g., "submit" to indicate form submission after typing).
Name | Type |
---|---|
captainId | string |
command | string |
options | undefined | string |
value | undefined | string |
Example
// Example 1: Focus on an element with specific captainId
getActionArguments("focus:color-mode-settings");
// Returns: { command: "focus", captainId: "color-mode-settings", value: undefined, options: undefined }
Example
// Example 2: Click an element with specific captainId
getActionArguments("click:language-settings");
// Returns: { command: "click", captainId: "language-settings", value: undefined, options: undefined }
Example
// Example 3: Type into a form and submit
getActionArguments("type:feedback-form:this app is amazing|submit");
// Returns: { command: "type", captainId: "feedback-form", value: "this app is amazing", options: "submit" }
Defined in
src/shared/string.ts:59 (opens in a new tab)
getFileType
▸ getFileType(filePath
): "image"
| "other"
| "markdown"
| "audio"
Determines the file type based on its extension.
This function examines the extension of the provided file path and categorizes it into one of the predetermined types: 'image', 'markdown', 'audio', or 'other'.
Parameters
Name | Type | Description |
---|---|---|
filePath | string | The complete path of the file including its name and extension. |
Returns
"image"
| "other"
| "markdown"
| "audio"
The category of the file based on its extension. Possible return values are 'image', 'markdown', 'audio', or 'other'.