Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions string.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/string_test.jsonnet
Original file line number Diff line number Diff line change
@@ -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',
)
)