"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class DeclarationParser {
    static parsePackage(name) {
        let path;
        name = name.split("\\").join("/");
        const tokens = name.split("/");
        if (tokens[0].startsWith("@")) {
            name = [tokens[0], tokens[1]].join("/");
            path = tokens.filter((s, i) => i > 1).join("/");
        }
        else {
            name = tokens[0];
            path = tokens.filter((s, i) => i > 0).join("/");
        }
        return {
            name,
            path,
            fullPath: path ? `${name}/${path}` : name
        };
    }
    static packageName(name) {
        const tokens = name.split("/", 3);
        if (tokens[0].startsWith("@")) {
            return [tokens[0], tokens[1]].join("/");
        }
        return tokens[0];
    }
    static parseDependencies(content) {
        const dependencies = [];
        const lines = content.split("\n").map((s) => s.trim());
        for (const line of lines) {
            if (/^import\s/.test(line)) {
                let i = line.lastIndexOf("\"");
                let s = line.substring(0, i);
                i = s.lastIndexOf("\"");
                s = s.substring(i + 1);
                dependencies.push(s);
            }
        }
        return dependencies;
    }
    static resolveRelativePath(name, currentPackage) {
        if (name.charAt(0) !== ".") {
            return name;
        }
        const tokens = name.split("/");
        const currentTokens = currentPackage.split("/");
        currentTokens.pop();
        while (tokens.length) {
            const first = tokens[0];
            if (first === "..") {
                currentTokens.pop();
                tokens.splice(0, 1);
                continue;
            }
            if (first === ".") {
                tokens.splice(0, 1);
            }
            break;
        }
        return `${currentTokens.join("/")}/${tokens.join("/")}`;
    }
}
exports.default = DeclarationParser;
//# sourceMappingURL=DeclarationParser.js.map