lowdefy/packages/docs/operators/_get.yaml

93 lines
2.6 KiB
YAML

# Copyright 2020-2021 Lowdefy, Inc
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
_ref:
path: templates/operators.yaml.njk
transformer: templates/operatorsMethodTransformer.js
vars:
pageId: _get
pageTitle: _get
types: |
```
(arguments: {
from: any[] | object,
key: string,
default?: any,
}): any
```
description: |
The `_get` operator gets a value from the object or array specified in `from`. If the `key` is not found, the provided `default`, or `null` if not specified, are returned.
arguments: |
###### object
- `from: any[] | object`: __Required__ - The object to get the value from.
- `key: string`: __Required__ - The value of the key in the `from` object is returned. If the value is not found, `null`, or the specified default value is returned. Dot notation and [block list indexes](/lists) are supported.
- `default: any`: A value to return if the `key` is not found in `from`. By default, `null` is returned if a value is not found.
examples: |
###### Get the value of a key from an object:
```yaml
_get:
from:
name: George
age: 22
key: name
```
Returns: `"George"`.
###### Get from an array (arrays are `0` indexed):
```yaml
_get:
from:
- id: 1
name: Joe
- id: 2
Name: Dave
key: 0.name
```
Returns: `1`.
###### Dot notation:
```yaml
_get:
from:
my_object:
subfield: 'Value'
key: my_object.subfield
```
Returns: `"Value"`.
###### Return a default value if the value is not found:
```yaml
_get:
from:
value1: 1
key: value2
default: 99
```
Returns: `99`.
###### Block list indices:
Assuming `state`:
```yaml
_get:
from:
my_array:
- value: 0
- value: 1
- value: 2
key: my_array.$.value
```
Returns: `0` when used from the first block (0th index) in a list.