aboutsummaryrefslogtreecommitdiff
path: root/docs/text.md
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-06 00:03:28 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-06 00:03:28 -0400
commit44892df4c5686b292a058ca19eaba1e852fe42f3 (patch)
treeb01b46ef7e9496e1971616e3b55e124dfd217cbb /docs/text.md
parent1000423d2b351f1f5edbb3c9a08898883ba47f3e (diff)
Add Text.trim()
Diffstat (limited to 'docs/text.md')
-rw-r--r--docs/text.md36
1 files changed, 36 insertions, 0 deletions
diff --git a/docs/text.md b/docs/text.md
index 1d26040b..02c30912 100644
--- a/docs/text.md
+++ b/docs/text.md
@@ -279,6 +279,7 @@ Text.map(pattern:Pattern, fn:func(t:Text)->Text)->Text
Text.replace(pattern:Pattern, replacement:Text, placeholder:Pattern=$//)->[Text]
Text.replace_all(replacements:{Pattern:Text}, placeholder:Pattern=$//)->[Text]
Text.split(pattern:Pattern)->[Text]
+Text.trim(pattern=$/{whitespace}/, trim_left=yes, trim_right=yes)->[Text]
```
See [Text Functions](#Text-Functions) for the full API documentation.
@@ -1098,6 +1099,41 @@ The text in title case.
---
+## `trim`
+
+**Description:**
+Trims the matching pattern from the left and/or right side of the text
+See [Patterns](#patterns) for more information about patterns.
+
+**Usage:**
+```tomo
+trim(text: Text, pattern: Pattern = $/{whitespace/, trim_left: Bool = yes, trim_right: Bool = yes) -> Text
+```
+
+**Parameters:**
+
+- `text`: The text to be trimmed.
+- `pattern`: The pattern that will be trimmed away.
+- `trim_left`: Whether or not to trim from the front of the text.
+- `trim_right`: Whether or not to trim from the back of the text.
+
+**Returns:**
+The text without the trim pattern at either end.
+
+**Example:**
+```tomo
+>> " x y z $(\n)":trim()
+= "x y z"
+
+>> "abc123def":trim($/{!digit}/)
+= "123"
+
+>> " xyz ":trim(trim_right=no)
+= "xyz "
+```
+
+---
+
## `upper`
**Description:**