Get the name of a variable as a string.
The target variable wrapped by an object literal
The name of the variable
Get the names of a list of variables as an Array
of string.
The target variables wrapped by an Array
of object literal
The names of the variables
Generated using TypeDoc
@jasonhk/variable-name
A utility package consists functions that used to retrieve the name of variables.
Installation
Node.js
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.