diff --git a/doc/_stdlib_gen/stdlib-content.jsonnet b/doc/_stdlib_gen/stdlib-content.jsonnet index 52ac42f1..63fb7341 100644 --- a/doc/_stdlib_gen/stdlib-content.jsonnet +++ b/doc/_stdlib_gen/stdlib-content.jsonnet @@ -89,6 +89,28 @@ local exampleDocMultiline(mid, ex) = The argument a may have any type. |||, }, + { + name: 'isNull', + params: ['x'], + availableSince: 'upcoming', + description: ||| + Returns true if the given value is null, false otherwise. + |||, + examples: [ + { + input: 'std.isNull(null)', + output: true, + }, + { + input: 'std.isNull(42)', + output: false, + }, + { + input: 'std.isNull("string")', + output: false, + }, + ], + }, ], }, { diff --git a/stdlib/std.jsonnet b/stdlib/std.jsonnet index ec7ab8f4..f627a958 100644 --- a/stdlib/std.jsonnet +++ b/stdlib/std.jsonnet @@ -33,6 +33,7 @@ limitations under the License. isObject(v):: std.type(v) == 'object', isArray(v):: std.type(v) == 'array', isFunction(v):: std.type(v) == 'function', + isNull(v):: v == null, toString(a):: if std.type(a) == 'string' then a else '' + a, diff --git a/test_suite/stdlib.jsonnet b/test_suite/stdlib.jsonnet index 9d11766a..6d3a40dc 100644 --- a/test_suite/stdlib.jsonnet +++ b/test_suite/stdlib.jsonnet @@ -121,6 +121,8 @@ std.assertEqual(std.isNumber(0), true) && std.assertEqual(std.isObject({}), true) && std.assertEqual(std.isArray([]), true) && std.assertEqual(std.isFunction(function() 0), true) && +std.assertEqual(std.isNull(null), true) && +std.assertEqual(std.isNull('foo'), false) && std.assertEqual(std.isString(null), false) && std.assertEqual(std.isBoolean(null), false) &&