UNPKG

sussy-util

Version:
20 lines (19 loc) 822 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); /** * "If the package.json file exists in the given directory, return the directory, otherwise, return the * parent directory." * * The function is recursive, meaning that it calls itself. It does this until it finds the * package.json file * @param {string} dirPath - The path to the directory you want to check. */ const temp = (dirPath) => fs_1.default.existsSync(path_1.default.join(dirPath, 'package.json')) ? dirPath : temp(path_1.default.resolve(`${dirPath}/../`)); exports.default = temp;