accessor-fn-2
v2.0.3
Published
A wrapper function for object accessor properties
Downloads
2
Maintainers
Readme
Accessor function
A wrapper for property accessors supporting functions, property strings or constant values.
Quick start
import { accessorFn } from 'accessor-fn';
Usage example
Given an object, Use accessorFn
to access object values via property strings or transformation functions:
const obj = {
a: 1,
b: 2
}
const aFn = accessorFn('a');
aFn(obj); // 1
const sumFn = accessorFn(d => d.a + d.b);
sumFn(obj); // 3
const constantFn = accessorFn(7);
constantFn(obj); // 7