@nodesecure/js-x-ray
Version:
JavaScript AST XRay analysis
47 lines • 1.41 kB
JavaScript
export function isNode(value) {
return (value !== null &&
typeof value === "object" &&
"type" in value &&
typeof value.type === "string");
}
export function isStringLiteral(node) {
return isLiteral(node) &&
typeof node.value === "string";
}
export function isLiteral(node) {
return isNode(node) &&
node.type === "Literal";
}
export function isNumericLiteral(node) {
return isLiteral(node) &&
typeof (node).value === "number";
}
export function isTemplateLiteral(node) {
if (!isNode(node) || node.type !== "TemplateLiteral") {
return false;
}
const firstQuasi = node.quasis.at(0);
if (!firstQuasi) {
return false;
}
return (firstQuasi.type === "TemplateElement" &&
typeof firstQuasi.value.raw === "string");
}
export function isFunctionNode(node) {
return isNode(node) && (node.type === "FunctionDeclaration" ||
node.type === "FunctionExpression" ||
node.type === "ArrowFunctionExpression");
}
export function isCallExpression(node) {
return isNode(node) && node.type === "CallExpression";
}
export function isIdentifier(node) {
return isNode(node) && node.type === "Identifier";
}
export function isMemberExpression(node) {
return isNode(node) && node.type === "MemberExpression";
}
export function noop(_name) {
return null;
}
//# sourceMappingURL=types.js.map