UNPKG

@aikidosec/firewall

Version:

Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.

25 lines (24 loc) 821 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getModuleInfoFromPath = getModuleInfoFromPath; const path_1 = require("path"); /** * Get the module name and dir from a path that is inside a node_modules folder. */ function getModuleInfoFromPath(path) { const segments = path.split(path_1.sep); const i = segments.lastIndexOf("node_modules"); if (i === -1 || i + 1 >= segments.length) { return undefined; } const isScoped = segments[i + 1][0] === "@"; const name = isScoped ? segments[i + 1] + "/" + segments[i + 2] : segments[i + 1]; const offset = isScoped ? 3 : 2; return { name: name, base: segments.slice(0, i + offset).join(path_1.sep), path: segments.slice(i + offset).join(path_1.sep), }; }