diff --git a/doc/_stdlib_gen/stdlib-content.jsonnet b/doc/_stdlib_gen/stdlib-content.jsonnet
index 40de10df5..f2eb52da1 100644
--- a/doc/_stdlib_gen/stdlib-content.jsonnet
+++ b/doc/_stdlib_gen/stdlib-content.jsonnet
@@ -70,83 +70,6 @@ local html = import 'html.libsonnet';
null
, true
or false
.
|||,
},
- {
- name: 'get',
- params: ['o', 'f', 'default=null', 'inc_hidden=true'],
- availableSince: '0.18.0',
- description: |||
- Returns the object's field if it exists or default value otherwise.
- inc_hidden
controls whether to include hidden fields.
- |||,
- },
- {
- name: 'objectHas',
- params: ['o', 'f'],
- availableSince: '0.10.0',
- description: |||
- Returns true
if the given object has the field (given as a string), otherwise
- false
. Raises an error if the arguments are not object and string
- respectively. Returns false if the field is hidden.
- |||,
- },
- {
- name: 'objectFields',
- params: ['o'],
- availableSince: '0.10.0',
- description: |||
- Returns an array of strings, each element being a field from the given object. Does not include
- hidden fields.
- |||,
- },
- {
- name: 'objectValues',
- params: ['o'],
- availableSince: '0.17.0',
- description: |||
- Returns an array of the values in the given object. Does not include hidden fields.
- |||,
- },
- {
- name: 'objectKeysValues',
- params: ['o'],
- availableSince: '0.20.0',
- description: |||
- Returns an array of objects from the given object, each object having two fields:
- key
(string) and value
(object). Does not include hidden fields.
- |||,
- },
- {
- name: 'objectHasAll',
- params: ['o', 'f'],
- availableSince: '0.10.0',
- description: |||
- As std.objectHas
but also includes hidden fields.
- |||,
- },
- {
- name: 'objectFieldsAll',
- params: ['o'],
- availableSince: '0.10.0',
- description: |||
- As std.objectFields
but also includes hidden fields.
- |||,
- },
- {
- name: 'objectValuesAll',
- params: ['o'],
- availableSince: '0.17.0',
- description: |||
- As std.objectValues
but also includes hidden fields.
- |||,
- },
- {
- name: 'objectKeysValuesAll',
- params: ['o'],
- availableSince: '0.20.0',
- description: |||
- As std.objectKeysValues
but also includes hidden fields.
- |||,
- },
{
name: 'prune',
params: ['a'],
@@ -157,16 +80,6 @@ local html = import 'html.libsonnet';
The argument a
may have any type.
|||,
},
- {
- name: 'mapWithKey',
- params: ['func', 'obj'],
- availableSince: '0.10.0',
- description: |||
- Apply the given function to all fields of the given object, also passing
- the field name. The function func
is expected to take the
- field name as the first parameter and the field value as the second.
- |||,
- },
],
},
{
@@ -1515,6 +1428,107 @@ local html = import 'html.libsonnet';
},
],
},
+ {
+ name: 'Objects',
+ id: 'objects',
+ fields: [
+ {
+ name: 'get',
+ params: ['o', 'f', 'default=null', 'inc_hidden=true'],
+ availableSince: '0.18.0',
+ description: |||
+ Returns the object's field if it exists or default value otherwise.
+ inc_hidden
controls whether to include hidden fields.
+ |||,
+ },
+ {
+ name: 'objectHas',
+ params: ['o', 'f'],
+ availableSince: '0.10.0',
+ description: |||
+ Returns true
if the given object has the field (given as a string), otherwise
+ false
. Raises an error if the arguments are not object and string
+ respectively. Returns false if the field is hidden.
+ |||,
+ },
+ {
+ name: 'objectFields',
+ params: ['o'],
+ availableSince: '0.10.0',
+ description: |||
+ Returns an array of strings, each element being a field from the given object. Does not include
+ hidden fields.
+ |||,
+ },
+ {
+ name: 'objectValues',
+ params: ['o'],
+ availableSince: '0.17.0',
+ description: |||
+ Returns an array of the values in the given object. Does not include hidden fields.
+ |||,
+ },
+ {
+ name: 'objectKeysValues',
+ params: ['o'],
+ availableSince: '0.20.0',
+ description: |||
+ Returns an array of objects from the given object, each object having two fields:
+ key
(string) and value
(object). Does not include hidden fields.
+ |||,
+ },
+ {
+ name: 'objectHasAll',
+ params: ['o', 'f'],
+ availableSince: '0.10.0',
+ description: |||
+ As std.objectHas
but also includes hidden fields.
+ |||,
+ },
+ {
+ name: 'objectFieldsAll',
+ params: ['o'],
+ availableSince: '0.10.0',
+ description: |||
+ As std.objectFields
but also includes hidden fields.
+ |||,
+ },
+ {
+ name: 'objectValuesAll',
+ params: ['o'],
+ availableSince: '0.17.0',
+ description: |||
+ As std.objectValues
but also includes hidden fields.
+ |||,
+ },
+ {
+ name: 'objectKeysValuesAll',
+ params: ['o'],
+ availableSince: '0.20.0',
+ description: |||
+ As std.objectKeysValues
but also includes hidden fields.
+ |||,
+ },
+ {
+ name: 'objectRemoveKey',
+ params: ['obj', 'key'],
+ availableSince: 'upcoming',
+ description: |||
+ Returns a new object after removing the given key from object.
+ |||,
+ },
+ {
+ name: 'mapWithKey',
+ params: ['func', 'obj'],
+ availableSince: '0.10.0',
+ description: |||
+ Apply the given function to all fields of the given object, also passing
+ the field name. The function func
is expected to take the
+ field name as the first parameter and the field value as the second.
+ |||,
+ },
+ ],
+ },
{
name: 'Encoding',
id: 'encoding',
diff --git a/stdlib/std.jsonnet b/stdlib/std.jsonnet
index 160dd7eb3..9b0865cde 100644
--- a/stdlib/std.jsonnet
+++ b/stdlib/std.jsonnet
@@ -1724,4 +1724,10 @@ limitations under the License.
isEmpty(str):: std.length(str) == 0,
contains(arr, elem):: std.any([e == elem for e in arr]),
+
+ objectRemoveKey(obj, key):: {
+ [k]: obj[k],
+ for k in std.objectFields(obj)
+ if k != key
+ },
}
diff --git a/test_suite/stdlib.jsonnet b/test_suite/stdlib.jsonnet
index 186399245..9dd8f48e4 100644
--- a/test_suite/stdlib.jsonnet
+++ b/test_suite/stdlib.jsonnet
@@ -1559,7 +1559,9 @@ std.assertEqual(std.round(1.5), 2) &&
std.assertEqual(std.isEmpty(''), true) &&
std.assertEqual(std.isEmpty('non-empty string'), false) &&
-std.contains(std.contains([1, 2, 3], 2), true) &&
-std.contains(std.contains([1, 2, 3], "foo"), false) &&
+std.assertEqual(std.contains([1, 2, 3], 2), true) &&
+std.assertEqual(std.contains([1, 2, 3], "foo"), false) &&
+
+std.assertEqual(std.objectRemoveKey({ foo: 1, bar: 2, baz: 3 }, 'foo'), { bar: 2, baz: 3 }) &&
true