Documentation
¶
Overview ¶
Package stringutil provides utility functions for working with strings.
Index ¶
- func NormalizePath(path string) string
- func NormalizeSafeOutputIdentifier(identifier string) string
- func NormalizeWhitespace(content string) string
- func NormalizeWorkflowName(name string) string
- func ParseVersionValue(version any) string
- func SanitizeErrorMessage(message string) string
- func SanitizeParameterName(name string) string
- func SanitizePythonVariableName(name string) string
- func SanitizeToolID(toolID string) string
- func Truncate(s string, maxLen int) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizePath ¶ added in v0.35.1
NormalizePath normalizes a file path by resolving . and .. components. It splits the path on "/" and processes each component: - Empty parts and "." are skipped - ".." moves up one directory (if possible) - Other parts are added to the result
This is useful for resolving relative paths in bundler operations and other file path manipulations where . and .. components need to be resolved.
Examples:
NormalizePath("a/b/../c") // returns "a/c"
NormalizePath("./a/./b") // returns "a/b"
NormalizePath("a/b/../../c") // returns "c"
NormalizePath("../a/b") // returns "a/b" (leading .. is ignored)
NormalizePath("a//b") // returns "a/b" (empty parts removed)
func NormalizeSafeOutputIdentifier ¶ added in v0.35.1
NormalizeSafeOutputIdentifier converts dashes to underscores for safe output identifiers. This standardizes identifier format from the user-facing dash-separated format to the internal underscore-separated format used in safe outputs configuration.
Both dash-separated and underscore-separated formats are valid inputs. This function simply standardizes to the internal representation.
This function performs normalization only - it assumes the input is already a valid identifier and does NOT perform character validation or sanitization.
Examples:
NormalizeSafeOutputIdentifier("create-issue") // returns "create_issue"
NormalizeSafeOutputIdentifier("create_issue") // returns "create_issue" (unchanged)
NormalizeSafeOutputIdentifier("add-comment") // returns "add_comment"
NormalizeSafeOutputIdentifier("update-pr") // returns "update_pr"
func NormalizeWhitespace ¶
NormalizeWhitespace normalizes trailing whitespace and newlines to reduce spurious conflicts. It trims trailing whitespace from each line and ensures exactly one trailing newline.
func NormalizeWorkflowName ¶ added in v0.35.1
NormalizeWorkflowName removes .md and .lock.yml extensions from workflow names. This is used to standardize workflow identifiers regardless of the file format.
The function checks for extensions in order of specificity: 1. Removes .lock.yml extension (the compiled workflow format) 2. Removes .md extension (the markdown source format) 3. Returns the name unchanged if no recognized extension is found
This function performs normalization only - it assumes the input is already a valid identifier and does NOT perform character validation or sanitization.
Examples:
NormalizeWorkflowName("weekly-research") // returns "weekly-research"
NormalizeWorkflowName("weekly-research.md") // returns "weekly-research"
NormalizeWorkflowName("weekly-research.lock.yml") // returns "weekly-research"
NormalizeWorkflowName("my.workflow.md") // returns "my.workflow"
func ParseVersionValue ¶
ParseVersionValue converts version values of various types to strings. Supports string, int, int64, uint64, and float64 types. Returns empty string for unsupported types.
func SanitizeErrorMessage ¶
SanitizeErrorMessage removes potential secret key names from error messages to prevent information disclosure via logs. This prevents exposing details about an organization's security infrastructure by redacting secret key names that might appear in error messages.
func SanitizeParameterName ¶ added in v0.35.1
SanitizeParameterName converts a parameter name to a safe JavaScript identifier by replacing non-alphanumeric characters with underscores.
This function ensures that parameter names from workflows can be used safely in JavaScript code by: 1. Replacing any non-alphanumeric characters (except $ and _) with underscores 2. Prepending an underscore if the name starts with a number
Valid characters: a-z, A-Z, 0-9 (not at start), _, $
Examples:
SanitizeParameterName("my-param") // returns "my_param"
SanitizeParameterName("my.param") // returns "my_param"
SanitizeParameterName("123param") // returns "_123param"
SanitizeParameterName("valid_name") // returns "valid_name"
SanitizeParameterName("$special") // returns "$special"
func SanitizePythonVariableName ¶ added in v0.35.1
SanitizePythonVariableName converts a parameter name to a valid Python identifier by replacing non-alphanumeric characters with underscores.
This function ensures that parameter names from workflows can be used safely in Python code by: 1. Replacing any non-alphanumeric characters (except _) with underscores 2. Prepending an underscore if the name starts with a number
Valid characters: a-z, A-Z, 0-9 (not at start), _ Note: Python does not allow $ in identifiers (unlike JavaScript)
Examples:
SanitizePythonVariableName("my-param") // returns "my_param"
SanitizePythonVariableName("my.param") // returns "my_param"
SanitizePythonVariableName("123param") // returns "_123param"
SanitizePythonVariableName("valid_name") // returns "valid_name"
func SanitizeToolID ¶ added in v0.35.1
SanitizeToolID removes common MCP prefixes and suffixes from tool IDs. This cleans up tool identifiers by removing redundant MCP-related naming patterns.
The function: 1. Removes "mcp-" prefix 2. Removes "-mcp" suffix 3. Returns the original ID if the result would be empty
Examples:
SanitizeToolID("notion-mcp") // returns "notion"
SanitizeToolID("mcp-notion") // returns "notion"
SanitizeToolID("some-mcp-server") // returns "some-server"
SanitizeToolID("github") // returns "github" (unchanged)
SanitizeToolID("mcp") // returns "mcp" (prevents empty result)
func Truncate ¶
Truncate truncates a string to a maximum length, adding "..." if truncated. If maxLen is 3 or less, the string is truncated without "...".
This is a general-purpose utility for truncating any string to a configurable length. For domain-specific workflow command identifiers with newline handling, see workflow.ShortenCommand instead.
Types ¶
This section is empty.