@contextjs/system
Version:
ContextJS - System
10 lines (9 loc) • 403 B
JavaScript
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];
}