UNPKG

@contextjs/system

Version:
10 lines (9 loc) 403 B
import { InvalidExpressionException } from "../exceptions/invalid-expression.exception.js"; export function nameof(expr) { if (typeof expr === "string") return expr; const match = /\.\s*([_$a-zA-Z][_$a-zA-Z0-9]*)\s*$/.exec(expr.toString()); if (!match) throw new InvalidExpressionException(`Invalid expression passed to nameof(): ${expr.toString()}`); return match[1]; }