@@ -33,7 +33,9 @@ String Functions
33
33
- abbrevboth: Abbreviate from both sides, yielding "...lo wo..."
34
34
- trunc: Truncate a string (no suffix). `trunc 5 "Hello World"` yields "hello".
35
35
- trim: strings.TrimSpace
36
- - trimall: strings.Trim, but with the argument order reversed `trimall "$" "$5.00"` or `"$5.00 | trimall "$"`
36
+ - trimAll: strings.Trim, but with the argument order reversed `trimAll "$" "$5.00"` or `"$5.00 | trimAll "$"`
37
+ - trimSuffix: strings.TrimSuffix, but with the argument order reversed: `trimSuffix "-" "ends-with-"`
38
+ - trimPrefix: strings.TrimPrefix, but with the argument order reversed `trimPrefix "$" "$5"`
37
39
- upper: strings.ToUpper
38
40
- lower: strings.ToLower
39
41
- nospace: Remove all space characters from a string. `nospace "h e l l o"` becomes "hello"
@@ -49,6 +51,8 @@ String Functions
49
51
- wrap: Force a line wrap at the given width. `wrap 80 "imagine a longer string"`
50
52
- wrapWith: Wrap a line at the given length, but using 'sep' instead of a newline. `wrapWith 50, "<br>", $html`
51
53
- contains: strings.Contains, but with the arguments switched: `contains substr str`. (This simplifies common pipelines)
54
+ - hasPrefix: strings.hasPrefix, but with the arguments switched
55
+ - hasSuffix: strings.hasSuffix, but with the arguments switched
52
56
- quote: Wrap string(s) in double quotation marks.
53
57
- squote: Wrap string(s) in double quotation marks.
54
58
- cat: Concatenate strings, separating them by spaces. `cat $a $b $c`.
@@ -266,8 +270,12 @@ var genericMap = map[string]interface{}{
266
270
"substr" : substring ,
267
271
// Switch order so that "foo" | repeat 5
268
272
"repeat" : func (count int , str string ) string { return strings .Repeat (str , count ) },
273
+ // Deprecated: Use trimAll.
274
+ "trimall" : func (a , b string ) string { return strings .Trim (b , a ) },
269
275
// Switch order so that "$foo" | trimall "$"
270
- "trimall" : func (a , b string ) string { return strings .Trim (b , a ) },
276
+ "trimAll" : func (a , b string ) string { return strings .Trim (b , a ) },
277
+ "trimSuffix" : func (a , b string ) string { return strings .TrimSuffix (b , a ) },
278
+ "trimPrefix" : func (a , b string ) string { return strings .TrimPrefix (b , a ) },
271
279
"nospace" : util .DeleteWhiteSpace ,
272
280
"initials" : initials ,
273
281
"randAlphaNum" : randAlphaNumeric ,
@@ -278,13 +286,15 @@ var genericMap = map[string]interface{}{
278
286
"wrap" : func (l int , s string ) string { return util .Wrap (s , l ) },
279
287
"wrapWith" : func (l int , sep , str string ) string { return util .WrapCustom (str , l , sep , true ) },
280
288
// Switch order so that "foobar" | contains "foo"
281
- "contains" : func (substr string , str string ) bool { return strings .Contains (str , substr ) },
282
- "quote" : quote ,
283
- "squote" : squote ,
284
- "cat" : cat ,
285
- "indent" : indent ,
286
- "replace" : replace ,
287
- "plural" : plural ,
289
+ "contains" : func (substr string , str string ) bool { return strings .Contains (str , substr ) },
290
+ "hasPrefix" : func (substr string , str string ) bool { return strings .HasPrefix (str , substr ) },
291
+ "hasSuffix" : func (substr string , str string ) bool { return strings .HasSuffix (str , substr ) },
292
+ "quote" : quote ,
293
+ "squote" : squote ,
294
+ "cat" : cat ,
295
+ "indent" : indent ,
296
+ "replace" : replace ,
297
+ "plural" : plural ,
288
298
289
299
// Wrap Atoi to stop errors.
290
300
"atoi" : func (a string ) int { i , _ := strconv .Atoi (a ); return i },
0 commit comments