Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

accessor-fn

1.3.0 • Public • Published

Accessor function

NPM package Build Size Dependencies

A wrapper for property accessors supporting functions, property strings or constant values.

Quick start

import accessorFn from 'accessor-fn';

or

var accessorFn = require('accessor-fn');

or even

<script src="//unpkg.com/accessor-fn"></script>

Usage example

Given an object

var obj = {
    a: 1,
    b: 2
}

Use accessorFn to access object values via property strings or transformation functions:

var aFn = accessorFn('a');
aFn(obj); // 1

var sumFn = accessorFn(d => d.a + d.b);
sumFn(obj); // 3

var constantFn = accessorFn(7);
constantFn(obj); // 7

Install

npm i accessor-fn

DownloadsWeekly Downloads

5,583

Version

1.3.0

License

MIT

Unpacked Size

5.85 kB

Total Files

9

Last publish

Collaborators

  • avatar