goliatone / gkeypath

Simple keypath module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `ifNotSet` function

goliatone opened this issue · comments

Add an ifNotSet function to conditionally set a value if not present.

We basically want to do the following in a single operation:

let statusCode = KeyPath.get(response, '$meta.statusCode', '_EMPTY_');
if (statusCode === '_EMPTY_') {
    KeyPath.set(response, '$meta.statusCode', 500);
}