Skip to content

Variant keywords

Variants evaluate a list of descriptors and pick from the results.

Core. An array where a descriptor goes means alternatives. The first defined result wins:

/name: ['/nickname', '/fullName']

Defined is the test, not truthy. An alternative that reads 0, "", or false wins over a later one:

/v: ['/zero', '/one']
{ "zero": 0, "one": 1 }

writes 0.

Core. Explicit form of the array descriptor: the first defined result.

/v: { first: ['/missing', '/b'] }
{ "b": 2 }

writes 2.

Core. The last defined result:

/v: { last: ['/a', '/missing'] }
{ "a": 1 }

writes 1.

Core. Every defined result, as an array:

/v: { all: ['/a', '/b'] }
{ "a": 1, "b": 2 }

writes [1, 2].

Core. Flattens an array result one level. Useful with all when the alternatives are themselves arrays:

/v: { all: ['/a', '/b'], concat: true }
{ "a": [1, 2], "b": [3] }

writes [1, 2, 3].