diff --git a/string.libsonnet b/string.libsonnet index 6655981..4245c6e 100644 --- a/string.libsonnet +++ b/string.libsonnet @@ -12,6 +12,15 @@ local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet'; // character and thereby will unlikely be in a valid key by accident. Only when we include it. local BelRune = std.char(7), + '#capitalize':: d.fn( + ||| + `capitalize` will uppercase the first letter of string. + |||, + [d.arg('str', d.T.string)] + ), + capitalize(str): if std.length(str) > 0 then + std.asciiUpper(str[0]) + std.substr(str, 1, std.length(str) - 1) else '', + '#splitEscape':: d.fn( ||| `split` works the same as `std.split` but with support for escaping the dividing diff --git a/test/string_test.jsonnet b/test/string_test.jsonnet new file mode 100644 index 0000000..43a9435 --- /dev/null +++ b/test/string_test.jsonnet @@ -0,0 +1,19 @@ +local xtd = import '../main.libsonnet'; +local test = import 'github.com/jsonnet-libs/testonnet/main.libsonnet'; + +test.new(std.thisFile) ++ test.case.new( + name='empty', + test=test.expect.eq( + actual=xtd.string.capitalize(''), + expected='', + ) +) + ++ test.case.new( + name='abc', + test=test.expect.eq( + actual=xtd.string.capitalize('abc'), + expected='Abc', + ) +)