@synstack/path
Version:
Advanced path manipulation utilities
149 lines (146 loc) • 4.89 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/path.index.ts
var path_index_exports = {};
__export(path_index_exports, {
PathNotInCwdException: () => PathNotInCwdException,
addMissingExtension: () => addMissingExtension,
dirname: () => dirname2,
ensureFileExtension: () => ensureFileExtension,
fileExtension: () => fileExtension,
filename: () => filename,
filenameWithoutExtension: () => filenameWithoutExtension,
importUrlToAbsolutePath: () => importUrlToAbsolutePath,
isAbsolute: () => isAbsolute2,
isInPath: () => isInPath,
join: () => join2,
mimeType: () => mimeType,
path: () => path_bundle_exports,
relative: () => relative2,
removeRelativeIndicator: () => removeRelativeIndicator,
resolve: () => resolve2
});
module.exports = __toCommonJS(path_index_exports);
// src/path.bundle.ts
var path_bundle_exports = {};
__export(path_bundle_exports, {
addMissingExtension: () => addMissingExtension,
dirname: () => dirname2,
ensureFileExtension: () => ensureFileExtension,
fileExtension: () => fileExtension,
filename: () => filename,
filenameWithoutExtension: () => filenameWithoutExtension,
importUrlToAbsolutePath: () => importUrlToAbsolutePath,
isAbsolute: () => isAbsolute2,
isInPath: () => isInPath,
join: () => join2,
mimeType: () => mimeType,
relative: () => relative2,
removeRelativeIndicator: () => removeRelativeIndicator,
resolve: () => resolve2
});
// src/path.lib.ts
var import_mime_types = __toESM(require("mime-types"), 1);
var fsPath = __toESM(require("path"), 1);
var import_url = require("url");
var PathNotInCwdException = class extends Error {
constructor(path, cwd) {
super(`Path ${path} is not in cwd ${cwd}`);
}
};
function resolve2(...paths) {
return fsPath.resolve(...paths);
}
function isAbsolute2(path) {
return fsPath.isAbsolute(path);
}
function dirname2(path) {
return fsPath.dirname(resolve2(path));
}
function isInPath(basePath, path) {
const resolvedBasePath = resolve2(basePath);
const resolvedPath = resolve2(path);
return resolvedPath.startsWith(resolvedBasePath);
}
function relative2(basePath, path) {
return removeRelativeIndicator(
fsPath.relative(basePath, path)
);
}
function addMissingExtension(path, ext) {
return path.endsWith(ext) ? path : `${path}.${ext}`;
}
function join2(cwd, ...paths) {
return fsPath.join(cwd, ...paths);
}
function removeRelativeIndicator(path) {
return path.replace(/^\.\//, "");
}
function ensureFileExtension(filePath, extension) {
const normalizedExt = extension.startsWith(".") ? extension : `.${extension}`;
if (filePath.endsWith(normalizedExt)) return filePath;
return `${filePath}${normalizedExt}`;
}
var importUrlToAbsolutePath = (importUrl) => {
return fsPath.dirname((0, import_url.fileURLToPath)(importUrl));
};
var filename = (path) => {
return fsPath.parse(path).base;
};
var filenameWithoutExtension = (path) => {
return fsPath.parse(path).name;
};
var fileExtension = (path) => {
return fsPath.parse(path).ext;
};
var mimeType = (path) => {
const type = import_mime_types.default.lookup(path);
if (!type) return null;
return type;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PathNotInCwdException,
addMissingExtension,
dirname,
ensureFileExtension,
fileExtension,
filename,
filenameWithoutExtension,
importUrlToAbsolutePath,
isAbsolute,
isInPath,
join,
mimeType,
path,
relative,
removeRelativeIndicator,
resolve
});
//# sourceMappingURL=path.index.cjs.map