Skip to content

Instantly share code, notes, and snippets.

View JuanFelix88's full-sized avatar
🏠
Working from home

Juan Felix JuanFelix88

🏠
Working from home
View GitHub Profile
@JuanFelix88
JuanFelix88 / getName.ts
Last active February 7, 2020 22:04
Get variable name by call stack in NODE.JS (unsafe code)
import fs from "fs";
import { resolve } from "path";
function getVarName(variable: any): string {
const stack2: string = new Error().stack.split(/at/g)[2].trim();
const splitted = stack2.substr(20, stack2.length - 21).split(/:/);
const lineAndPosition = splitted.slice(2).map(item => parseInt(item));