UNPKG

@storm-software/config-tools

Version:

A package containing various utilities to support custom workspace configurations and environment management for Storm Software projects, including configuration file handling, environment variable management, and logging utilities.

39 lines (36 loc) 1.15 kB
import { normalizeWindowsPath } from "./chunk-V3GMJ4TX.js"; // src/utilities/file-path-utils.ts var removeExtension = (filePath) => { const result = !filePath || (filePath?.match(/./g) || []).length <= 1 ? "." : filePath.lastIndexOf(".") ? filePath.substring(0, filePath.lastIndexOf(".")) : filePath; if (result.startsWith("./")) { return result.substring(2); } if (result.startsWith(".") || result.startsWith("/")) { return result.substring(1); } return result; }; function findFileName(filePath, { requireExtension, withExtension } = {}) { const result = normalizeWindowsPath(filePath)?.split(filePath?.includes("\\") ? "\\" : "/")?.pop() ?? ""; if (requireExtension === true && !result.includes(".")) { return ""; } if (withExtension === false && result.includes(".")) { return result.split(".").slice(-1).join(".") || ""; } return result; } function findFilePath(filePath) { const normalizedPath = normalizeWindowsPath(filePath); return normalizedPath.replace( findFileName(normalizedPath, { requireExtension: true }), "" ); } export { removeExtension, findFileName, findFilePath };