A wrapper for property accessors supporting functions, property strings or constant values.
import accessorFn from 'accessor-fn';
or using a script tag
<script src="//unpkg.com/accessor-fn"></script>
Given an object
const obj = {
a: 1,
b: 2
}
Use accessorFn
to access object values via property strings or transformation functions:
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