@putkoff/abstract-utilities 0.1.235 → 0.1.236
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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
|
+
var path = require('path');
|
|
4
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
6
|
|
|
6
7
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -561,6 +562,89 @@ function fetchIndexHtmlContainer(filename_1) {
|
|
|
561
562
|
});
|
|
562
563
|
}
|
|
563
564
|
|
|
565
|
+
function urlJoin(...parts) {
|
|
566
|
+
var _a;
|
|
567
|
+
const s = (parts.length === 1 && Array.isArray(parts[0]) ? parts[0] : parts);
|
|
568
|
+
let r = "";
|
|
569
|
+
for (let i = 0; i < s.length; i++) {
|
|
570
|
+
let d = ((_a = s[i]) !== null && _a !== void 0 ? _a : "").toString();
|
|
571
|
+
if (!d)
|
|
572
|
+
continue;
|
|
573
|
+
if (i === 0)
|
|
574
|
+
r = d;
|
|
575
|
+
else {
|
|
576
|
+
d = d.replace(/^\/+/, "");
|
|
577
|
+
r = r.replace(/\/+$/, "");
|
|
578
|
+
r = `${r}/${d}`;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return r;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Returns a full URL.
|
|
585
|
+
* If partial_url is already absolute (starts with http), it is returned as is.
|
|
586
|
+
* Otherwise, it is combined with the base URL.
|
|
587
|
+
*/
|
|
588
|
+
function get_full_url(partial_url, domain = null) {
|
|
589
|
+
if (typeof partial_url !== 'string') {
|
|
590
|
+
throw new Error('partial_url must be a string');
|
|
591
|
+
}
|
|
592
|
+
// If it already starts with http, assume it is absolute.
|
|
593
|
+
if (partial_url.startsWith('http')) {
|
|
594
|
+
return partial_url;
|
|
595
|
+
}
|
|
596
|
+
return urlJoin(domain, partial_url);
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Returns a full file system path.
|
|
600
|
+
* If partial_path is already absolute, it is returned as is.
|
|
601
|
+
* Otherwise, it is joined with the base directory.
|
|
602
|
+
*/
|
|
603
|
+
function get_full_path(partial_path, parent_dir = null) {
|
|
604
|
+
if (typeof partial_path !== 'string') {
|
|
605
|
+
throw new Error('partial_path must be a string');
|
|
606
|
+
}
|
|
607
|
+
if (path.isAbsolute(partial_path)) {
|
|
608
|
+
return partial_path;
|
|
609
|
+
}
|
|
610
|
+
return urlJoin(parent_dir, partial_path);
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Converts a local file system path into its corresponding URL.
|
|
614
|
+
* It checks against the known directories in all_paths and replaces the matching base.
|
|
615
|
+
*/
|
|
616
|
+
function path_to_url(filePath, all_paths) {
|
|
617
|
+
if (typeof filePath !== 'string') {
|
|
618
|
+
throw new Error('filePath must be a string');
|
|
619
|
+
}
|
|
620
|
+
for (const key in all_paths) {
|
|
621
|
+
const mapping = all_paths[key];
|
|
622
|
+
const normalizedBase = path.normalize(mapping.path);
|
|
623
|
+
if (filePath.startsWith(normalizedBase)) {
|
|
624
|
+
const relativePath = filePath.substring(normalizedBase.length);
|
|
625
|
+
return urlJoin(mapping.url, relativePath.replace(/\\/g, '/'));
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return null;
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Converts a URL into its corresponding local file system path.
|
|
632
|
+
* It checks against the known URL prefixes in all_paths and replaces the matching base.
|
|
633
|
+
*/
|
|
634
|
+
function url_to_path(urlStr, all_paths) {
|
|
635
|
+
if (typeof urlStr !== 'string') {
|
|
636
|
+
throw new Error('urlStr must be a string');
|
|
637
|
+
}
|
|
638
|
+
for (const key in all_paths) {
|
|
639
|
+
const mapping = all_paths[key];
|
|
640
|
+
if (urlStr.startsWith(mapping.url)) {
|
|
641
|
+
const relativeUrl = urlStr.substring(mapping.url.length);
|
|
642
|
+
return urlJoin(mapping.path, relativeUrl);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
|
|
564
648
|
function assertPath(path) {
|
|
565
649
|
if (typeof path !== 'string') {
|
|
566
650
|
throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
|
|
@@ -1796,6 +1880,8 @@ exports.get_basename = get_basename;
|
|
|
1796
1880
|
exports.get_dirname = get_dirname;
|
|
1797
1881
|
exports.get_extname = get_extname;
|
|
1798
1882
|
exports.get_filename = get_filename;
|
|
1883
|
+
exports.get_full_path = get_full_path;
|
|
1884
|
+
exports.get_full_url = get_full_url;
|
|
1799
1885
|
exports.get_key_value = get_key_value;
|
|
1800
1886
|
exports.get_keyword_string = get_keyword_string;
|
|
1801
1887
|
exports.get_relative_path = get_relative_path;
|
|
@@ -1815,6 +1901,7 @@ exports.make_path = make_path;
|
|
|
1815
1901
|
exports.make_sanitized_path = make_sanitized_path;
|
|
1816
1902
|
exports.normalizeUrl = normalizeUrl;
|
|
1817
1903
|
exports.parseResult = parseResult;
|
|
1904
|
+
exports.path_to_url = path_to_url;
|
|
1818
1905
|
exports.processKeywords = processKeywords;
|
|
1819
1906
|
exports.readJsonFile = readJsonFile;
|
|
1820
1907
|
exports.removeToken = removeToken;
|
|
@@ -1829,4 +1916,6 @@ exports.sanitizeFilename = sanitizeFilename;
|
|
|
1829
1916
|
exports.stripPrefixes = stripPrefixes;
|
|
1830
1917
|
exports.truncateString = truncateString;
|
|
1831
1918
|
exports.tryParse = tryParse;
|
|
1919
|
+
exports.urlJoin = urlJoin;
|
|
1920
|
+
exports.url_to_path = url_to_path;
|
|
1832
1921
|
//# sourceMappingURL=index.js.map
|