diff options
author | Nico Williams <nico@cryptonector.com> | 2014-12-26 22:00:41 -0600 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2014-12-26 22:00:41 -0600 |
commit | 3234a7681e4c494d31c1dff5517e1d5d12eacf7b (patch) | |
tree | 88fcebe4dc8cf0b6fe58a0bbd2a7b30f6bd1b992 | |
parent | 36077da66ac06b4fdb325ac97a385ff2f0e9e8a6 (diff) | |
parent | a3234034b5cff66cca8b32c1caf4e935d2869812 (diff) |
Merge pull request #366 from slapresta/inversed-contains
Added `in` command
-rw-r--r-- | builtin.c | 2 | ||||
-rw-r--r-- | docs/content/3.manual/manual.yml | 40 |
2 files changed, 42 insertions, 0 deletions
@@ -1121,6 +1121,8 @@ static const char* const jq_builtins[] = { " | reduce range(0; $max) as $j" " ([]; . + [reduce range(0;$length) as $i ([]; . + [ $in[$i][$j] ] )] )" " end;", + "def in(xs): . as $x | xs | has($x)", + "def inside(xs): . as $x | xs | contains($x)", }; #undef LIBM_DD diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml index cd2b34e5..8087d8b6 100644 --- a/docs/content/3.manual/manual.yml +++ b/docs/content/3.manual/manual.yml @@ -653,6 +653,22 @@ sections: input: '[[0,1], ["a","b","c"]]' output: ['[false, true]'] + - title: `in` + body: | + + The builtin function `in` returns the input key is in the + given object, or the input index corresponds to an element + in the given array. It is, essentially, an inversed version + of `has`. + + examples: + - program: 'in({"foo": 42})' + input: '"foo", "bar"' + output: ['true', 'false'] + - program: 'map(in([0,1]))' + input: '[2, 0]' + output: ['false', 'true'] + - title: "`path(path_expression)`" body: | @@ -1175,6 +1191,30 @@ sections: input: '"a,b, cd, efg, hijk"' output: ['12'] + - title: `inside` + body: | + + The filter `inside(b)` will produce true if the input is + completely contained within b. It is, essentially, an + inversed version of `contains`. + + examples: + - program: 'inside("foobar")' + input: '"bar"' + output: ['true'] + - program: 'inside(["foobar", "foobaz", "blarp"])' + input: '["baz", "bar"]' + output: ['true'] + - program: 'inside(["foobar", "foobaz", "blarp"])' + input: '["bazzzzz", "bar"]' + output: ['false'] + - program: 'inside({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})' + input: '{foo: 12, bar: [{barp: 12}]}' + output: ['true'] + - program: 'inside({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})' + input: '{foo: 12, bar: [{barp: 15}]}' + output: ['false'] + - title: "`startswith(str)`" body: | |