diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2019-02-16 00:36:18 -0500 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2019-02-16 11:11:08 -0500 |
| commit | effecf8007507ee2e90e5462ff6ef7dbc8871d3f (patch) | |
| tree | 8f5a2ea446e1c3daaa05e4acbac62756786ba33a /docs | |
| parent | ffb7d693baa8f95df96484e9b1a9c6267be066cf (diff) | |
New functions strings.CamelCase and strings.SnakeCase
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/content/functions/strings.md | 108 |
1 files changed, 106 insertions, 2 deletions
diff --git a/docs/content/functions/strings.md b/docs/content/functions/strings.md index a13ad138..8f019dfa 100644 --- a/docs/content/functions/strings.md +++ b/docs/content/functions/strings.md @@ -160,11 +160,11 @@ Returns an alphanumerically-sorted copy of a given string list. ### Usage ```go -strings.Sort list +strings.Sort list ``` ```go -list | strings.Sort +list | strings.Sort ``` ### Arguments @@ -355,6 +355,8 @@ in | strings.Squote ```console $ gomplate -i '{{ "in" | squote }}' 'in' +``` +```console $ gomplate -i "{{ strings.Squote \"it's a banana\" }}" 'it''s a banana' ``` @@ -528,6 +530,108 @@ $ gomplate -i '{{ "hello, world" | strings.Trunc 5 }}' hello ``` +## `strings.CamelCase` + +Converts a sentence to CamelCase, i.e. `The quick brown fox` becomes `TheQuickBrownFox`. + +All non-alphanumeric characters are stripped, and the beginnings of words are upper-cased. If the input begins with a lower-case letter, the result will also begin with a lower-case letter. + +See [CamelCase on Wikipedia](https://en.wikipedia.org/wiki/Camel_case) for more details. + +### Usage +```go +strings.CamelCase in +``` + +```go +in | strings.CamelCase +``` + +### Arguments + +| name | description | +|------|-------------| +| `in` | _(required)_ The input | + +### Examples + +```console +$ gomplate -i '{{ "Hello, World!" | strings.CamelCase }}' +HelloWorld +``` +```console +$ gomplate -i '{{ "hello jello" | strings.CamelCase }}' +helloJello +``` + +## `strings.SnakeCase` + +Converts a sentence to snake_case, i.e. `The quick brown fox` becomes `The_quick_brown_fox`. + +All non-alphanumeric characters are stripped, and spaces are replaced with an underscore (`_`). If the input begins with a lower-case letter, the result will also begin with a lower-case letter. + +See [Snake Case on Wikipedia](https://en.wikipedia.org/wiki/Snake_case) for more details. + +### Usage +```go +strings.SnakeCase in +``` + +```go +in | strings.SnakeCase +``` + +### Arguments + +| name | description | +|------|-------------| +| `in` | _(required)_ The input | + +### Examples + +```console +$ gomplate -i '{{ "Hello, World!" | strings.SnakeCase }}' +Hello_world +``` +```console +$ gomplate -i '{{ "hello jello" | strings.SnakeCase }}' +hello_jello +``` + +## `strings.KebabCase` + +Converts a sentence to kebab-case, i.e. `The quick brown fox` becomes `The-quick-brown-fox`. + +All non-alphanumeric characters are stripped, and spaces are replaced with a hyphen (`-`). If the input begins with a lower-case letter, the result will also begin with a lower-case letter. + +See [Kebab Case on Wikipedia](https://en.wikipedia.org/wiki/Kebab_case) for more details. + +### Usage +```go +strings.KebabCase in +``` + +```go +in | strings.KebabCase +``` + +### Arguments + +| name | description | +|------|-------------| +| `in` | _(required)_ The input | + +### Examples + +```console +$ gomplate -i '{{ "Hello, World!" | strings.KebabCase }}' +Hello-world +``` +```console +$ gomplate -i '{{ "hello jello" | strings.KebabCase }}' +hello-jello +``` + ## `contains` **See [`strings.Contains](#strings-contains) for a pipeline-compatible version** |
