strings
Case conversion and word helpers (camel/snake/kebab/Pascal, capitalize, words, ellipsis).
Naming convention: import the module under its bare name (
import "strings"), reach members with a backslash, and call methods incamelCase:strings\someMethod.
Methods
camelCase
Convert s to camelCase.
Signature: strings\camelCase(s) → string · source
| Parameter | Type | Optional | Description |
|---|---|---|---|
s |
string |
Returns: string
Example:
import "std";
import "strings";
std\print(strings\camelCase("hello world"));
// -> "helloWorld"
snakeCase
Convert s to snake_case.
Signature: strings\snakeCase(s) → string · source
| Parameter | Type | Optional | Description |
|---|---|---|---|
s |
string |
Returns: string
Example:
import "std";
import "strings";
std\print(strings\snakeCase("HelloWorld"));
// -> "hello_world"
kebabCase
Convert s to kebab-case.
Signature: strings\kebabCase(s) → string · source
| Parameter | Type | Optional | Description |
|---|---|---|---|
s |
string |
Returns: string
Example:
import "std";
import "strings";
std\print(strings\kebabCase("MyComponentName"));
// -> "my-component-name"
pascalCase
Convert s to PascalCase.
Signature: strings\pascalCase(s) → string · source
| Parameter | Type | Optional | Description |
|---|---|---|---|
s |
string |
Returns: string
Example:
import "std";
import "strings";
std\print(strings\pascalCase("user_profile"));
// -> "UserProfile"
capitalize
Uppercase the first rune of s and lowercase the rest.
Signature: strings\capitalize(s) → string · source
| Parameter | Type | Optional | Description |
|---|---|---|---|
s |
string |
Returns: string
Example:
import "std";
import "strings";
std\print(strings\capitalize("hELLO"));
// -> "Hello"
words
Split s into its constituent words (splitting on case changes, digits, and separators).
Signature: strings\words(s) → []string · source
| Parameter | Type | Optional | Description |
|---|---|---|---|
s |
string |
Returns: []string
Example:
import "std";
import "strings";
final parts = strings\words("parseHTTPResponse2");
foreach (w in parts) { std\print(w); }
// -> parse
// -> HTTP
// -> Response
// -> 2
ellipsis
Trim s to at most length runes, appending "..." when truncated.
Signature: strings\ellipsis(s, length) → string · source
| Parameter | Type | Optional | Description |
|---|---|---|---|
s |
string |
||
length |
int |
Returns: string
Example:
import "std";
import "strings";
std\print(strings\ellipsis("the quick brown fox", 12));
// -> "the quick..."