memoize-get

v0.1.0
Memoize functions with the "get" function signature.

memoize-get

Memoize functions with the "get" function signature.

Installation

yarn add memoize-get

npm install memoize-get

Usage

import {memoizeGet, Get} from 'memoize-get';

const get: Get = (
  obj: object,
  path: string | number,
  fallback?: any,
) {
  const key = typeof path === 'string' ? path.split('.') : [path];

  for (index = 0; index < key.length; index += 1 ) {
    if (!obj) break;
    obj = obj[key[index]];
  }

  return obj === undefined ? fallback : obj;
}

const memoizedGet = memoizeGet(get);
npm i memoize-get

Metadata

  • MIT
  • >=10
  • Rogin Farrer
  • released 3/18/2021

Downloads

Maintainers