memoize-get
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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);

/memoize-get/

    Package Sidebar

    Install

    npm i memoize-get

    Weekly Downloads

    2

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    9.38 kB

    Total Files

    15

    Last publish

    Collaborators

    • roginfarrer