@putkoff/abstract-utilities 1.0.28 → 1.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js
CHANGED
|
@@ -1831,6 +1831,28 @@ function get_splitext(filePath) {
|
|
|
1831
1831
|
const filename = pathBrowserify.basename(filePath, ext);
|
|
1832
1832
|
return { filename, ext };
|
|
1833
1833
|
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Returns the path of `targetPath` relative to `basePath`.
|
|
1836
|
+
* Normalizes separators for consistent web and server environments.
|
|
1837
|
+
*
|
|
1838
|
+
* @param basePath - The base directory you want to compare from.
|
|
1839
|
+
* @param targetPath - The full path of the file/directory.
|
|
1840
|
+
* @returns A normalized relative path (e.g., "subdir/file.txt").
|
|
1841
|
+
*/
|
|
1842
|
+
function get_relative_path(basePath, targetPath) {
|
|
1843
|
+
try {
|
|
1844
|
+
// Compute the relative path using Node's native path.relative
|
|
1845
|
+
let rel = pathBrowserify.relative(basePath, targetPath);
|
|
1846
|
+
// Normalize to POSIX-style slashes for consistency (especially on Windows)
|
|
1847
|
+
rel = rel.split(pathBrowserify.sep).join('/');
|
|
1848
|
+
// Avoid empty string (happens if both paths are identical)
|
|
1849
|
+
return rel || '.';
|
|
1850
|
+
}
|
|
1851
|
+
catch (err) {
|
|
1852
|
+
console.error(`[get_relative_path] Error computing relative path`, err);
|
|
1853
|
+
return targetPath;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1834
1856
|
/**
|
|
1835
1857
|
* Join multiple path segments, normalizing leading/trailing slashes.
|
|
1836
1858
|
*
|
|
@@ -2416,6 +2438,7 @@ exports.get_keyword_string = get_keyword_string;
|
|
|
2416
2438
|
exports.get_media_exts = get_media_exts;
|
|
2417
2439
|
exports.get_media_map = get_media_map;
|
|
2418
2440
|
exports.get_mime_type = get_mime_type;
|
|
2441
|
+
exports.get_relative_path = get_relative_path;
|
|
2419
2442
|
exports.get_splitext = get_splitext;
|
|
2420
2443
|
exports.get_window = get_window;
|
|
2421
2444
|
exports.get_window_location = get_window_location;
|