A value extractor that can retrieve data from an object using various methods.
This type supports multiple ways to extract values from your data structure:
The type of the data object to extract values from
Simple property access:
const getter: ValueGetter<{ name: string }> = "name"; Copy
const getter: ValueGetter<{ name: string }> = "name";
Dot notation for nested properties:
const getter: ValueGetter<{ user: { profile: { name: string } } }> = "user.profile.name"; Copy
const getter: ValueGetter<{ user: { profile: { name: string } } }> = "user.profile.name";
Array element access:
const getter: ValueGetter<{ items: string[] }> = "items[0]"; Copy
const getter: ValueGetter<{ items: string[] }> = "items[0]";
JSONPath expression:
const getter: ValueGetter<{ items: Array<{ id: number }> }> = "$.items[*].id"; Copy
const getter: ValueGetter<{ items: Array<{ id: number }> }> = "$.items[*].id";
Function-based extraction:
const getter: ValueGetter<{ firstName: string; lastName: string }> = (data) => `${data.firstName} ${data.lastName}`; Copy
const getter: ValueGetter<{ firstName: string; lastName: string }> = (data) => `${data.firstName} ${data.lastName}`;
Complex transformation:
const getter: ValueGetter<{ scores: number[] }> = (data) => data.scores.reduce((a, b) => a + b, 0) / data.scores.length; Copy
const getter: ValueGetter<{ scores: number[] }> = (data) => data.scores.reduce((a, b) => a + b, 0) / data.scores.length;
A value extractor that can retrieve data from an object using various methods.
This type supports multiple ways to extract values from your data structure: