Skip to content
Merged
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
14 changes: 14 additions & 0 deletions doc/_stdlib_gen/stdlib-content.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ local html = import 'html.libsonnet';
hidden fields.
|||,
},
{
name: 'objectValues',
params: ['o'],
description: |||
Returns an array of the values in the given object. Does not include hidden fields.
|||,
},
{
name: 'objectHasAll',
params: ['o', 'f'],
Expand All @@ -94,6 +101,13 @@ local html = import 'html.libsonnet';
As <code>std.objectFields</code> but also includes hidden fields.
|||,
},
{
name: 'objectValuesAll',
params: ['o'],
description: |||
As <code>std.objectValues</code> but also includes hidden fields.
|||,
},
{
name: 'prune',
params: ['a'],
Expand Down
44 changes: 44 additions & 0 deletions doc/ref/stdlib.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ <h4 id="objectFields">
</div>
</div>

<div class="hgroup">
<div class="hgroup-inline">
<div class="panel">
<h4 id="objectValues">
std.objectValues(o)
</h4>
</div>
<div style="clear: both"></div>
</div>
</div>
<div class="hgroup">
<div class="hgroup-inline">
<div class="panel">
<p>
Returns an array of the values in the given object. Does not include hidden fields.
</p>

</div>
<div style="clear: both"></div>
</div>
</div>

<div class="hgroup">
<div class="hgroup-inline">
<div class="panel">
Expand Down Expand Up @@ -248,6 +270,28 @@ <h4 id="objectFieldsAll">
</div>
</div>

<div class="hgroup">
<div class="hgroup-inline">
<div class="panel">
<h4 id="objectValuesAll">
std.objectValuesAll(o)
</h4>
</div>
<div style="clear: both"></div>
</div>
</div>
<div class="hgroup">
<div class="hgroup-inline">
<div class="panel">
<p>
As <code>std.objectValues</code> but also includes hidden fields.
</p>

</div>
<div style="clear: both"></div>
</div>
</div>

<div class="hgroup">
<div class="hgroup-inline">
<div class="panel">
Expand Down
20 changes: 13 additions & 7 deletions stdlib/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ limitations under the License.
assert std.isString(str) : 'substr first parameter should be a string, got ' + std.type(str);
assert std.isNumber(from) : 'substr second parameter should be a string, got ' + std.type(from);
assert std.isNumber(len) : 'substr third parameter should be a string, got ' + std.type(len);
assert len >=0 : 'substr third parameter should be greater than zero, got ' + len;
assert len >= 0 : 'substr third parameter should be greater than zero, got ' + len;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are also all autoformatting but they look like good changes? I can rebase and just take the actual stuff I added if you want.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks like our own auto-formatting. Ideally that would be a separate commit, but that's not a big deal.

std.join('', std.makeArray(std.max(0, std.min(len, std.length(str) - from)), function(i) str[i + from])),

startsWith(a, b)::
Expand Down Expand Up @@ -112,13 +112,13 @@ limitations under the License.
split(str, c)::
assert std.isString(str) : 'std.split first parameter should be a string, got ' + std.type(str);
assert std.isString(c) : 'std.split second parameter should be a string, got ' + std.type(c);
assert std.length(c) == 1 : 'std.split second parameter should have length 1, got ' + std.length(c);
assert std.length(c) == 1 : 'std.split second parameter should have length 1, got ' + std.length(c);
std.splitLimit(str, c, -1),

splitLimit(str, c, maxsplits)::
assert std.isString(str) : 'std.splitLimit first parameter should be a string, got ' + std.type(str);
assert std.isString(c) : 'std.splitLimit second parameter should be a string, got ' + std.type(c);
assert std.length(c) == 1 : 'std.splitLimit second parameter should have length 1, got ' + std.length(c);
assert std.length(c) == 1 : 'std.splitLimit second parameter should have length 1, got ' + std.length(c);
assert std.isNumber(maxsplits) : 'std.splitLimit third parameter should be a number, got ' + std.type(maxsplits);
local aux(str, delim, i, arr, v) =
local c = str[i];
Expand Down Expand Up @@ -183,9 +183,9 @@ limitations under the License.

repeat(what, count)::
local joiner =
if std.isString(what) then ""
if std.isString(what) then ''
else if std.isArray(what) then []
else error "std.repeat first argument must be an array or a string";
else error 'std.repeat first argument must be an array or a string';
std.join(joiner, std.makeArray(count, function(i) what)),

slice(indexable, index, end, step)::
Expand Down Expand Up @@ -226,7 +226,7 @@ limitations under the License.
std.count(arr, x) > 0
else if std.isString(arr) then
std.length(std.findSubstr(x, arr)) > 0
else error "std.member first argument must be an array or a string",
else error 'std.member first argument must be an array or a string',

count(arr, x):: std.length(std.filter(function(v) v == x, arr)),

Expand Down Expand Up @@ -839,7 +839,7 @@ limitations under the License.
if a < b then a else b,

clamp(x, minVal, maxVal)::
if x < minVal then minVal
if x < minVal then minVal
else if x > maxVal then maxVal
else x,

Expand Down Expand Up @@ -1301,6 +1301,12 @@ limitations under the License.
objectHasAll(o, f)::
std.objectHasEx(o, f, true),

objectValues(o)::
[o[k] for k in std.objectFields(o)],

objectValuesAll(o)::
[o[k] for k in std.objectFieldsAll(o)],

equals(a, b)::
local ta = std.type(a);
local tb = std.type(b);
Expand Down
12 changes: 12 additions & 0 deletions test_suite/stdlib.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ std.assertEqual(std.objectFields({ x::: 1 } { x: 1 }), ['x']) &&
std.assertEqual(std.objectFields({ x::: 1 } { x:: 1 }), []) &&
std.assertEqual(std.objectFields({ x::: 1 } { x::: 1 }), ['x']) &&

std.assertEqual(std.objectValues({}), []) &&
std.assertEqual(std.objectValues({ x: 1, y: 2 }), [1, 2]) &&
std.assertEqual(std.objectValues({ x: 1 } { x: 1 }), [1]) &&
std.assertEqual(std.objectValues({ x: 1 } { x:: 1 }), []) &&
std.assertEqual(std.objectValues({ x: 1 } { x::: 1 }), [1]) &&
std.assertEqual(std.objectValues({ x:: 1 } { x: 1 }), []) &&
std.assertEqual(std.objectValues({ x:: 1 } { x:: 1 }), []) &&
std.assertEqual(std.objectValues({ x:: 1 } { x::: 1 }), [1]) &&
std.assertEqual(std.objectValues({ x::: 1 } { x: 1 }), [1]) &&
std.assertEqual(std.objectValues({ x::: 1 } { x:: 1 }), []) &&
std.assertEqual(std.objectValues({ x::: 1 } { x::: 1 }), [1]) &&


std.assertEqual(std.toString({ a: 1, b: 2 }), '{"a": 1, "b": 2}') &&
std.assertEqual(std.toString({}), '{ }') &&
Expand Down