Case convert
str_snake_case¶
Convert a string to snake_case. Handles space-separated words, hyphen-separated words, and camelCase input.
Example¶
str_snake_case "Hello World" # => hello_world
str_snake_case "fooBar" # => foo_bar
str_snake_case "kebab-case" # => kebab_case
Arguments¶
- ... (string): The string to convert
Exit codes¶
- 0: Always
Output on stdout¶
- snake_case string
str_camel_case¶
Convert a string to camelCase. Handles space-separated, underscore-separated, and hyphen-separated words. Input that is already camelCase will be normalised to all-lowercase then re-cased. Requires bash 4+.
Example¶
str_camel_case "hello world" # => helloWorld
str_camel_case "foo_bar_baz" # => fooBarBaz
str_camel_case "kebab-case" # => kebabCase
Arguments¶
- ... (string): The string to convert
Exit codes¶
- 0: Always
Output on stdout¶
- camelCase string
str_kebab_case¶
Convert a string to kebab-case. Handles space-separated words, underscore-separated words, and camelCase input.
Example¶
str_kebab_case "Hello World" # => hello-world
str_kebab_case "fooBar" # => foo-bar
str_kebab_case "snake_case" # => snake-case
Arguments¶
- ... (string): The string to convert
Exit codes¶
- 0: Always
Output on stdout¶
- kebab-case string
str_slug¶
Convert a string to a URL-safe slug: lowercase alphanumeric characters only, with runs of non-alphanumeric characters replaced by a single hyphen.
Example¶
str_slug "Hello, World!" # => hello-world
str_slug "My Blog Post Title" # => my-blog-post-title
str_slug " extra spaces " # => extra-spaces
Arguments¶
- ... (string): The string to convert
Exit codes¶
- 0: Always
Output on stdout¶
- URL slug string
str_ucfirst¶
Uppercase the first character of a string. Requires bash 4+.
Example¶
str_ucfirst "hello world" # => Hello world
Arguments¶
- ... (string): The string to convert
Exit codes¶
- 0: Always
Output on stdout¶
- String with first character uppercased
str_lcfirst¶
Lowercase the first character of a string. Requires bash 4+.
Example¶
str_lcfirst "Hello World" # => hello World
Arguments¶
- ... (string): The string to convert
Exit codes¶
- 0: Always
Output on stdout¶
- String with first character lowercased
str_ucwords¶
Uppercase the first character of each word. Requires bash 4+.
Example¶
str_ucwords "hello world" # => Hello World
Arguments¶
- ... (string): The string to convert
Exit codes¶
- 0: Always
Output on stdout¶
- String with first character of each word uppercased
str_title_case¶
Convert a lower_snake_case string to Title Case. Splits on underscores and capitalises each word. Requires bash 4+ for the ${^} case modifier.
Example¶
str_title_case "slice_drive_size" # => "Slice Drive Size"
str_title_case "foo_bar" # => "Foo Bar"
Arguments¶
- $1 (string): Input string in snake_case or similar
Exit codes¶
- 0: Always
Output on stdout¶
- Title-cased string