Added docs

This commit is contained in:
Mike Farah 2023-03-18 14:51:31 +11:00
parent d8324dee0d
commit fdce8fce13
7 changed files with 51 additions and 0 deletions

View File

@ -1,3 +1,8 @@
# Divide
Divide behaves differently according to the type of the LHS:
* strings: split by the divider
* number: arithmetic division
## String split
Given a sample.yml file of:

View File

@ -1,3 +1,7 @@
# Filter
Filters an array (or map values) by the expression given. Equivalent to doing `map(select(exp))`.
## Filter array
Given a sample.yml file of:
@ -16,3 +20,23 @@ will output
- 2
```
## Filter map values
Given a sample.yml file of:
```yaml
c:
things: cool
frog: yes
d:
things: hot
frog: false
```
then
```bash
yq 'filter(.things == "cool")' sample.yml
```
will output
```yaml
- things: cool
frog: yes
```

View File

@ -0,0 +1,5 @@
# Divide
Divide behaves differently according to the type of the LHS:
* strings: split by the divider
* number: arithmetic division

View File

@ -0,0 +1,4 @@
# Filter
Filters an array (or map values) by the expression given. Equivalent to doing `map(select(exp))`.

View File

@ -0,0 +1,3 @@
# Modulo
Arithmetic modulo operator, returns the remainder from dividing two numbers.

View File

@ -1,4 +1,6 @@
# Modulo
Arithmetic modulo operator, returns the remainder from dividing two numbers.
## Number modulo - int
If the lhs and rhs are ints then the expression will be calculated with ints.

View File

@ -13,6 +13,14 @@ var filterOperatorScenarios = []expressionScenario{
"D0, P[], (!!seq)::[1, 2]\n",
},
},
{
description: "Filter map values",
document: `{c: {things: cool, frog: yes}, d: {things: hot, frog: false}}`,
expression: `filter(.things == "cool")`,
expected: []string{
"D0, P[], (!!seq)::[{things: cool, frog: yes}]\n",
},
},
{
skipDoc: true,
document: `[1,2,3]`,