detective-getter-deps
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

detective-getter-deps

Extract the getter dependencies from object.

Installation

npm i detective-getter-deps

Usage

import { detectGetterDeps } from 'detective-getter-deps';

const dependencies = detectGetterDeps({
  firstName: 'jeans',
  lastName: 'new',
  get fullName() {
    return [this.firstName, this.lastName].join(' ');
  },
});

dependencies.fullName; // Set { 'firstName', 'lastName' }

Why?

This is useful when you want to know which properties are used in the getter.

Disclaimer

If there are conditional evaluation rules within the getter body, it may not work properly because there could be properties that are not accessed depending on the object state conditions.

import { detectGetterDeps } from 'detective-getter-deps';

const dependencies = detectGetterDeps({
  realName: 'deno',
  alias: 'saurus',
  get name() {
    return this.alias || this.realName;
  },
});

dependencies.name;
// Set { 'alias' }
// not Set { 'alias', 'realName' }

Dependencies (0)

    Dev Dependencies (16)

    Package Sidebar

    Install

    npm i detective-getter-deps

    Weekly Downloads

    11

    Version

    2.0.2

    License

    Apache-2.0

    Unpacked Size

    19.6 kB

    Total Files

    16

    Last publish

    Collaborators

    • sungchuni