magus v0.3.0 is out. See what's new
¶ View markdown source · ✎ Suggest an edit
2 min read

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 in camelCase: 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..."
auto-generatedstringsmodulestdlibmagusfile
Last updated (e0463131)
Earlier changes on this page (1)

Full history ↗ · Blame source ↗

Glossary

Magusfile

The magusfile.buzz that declares a project's targets (as export funs) and binds its spells. See targets.

Module

A magus stdlib namespace a magusfile imports for host capabilities: filesystem, exec, vcs, and more. See the module reference.

Buzz

The language magusfiles are written in (the .buzz engine). See engines.

Conventions

This page uses none of the site's convention markers. The full set is on the conventions page.