JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 176522
  • Score
    100M100P100Q166177F
  • License MIT

A wrapper function for object accessor properties

Package Exports

  • accessor-fn

Readme

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="//cdn.jsdelivr.net/npm/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