diff --git a/pkg/stdlib/stdlib-content.jsonnet b/pkg/stdlib/stdlib-content.jsonnet index 241f11a..c36e1c5 100644 --- a/pkg/stdlib/stdlib-content.jsonnet +++ b/pkg/stdlib/stdlib-content.jsonnet @@ -29,7 +29,7 @@ local html = import 'html.libsonnet'; name: 'extVar', params: ['x'], availableSince: '0.10.0', - description: 'If an external variable with the given name was defined, return its string value. Otherwise, raise an error.', + description: 'If an external variable with the given name was defined, return its value. Otherwise, raise an error.', }, ], }, @@ -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. - |||, - }, ], }, { @@ -197,12 +110,20 @@ local html = import 'html.libsonnet'; + + + +

The function std.mod(a, b) is what the % operator is desugared to. It performs modulo arithmetic if the left hand side is a number, or if the left hand side is a string, it does Python-style string formatting with std.format().

+

+ The functions std.isEven(x) and std.isOdd(x) use integral part of a + floating number to test for even or odd. +

|||, ], fields: [ @@ -455,7 +376,23 @@ local html = import 'html.libsonnet'; params: ['str'], availableSince: '0.20.0', description: ||| - Returns true if the the given string is of zero length. + Returns true if the given string is of zero length. + |||, + }, + { + name: 'trim', + params: ['str'], + availableSince: 'upcoming', + description: ||| + Returns a copy of string after eliminating leading and trailing whitespaces. + |||, + }, + { + name: 'equalsIgnoreCase', + params: ['str1', 'str2'], + availableSince: 'upcoming', + description: ||| + Returns true if the the given str1 is equal to str2 by doing case insensitive comparison, false otherwise. |||, }, { @@ -869,13 +806,49 @@ local html = import 'html.libsonnet'; }, ], }, + { + name: 'manifestJson', + params: ['value'], + availableSince: '0.10.0', + description: ||| + Convert the given object to a JSON form. Under the covers, + it calls std.manifestJsonEx with a 4-space indent: + |||, + examples: [ + { + input: ||| + std.manifestJson( + { + x: [1, 2, 3, true, false, null, + "string\nstring"], + y: { a: 1, b: 2, c: [1, 2] }, + }) + |||, + output: + std.manifestJson( + { + x: [ + 1, + 2, + 3, + true, + false, + null, + 'string\nstring', + ], + y: { a: 1, b: 2, c: [1, 2] }, + } + ), + }, + ], + }, { name: 'manifestJsonMinified', params: ['value'], availableSince: '0.18.0', description: ||| Convert the given object to a minified JSON form. Under the covers, - it calls std.manifestJsonEx:'): + it calls std.manifestJsonEx: |||, examples: [ { @@ -1303,6 +1276,10 @@ local html = import 'html.libsonnet'; input: 'std.slice("jsonnet", 0, 4, 1)', output: std.slice('jsonnet', 0, 4, 1), }, + { + input: 'std.slice("jsonnet", -3, null, null)', + output: std.slice('jsonnet', -3, null, null), + }, ], }, { @@ -1349,6 +1326,20 @@ local html = import 'html.libsonnet'; }, ], }, + { + name: 'flattenDeepArray', + params: ['value'], + availableSince: 'upcoming', + description: ||| + Concatenate an array containing values and arrays into a single flattened array. + |||, + examples: [ + { + input: 'std.flattenDeepArray([[1, 2], [], [3, [4]], [[5, 6, [null]], [7, 8]]])', + output: std.flattenDeepArray([[1, 2], [], [3, [4]], [[5, 6, [null]], [7, 8]]]), + }, + ], + }, { name: 'reverse', params: ['arrs'], @@ -1421,6 +1412,66 @@ local html = import 'html.libsonnet'; |||, ]), }, + { + name: 'minArray', + params: ['arr', 'keyF', 'onEmpty'], + availableSince: 'upcoming', + description: html.paragraphs([ + ||| + Return the min of all element in arr. + |||, + ]), + }, + { + name: 'maxArray', + params: ['arr', 'keyF', 'onEmpty'], + availableSince: 'upcoming', + description: html.paragraphs([ + ||| + Return the max of all element in arr. + |||, + ]), + }, + { + name: 'contains', + params: ['arr', 'elem'], + availableSince: 'upcoming', + description: html.paragraphs([ + ||| + Return true if given elem is present in arr, false otherwise. + |||, + ]), + }, + { + name: 'avg', + params: ['arr'], + availableSince: '0.20.0', + description: html.paragraphs([ + ||| + Return average of all element in arr. + |||, + ]), + }, + { + name: 'remove', + params: ['arr', 'elem'], + availableSince: 'upcoming', + description: html.paragraphs([ + ||| + Remove first occurrence of elem from arr. + |||, + ]), + }, + { + name: 'removeAt', + params: ['arr', 'idx'], + availableSince: 'upcoming', + description: html.paragraphs([ + ||| + Remove element at idx index from arr. + |||, + ]), + }, ], }, { @@ -1497,6 +1548,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', @@ -1544,6 +1696,58 @@ local html = import 'html.libsonnet'; Encodes the given value into an MD5 string. |||, }, + { + name: 'sha1', + params: ['s'], + availableSince: 'upcoming', + description: [ + html.p({}, ||| + Encodes the given value into an SHA1 string. + |||), + html.p({}, ||| + This function is only available in Go version of jsonnet. + |||), + ], + }, + { + name: 'sha256', + params: ['s'], + availableSince: 'upcoming', + description: [ + html.p({}, ||| + Encodes the given value into an SHA256 string. + |||), + html.p({}, ||| + This function is only available in Go version of jsonnet. + |||), + ], + }, + { + name: 'sha512', + params: ['s'], + availableSince: 'upcoming', + description: [ + html.p({}, ||| + Encodes the given value into an SHA512 string. + |||), + html.p({}, ||| + This function is only available in Go version of jsonnet. + |||), + ], + }, + { + name: 'sha3', + params: ['s'], + availableSince: 'upcoming', + description: [ + html.p({}, ||| + Encodes the given value into an SHA3 string. + |||), + html.p({}, ||| + This function is only available in Go version of jsonnet. + |||), + ], + }, ], }, { diff --git a/pkg/stdlib/stdlib_test.go b/pkg/stdlib/stdlib_test.go index 0e8b2e6..af00576 100644 --- a/pkg/stdlib/stdlib_test.go +++ b/pkg/stdlib/stdlib_test.go @@ -17,6 +17,15 @@ func TestFunctions(t *testing.T) { } contains(t, functions, minFunc) + // Check std.objectHas + objectHasFunc := Function{ + Name: "objectHas", + Params: []string{"o", "f"}, + MarkdownDescription: "Returns `true` if the given object has the field (given as a string), otherwise\n`false`. Raises an error if the arguments are not object and string\nrespectively. Returns false if the field is hidden.", + AvailableSince: "0.10.0", + } + contains(t, functions, objectHasFunc) + // Check std.ceil ceilFunc := Function{ Name: "ceil",