accessor-fn
v1.5.1
Published
A wrapper function for object accessor properties
Downloads
281,329
Maintainers
Readme
Accessor function
A wrapper for property accessors supporting functions, property strings or constant values.
Quick start
import accessorFn from 'accessor-fn';
or using a script tag
<script src="//unpkg.com/accessor-fn"></script>
Usage example
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