Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @jasonhk/variable-name

@jasonhk/variable-name

A utility package consists functions that used to retrieve the name of variables.

npm-version-badge npm-download-badge npm-license-badge travis-build-badge codecov-coverage-badge

Installation

Node.js

$ npm install @jasonhk/variable-name

Usage

Load the Library

CommonJS

const { getVariableName, getVariableNames } = require("@jasonhk/variable-name");

ES2015 Modules

import { getVariableName, getVariableNames } from "@jasonhk/variable-name";

Using the Library

Get the name of a variable:

const variable = 1337;

// Should return "variable"
getVariableName({ variable });

Get the names of a list of variables:

const object = { property: 1337 };
const { property } = object;

// Should return ["object", "property"]
getVariableNames(
    [
        { object },
        { property },
    ]);

License

Copyright © 2019 Jason Kwok.
Licensed under the MIT License.

Index

Variables

Const DIRECTORY_DISTRIBUTION

DIRECTORY_DISTRIBUTION: string = Path.resolve(DIRECTORY_ROOT, "./dist")

Const DIRECTORY_ROOT

DIRECTORY_ROOT: string = Path.resolve(__dirname, "../")

Const DIRECTORY_SOURCE

DIRECTORY_SOURCE: string = Path.resolve(DIRECTORY_ROOT, "./src")

Functions

getVariableName

  • getVariableName(wrapper: object): string
  • Get the name of a variable as a string.

    remarks

    You must wrap the variable with an object literal, like the example below:

    const variable = 1337;
    
    // Should return "variable"
    getVariableName({ variable });
    since

    0.0.1

    Parameters

    • wrapper: object

      The target variable wrapped by an object literal

    Returns string

    The name of the variable

getVariableNames

  • getVariableNames(wrappers: object[]): string[]
  • Get the names of a list of variables as an Array of string.

    remarks

    You must wrap the variables with an Array of object literal, like the example below:

    const object = { property: 1337 };
    const { property } = object;
    
    // Should return ["object", "property"]
    getVariableNames(
        [
            { object },
            { property },
        ]);
    since

    0.0.1

    Parameters

    • wrappers: object[]

      The target variables wrapped by an Array of object literal

    Returns string[]

    The names of the variables

Generated using TypeDoc