accessor-fn
TypeScript icon, indicating that this package has built-in type declarations

1.5.1 • Public • Published

Accessor function

NPM package Build Size NPM Downloads

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

Package Sidebar

Install

npm i accessor-fn

Weekly Downloads

70,480

Version

1.5.1

License

MIT

Unpacked Size

5.78 kB

Total Files

8

Last publish

Collaborators

  • vasturiano