@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 (31 loc) • 2.15 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkM3REM2FUcjs = require('./chunk-M3REM2FU.cjs');
// 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 = _nullishCoalesce(_optionalChain([_chunkM3REM2FUcjs.normalizeWindowsPath.call(void 0, filePath), 'optionalAccess', _ => _.split, 'call', _2 => _2(_optionalChain([filePath, 'optionalAccess', _3 => _3.includes, 'call', _4 => _4("\\")]) ? "\\" : "/"), 'optionalAccess', _5 => _5.pop, 'call', _6 => _6()]), () => ( ""));
if (requireExtension === true && !result.includes(".")) {
return "";
}
if (withExtension === false && result.includes(".")) {
return result.split(".").slice(-1).join(".") || "";
}
return result;
}
function findFilePath(filePath) {
const normalizedPath = _chunkM3REM2FUcjs.normalizeWindowsPath.call(void 0, filePath);
return normalizedPath.replace(
findFileName(normalizedPath, { requireExtension: true }),
""
);
}
exports.removeExtension = removeExtension; exports.findFileName = findFileName; exports.findFilePath = findFilePath;