Skip to content

Commit 40713b7

Browse files
authored
Add std.isEmpty for string (#1059)
* Add std.isEmpty for string * added doc for `availableSince: 'upcoming'`
1 parent f071376 commit 40713b7

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/_stdlib_gen/stdlib-content.jsonnet

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,14 @@ local html = import 'html.libsonnet';
425425
},
426426
],
427427
},
428+
{
429+
name: 'isEmpty',
430+
params: ['str'],
431+
availableSince: 'upcoming',
432+
description: |||
433+
Returns true if the the given string is of zero length.
434+
|||,
435+
},
428436
{
429437
name: 'asciiUpper',
430438
params: ['str'],

stdlib/std.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,4 +1692,6 @@ limitations under the License.
16921692
xor(x, y):: x!=y,
16931693

16941694
xnor(x, y):: x==y,
1695+
1696+
isEmpty(str):: std.length(str) == 0,
16951697
}

test_suite/stdlib.jsonnet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,4 +1550,7 @@ std.assertEqual(std.xor(true, true), false) &&
15501550
std.assertEqual(std.xnor(true, false), false) &&
15511551
std.assertEqual(std.xnor(true, true), true) &&
15521552

1553+
std.assertEqual(std.isEmpty(""), true) &&
1554+
std.assertEqual(std.isEmpty("non-empty string"), false) &&
1555+
15531556
true

0 commit comments

Comments
 (0)