@putkoff/abstract-utilities 0.1.243 → 0.1.244
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 +511 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +514 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/functions/auth_utils/imports.js +1 -0
- package/dist/functions/auth_utils/index.js +1 -0
- package/dist/functions/auth_utils/src/index.js +1 -0
- package/dist/functions/auth_utils/src/token_utils.js +104 -0
- package/dist/functions/config_utils/imports.js +2 -0
- package/dist/functions/config_utils/index.js +1 -0
- package/dist/functions/config_utils/src/config_utils.js +16 -0
- package/dist/functions/config_utils/src/index.js +1 -0
- package/dist/functions/constants_utils/index.js +1 -0
- package/dist/functions/constants_utils/src/constants.js +7 -0
- package/dist/functions/constants_utils/src/index.js +1 -0
- package/dist/functions/env_utils/imports.js +1 -0
- package/dist/functions/env_utils/index.js +1 -0
- package/dist/functions/env_utils/src/index.js +1 -0
- package/dist/functions/env_utils/src/window_utils.js +47 -0
- package/dist/functions/fetch_utils/imports.js +2 -0
- package/dist/functions/fetch_utils/index.js +1 -0
- package/dist/functions/fetch_utils/src/fetch_utils.js +65 -0
- package/dist/functions/fetch_utils/src/index.js +3 -0
- package/dist/functions/fetch_utils/src/url_utils.js +83 -0
- package/dist/functions/fetch_utils/src/utils.js +101 -0
- package/dist/functions/index.js +17 -0
- package/dist/functions/math_utils/index.js +1 -0
- package/dist/functions/math_utils/safe_math.js +26 -0
- package/dist/functions/path_utils/imports.js +28 -0
- package/dist/functions/path_utils/index.js +1 -0
- package/dist/functions/path_utils/src/base_dirs.js +17 -0
- package/dist/functions/path_utils/src/function_dirs.js +42 -0
- package/dist/functions/path_utils/src/index.js +6 -0
- package/dist/functions/path_utils/src/misc_dirs.js +15 -0
- package/dist/functions/path_utils/src/path_utils.browser.js +3 -0
- package/dist/functions/path_utils/src/path_utils.js +112 -0
- package/dist/functions/path_utils/src/path_utils.node.js +3 -0
- package/dist/functions/path_utils/src/paths.js +12 -0
- package/dist/functions/path_utils/src/src_dirs.js +25 -0
- package/dist/functions/read_utils/imports.js +1 -0
- package/dist/functions/read_utils/index.js +1 -0
- package/dist/functions/read_utils/src/index.js +1 -0
- package/dist/functions/read_utils/src/read_utils.browser.js +17 -0
- package/dist/functions/read_utils/src/utils.browser.js +32 -0
- package/dist/functions/read_utils/src/utils.js +70 -0
- package/dist/functions/rndm_utils/imports.js +1 -0
- package/dist/functions/rndm_utils/index.js +1 -0
- package/dist/functions/rndm_utils/src/index.js +1 -0
- package/dist/functions/rndm_utils/src/utils.js +13 -0
- package/dist/functions/safe_utils/imports.js +1 -0
- package/dist/functions/safe_utils/index.js +1 -0
- package/dist/functions/safe_utils/src/index.js +4 -0
- package/dist/functions/safe_utils/src/safe_document.js +12 -0
- package/dist/functions/safe_utils/src/safe_globals.js +14 -0
- package/dist/functions/safe_utils/src/safe_storage.js +52 -0
- package/dist/functions/safe_utils/src/safe_window.js +42 -0
- package/dist/functions/string_utils/index.js +1 -0
- package/dist/functions/string_utils/src/index.js +1 -0
- package/dist/functions/string_utils/src/string_utils.js +153 -0
- package/dist/functions/type_utils/imports.js +1 -0
- package/dist/functions/type_utils/index.js +1 -0
- package/dist/functions/type_utils/src/clean_utils.js +38 -0
- package/dist/functions/type_utils/src/ensure_utils.js +33 -0
- package/dist/functions/type_utils/src/index.js +5 -0
- package/dist/functions/type_utils/src/json_utils.js +22 -0
- package/dist/functions/type_utils/src/mime_utils.js +311 -0
- package/dist/functions/type_utils/src/type_utils.js +39 -0
- package/dist/functions/ui_utils/imports.js +5 -0
- package/dist/functions/ui_utils/index.js +1 -0
- package/dist/functions/ui_utils/src/button.js +22 -0
- package/dist/functions/ui_utils/src/checkbox.js +6 -0
- package/dist/functions/ui_utils/src/index.js +4 -0
- package/dist/functions/ui_utils/src/input.js +6 -0
- package/dist/functions/ui_utils/src/spinner.js +4 -0
- package/dist/functions/url_utils/index.js +1 -0
- package/dist/functions/url_utils/uri_utils.js +69 -0
- package/dist/functions/variable_utils/imports.js +1 -0
- package/dist/functions/variable_utils/index.js +1 -0
- package/dist/functions/variable_utils/src/index.js +1 -0
- package/dist/functions/variable_utils/src/variable_utils.js +34 -0
- package/dist/functions.json +1727 -0
- package/dist/index.js +2 -0
- package/dist/types/index.js +1 -0
- package/dist/types/src/ChangePassword.js +1 -0
- package/dist/types/src/Files.js +1 -0
- package/dist/types/src/index.js +5 -0
- package/dist/types/src/login.js +1 -0
- package/dist/types/src/logout.js +1 -0
- package/dist/types/src/utils.js +1 -0
- package/dist/utils/imports.js +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/src/Input.js +2 -0
- package/dist/utils/src/config.js +12 -0
- package/dist/utils/src/index.js +3 -0
- package/package.json +4 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import path$
|
|
3
|
-
import * as path$1 from 'path-browserify';
|
|
2
|
+
import path$1 from 'path';
|
|
4
3
|
import * as fs from 'node:fs';
|
|
5
4
|
import * as fsp from 'node:fs/promises';
|
|
6
5
|
import * as path from 'node:path';
|
|
@@ -604,7 +603,7 @@ function get_full_path(partial_path, parent_dir = null) {
|
|
|
604
603
|
if (typeof partial_path !== 'string') {
|
|
605
604
|
throw new Error('partial_path must be a string');
|
|
606
605
|
}
|
|
607
|
-
if (path$
|
|
606
|
+
if (path$1.isAbsolute(partial_path)) {
|
|
608
607
|
return partial_path;
|
|
609
608
|
}
|
|
610
609
|
return urlJoin(parent_dir, partial_path);
|
|
@@ -619,7 +618,7 @@ function path_to_url(filePath, all_paths) {
|
|
|
619
618
|
}
|
|
620
619
|
for (const key in all_paths) {
|
|
621
620
|
const mapping = all_paths[key];
|
|
622
|
-
const normalizedBase = path$
|
|
621
|
+
const normalizedBase = path$1.normalize(mapping.path);
|
|
623
622
|
if (filePath.startsWith(normalizedBase)) {
|
|
624
623
|
const relativePath = filePath.substring(normalizedBase.length);
|
|
625
624
|
return urlJoin(mapping.url, relativePath.replace(/\\/g, '/'));
|
|
@@ -645,6 +644,508 @@ function url_to_path(urlStr, all_paths) {
|
|
|
645
644
|
return null;
|
|
646
645
|
}
|
|
647
646
|
|
|
647
|
+
function assertPath(path) {
|
|
648
|
+
if (typeof path !== 'string') {
|
|
649
|
+
throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// Resolves . and .. elements in a path with directory names
|
|
654
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
655
|
+
var res = '';
|
|
656
|
+
var lastSegmentLength = 0;
|
|
657
|
+
var lastSlash = -1;
|
|
658
|
+
var dots = 0;
|
|
659
|
+
var code;
|
|
660
|
+
for (var i = 0; i <= path.length; ++i) {
|
|
661
|
+
if (i < path.length)
|
|
662
|
+
code = path.charCodeAt(i);
|
|
663
|
+
else if (code === 47 /*/*/)
|
|
664
|
+
break;
|
|
665
|
+
else
|
|
666
|
+
code = 47 /*/*/;
|
|
667
|
+
if (code === 47 /*/*/) {
|
|
668
|
+
if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {
|
|
669
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
|
|
670
|
+
if (res.length > 2) {
|
|
671
|
+
var lastSlashIndex = res.lastIndexOf('/');
|
|
672
|
+
if (lastSlashIndex !== res.length - 1) {
|
|
673
|
+
if (lastSlashIndex === -1) {
|
|
674
|
+
res = '';
|
|
675
|
+
lastSegmentLength = 0;
|
|
676
|
+
} else {
|
|
677
|
+
res = res.slice(0, lastSlashIndex);
|
|
678
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
|
|
679
|
+
}
|
|
680
|
+
lastSlash = i;
|
|
681
|
+
dots = 0;
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
685
|
+
res = '';
|
|
686
|
+
lastSegmentLength = 0;
|
|
687
|
+
lastSlash = i;
|
|
688
|
+
dots = 0;
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
if (allowAboveRoot) {
|
|
693
|
+
if (res.length > 0)
|
|
694
|
+
res += '/..';
|
|
695
|
+
else
|
|
696
|
+
res = '..';
|
|
697
|
+
lastSegmentLength = 2;
|
|
698
|
+
}
|
|
699
|
+
} else {
|
|
700
|
+
if (res.length > 0)
|
|
701
|
+
res += '/' + path.slice(lastSlash + 1, i);
|
|
702
|
+
else
|
|
703
|
+
res = path.slice(lastSlash + 1, i);
|
|
704
|
+
lastSegmentLength = i - lastSlash - 1;
|
|
705
|
+
}
|
|
706
|
+
lastSlash = i;
|
|
707
|
+
dots = 0;
|
|
708
|
+
} else if (code === 46 /*.*/ && dots !== -1) {
|
|
709
|
+
++dots;
|
|
710
|
+
} else {
|
|
711
|
+
dots = -1;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return res;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function _format(sep, pathObject) {
|
|
718
|
+
var dir = pathObject.dir || pathObject.root;
|
|
719
|
+
var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
|
|
720
|
+
if (!dir) {
|
|
721
|
+
return base;
|
|
722
|
+
}
|
|
723
|
+
if (dir === pathObject.root) {
|
|
724
|
+
return dir + base;
|
|
725
|
+
}
|
|
726
|
+
return dir + sep + base;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
var posix = {
|
|
730
|
+
// path.resolve([from ...], to)
|
|
731
|
+
resolve: function resolve() {
|
|
732
|
+
var resolvedPath = '';
|
|
733
|
+
var resolvedAbsolute = false;
|
|
734
|
+
var cwd;
|
|
735
|
+
|
|
736
|
+
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
737
|
+
var path;
|
|
738
|
+
if (i >= 0)
|
|
739
|
+
path = arguments[i];
|
|
740
|
+
else {
|
|
741
|
+
if (cwd === undefined)
|
|
742
|
+
cwd = process.cwd();
|
|
743
|
+
path = cwd;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
assertPath(path);
|
|
747
|
+
|
|
748
|
+
// Skip empty entries
|
|
749
|
+
if (path.length === 0) {
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
resolvedPath = path + '/' + resolvedPath;
|
|
754
|
+
resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// At this point the path should be resolved to a full absolute path, but
|
|
758
|
+
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
759
|
+
|
|
760
|
+
// Normalize the path
|
|
761
|
+
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
762
|
+
|
|
763
|
+
if (resolvedAbsolute) {
|
|
764
|
+
if (resolvedPath.length > 0)
|
|
765
|
+
return '/' + resolvedPath;
|
|
766
|
+
else
|
|
767
|
+
return '/';
|
|
768
|
+
} else if (resolvedPath.length > 0) {
|
|
769
|
+
return resolvedPath;
|
|
770
|
+
} else {
|
|
771
|
+
return '.';
|
|
772
|
+
}
|
|
773
|
+
},
|
|
774
|
+
|
|
775
|
+
normalize: function normalize(path) {
|
|
776
|
+
assertPath(path);
|
|
777
|
+
|
|
778
|
+
if (path.length === 0) return '.';
|
|
779
|
+
|
|
780
|
+
var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
|
|
781
|
+
var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
|
|
782
|
+
|
|
783
|
+
// Normalize the path
|
|
784
|
+
path = normalizeStringPosix(path, !isAbsolute);
|
|
785
|
+
|
|
786
|
+
if (path.length === 0 && !isAbsolute) path = '.';
|
|
787
|
+
if (path.length > 0 && trailingSeparator) path += '/';
|
|
788
|
+
|
|
789
|
+
if (isAbsolute) return '/' + path;
|
|
790
|
+
return path;
|
|
791
|
+
},
|
|
792
|
+
|
|
793
|
+
isAbsolute: function isAbsolute(path) {
|
|
794
|
+
assertPath(path);
|
|
795
|
+
return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
|
|
796
|
+
},
|
|
797
|
+
|
|
798
|
+
join: function join() {
|
|
799
|
+
if (arguments.length === 0)
|
|
800
|
+
return '.';
|
|
801
|
+
var joined;
|
|
802
|
+
for (var i = 0; i < arguments.length; ++i) {
|
|
803
|
+
var arg = arguments[i];
|
|
804
|
+
assertPath(arg);
|
|
805
|
+
if (arg.length > 0) {
|
|
806
|
+
if (joined === undefined)
|
|
807
|
+
joined = arg;
|
|
808
|
+
else
|
|
809
|
+
joined += '/' + arg;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
if (joined === undefined)
|
|
813
|
+
return '.';
|
|
814
|
+
return posix.normalize(joined);
|
|
815
|
+
},
|
|
816
|
+
|
|
817
|
+
relative: function relative(from, to) {
|
|
818
|
+
assertPath(from);
|
|
819
|
+
assertPath(to);
|
|
820
|
+
|
|
821
|
+
if (from === to) return '';
|
|
822
|
+
|
|
823
|
+
from = posix.resolve(from);
|
|
824
|
+
to = posix.resolve(to);
|
|
825
|
+
|
|
826
|
+
if (from === to) return '';
|
|
827
|
+
|
|
828
|
+
// Trim any leading backslashes
|
|
829
|
+
var fromStart = 1;
|
|
830
|
+
for (; fromStart < from.length; ++fromStart) {
|
|
831
|
+
if (from.charCodeAt(fromStart) !== 47 /*/*/)
|
|
832
|
+
break;
|
|
833
|
+
}
|
|
834
|
+
var fromEnd = from.length;
|
|
835
|
+
var fromLen = fromEnd - fromStart;
|
|
836
|
+
|
|
837
|
+
// Trim any leading backslashes
|
|
838
|
+
var toStart = 1;
|
|
839
|
+
for (; toStart < to.length; ++toStart) {
|
|
840
|
+
if (to.charCodeAt(toStart) !== 47 /*/*/)
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
var toEnd = to.length;
|
|
844
|
+
var toLen = toEnd - toStart;
|
|
845
|
+
|
|
846
|
+
// Compare paths to find the longest common path from root
|
|
847
|
+
var length = fromLen < toLen ? fromLen : toLen;
|
|
848
|
+
var lastCommonSep = -1;
|
|
849
|
+
var i = 0;
|
|
850
|
+
for (; i <= length; ++i) {
|
|
851
|
+
if (i === length) {
|
|
852
|
+
if (toLen > length) {
|
|
853
|
+
if (to.charCodeAt(toStart + i) === 47 /*/*/) {
|
|
854
|
+
// We get here if `from` is the exact base path for `to`.
|
|
855
|
+
// For example: from='/foo/bar'; to='/foo/bar/baz'
|
|
856
|
+
return to.slice(toStart + i + 1);
|
|
857
|
+
} else if (i === 0) {
|
|
858
|
+
// We get here if `from` is the root
|
|
859
|
+
// For example: from='/'; to='/foo'
|
|
860
|
+
return to.slice(toStart + i);
|
|
861
|
+
}
|
|
862
|
+
} else if (fromLen > length) {
|
|
863
|
+
if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
|
|
864
|
+
// We get here if `to` is the exact base path for `from`.
|
|
865
|
+
// For example: from='/foo/bar/baz'; to='/foo/bar'
|
|
866
|
+
lastCommonSep = i;
|
|
867
|
+
} else if (i === 0) {
|
|
868
|
+
// We get here if `to` is the root.
|
|
869
|
+
// For example: from='/foo'; to='/'
|
|
870
|
+
lastCommonSep = 0;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
875
|
+
var fromCode = from.charCodeAt(fromStart + i);
|
|
876
|
+
var toCode = to.charCodeAt(toStart + i);
|
|
877
|
+
if (fromCode !== toCode)
|
|
878
|
+
break;
|
|
879
|
+
else if (fromCode === 47 /*/*/)
|
|
880
|
+
lastCommonSep = i;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
var out = '';
|
|
884
|
+
// Generate the relative path based on the path difference between `to`
|
|
885
|
+
// and `from`
|
|
886
|
+
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
887
|
+
if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
|
|
888
|
+
if (out.length === 0)
|
|
889
|
+
out += '..';
|
|
890
|
+
else
|
|
891
|
+
out += '/..';
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// Lastly, append the rest of the destination (`to`) path that comes after
|
|
896
|
+
// the common path parts
|
|
897
|
+
if (out.length > 0)
|
|
898
|
+
return out + to.slice(toStart + lastCommonSep);
|
|
899
|
+
else {
|
|
900
|
+
toStart += lastCommonSep;
|
|
901
|
+
if (to.charCodeAt(toStart) === 47 /*/*/)
|
|
902
|
+
++toStart;
|
|
903
|
+
return to.slice(toStart);
|
|
904
|
+
}
|
|
905
|
+
},
|
|
906
|
+
|
|
907
|
+
_makeLong: function _makeLong(path) {
|
|
908
|
+
return path;
|
|
909
|
+
},
|
|
910
|
+
|
|
911
|
+
dirname: function dirname(path) {
|
|
912
|
+
assertPath(path);
|
|
913
|
+
if (path.length === 0) return '.';
|
|
914
|
+
var code = path.charCodeAt(0);
|
|
915
|
+
var hasRoot = code === 47 /*/*/;
|
|
916
|
+
var end = -1;
|
|
917
|
+
var matchedSlash = true;
|
|
918
|
+
for (var i = path.length - 1; i >= 1; --i) {
|
|
919
|
+
code = path.charCodeAt(i);
|
|
920
|
+
if (code === 47 /*/*/) {
|
|
921
|
+
if (!matchedSlash) {
|
|
922
|
+
end = i;
|
|
923
|
+
break;
|
|
924
|
+
}
|
|
925
|
+
} else {
|
|
926
|
+
// We saw the first non-path separator
|
|
927
|
+
matchedSlash = false;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
if (end === -1) return hasRoot ? '/' : '.';
|
|
932
|
+
if (hasRoot && end === 1) return '//';
|
|
933
|
+
return path.slice(0, end);
|
|
934
|
+
},
|
|
935
|
+
|
|
936
|
+
basename: function basename(path, ext) {
|
|
937
|
+
if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
|
|
938
|
+
assertPath(path);
|
|
939
|
+
|
|
940
|
+
var start = 0;
|
|
941
|
+
var end = -1;
|
|
942
|
+
var matchedSlash = true;
|
|
943
|
+
var i;
|
|
944
|
+
|
|
945
|
+
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
946
|
+
if (ext.length === path.length && ext === path) return '';
|
|
947
|
+
var extIdx = ext.length - 1;
|
|
948
|
+
var firstNonSlashEnd = -1;
|
|
949
|
+
for (i = path.length - 1; i >= 0; --i) {
|
|
950
|
+
var code = path.charCodeAt(i);
|
|
951
|
+
if (code === 47 /*/*/) {
|
|
952
|
+
// If we reached a path separator that was not part of a set of path
|
|
953
|
+
// separators at the end of the string, stop now
|
|
954
|
+
if (!matchedSlash) {
|
|
955
|
+
start = i + 1;
|
|
956
|
+
break;
|
|
957
|
+
}
|
|
958
|
+
} else {
|
|
959
|
+
if (firstNonSlashEnd === -1) {
|
|
960
|
+
// We saw the first non-path separator, remember this index in case
|
|
961
|
+
// we need it if the extension ends up not matching
|
|
962
|
+
matchedSlash = false;
|
|
963
|
+
firstNonSlashEnd = i + 1;
|
|
964
|
+
}
|
|
965
|
+
if (extIdx >= 0) {
|
|
966
|
+
// Try to match the explicit extension
|
|
967
|
+
if (code === ext.charCodeAt(extIdx)) {
|
|
968
|
+
if (--extIdx === -1) {
|
|
969
|
+
// We matched the extension, so mark this as the end of our path
|
|
970
|
+
// component
|
|
971
|
+
end = i;
|
|
972
|
+
}
|
|
973
|
+
} else {
|
|
974
|
+
// Extension does not match, so our result is the entire path
|
|
975
|
+
// component
|
|
976
|
+
extIdx = -1;
|
|
977
|
+
end = firstNonSlashEnd;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
|
|
984
|
+
return path.slice(start, end);
|
|
985
|
+
} else {
|
|
986
|
+
for (i = path.length - 1; i >= 0; --i) {
|
|
987
|
+
if (path.charCodeAt(i) === 47 /*/*/) {
|
|
988
|
+
// If we reached a path separator that was not part of a set of path
|
|
989
|
+
// separators at the end of the string, stop now
|
|
990
|
+
if (!matchedSlash) {
|
|
991
|
+
start = i + 1;
|
|
992
|
+
break;
|
|
993
|
+
}
|
|
994
|
+
} else if (end === -1) {
|
|
995
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
996
|
+
// path component
|
|
997
|
+
matchedSlash = false;
|
|
998
|
+
end = i + 1;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
if (end === -1) return '';
|
|
1003
|
+
return path.slice(start, end);
|
|
1004
|
+
}
|
|
1005
|
+
},
|
|
1006
|
+
|
|
1007
|
+
extname: function extname(path) {
|
|
1008
|
+
assertPath(path);
|
|
1009
|
+
var startDot = -1;
|
|
1010
|
+
var startPart = 0;
|
|
1011
|
+
var end = -1;
|
|
1012
|
+
var matchedSlash = true;
|
|
1013
|
+
// Track the state of characters (if any) we see before our first dot and
|
|
1014
|
+
// after any path separator we find
|
|
1015
|
+
var preDotState = 0;
|
|
1016
|
+
for (var i = path.length - 1; i >= 0; --i) {
|
|
1017
|
+
var code = path.charCodeAt(i);
|
|
1018
|
+
if (code === 47 /*/*/) {
|
|
1019
|
+
// If we reached a path separator that was not part of a set of path
|
|
1020
|
+
// separators at the end of the string, stop now
|
|
1021
|
+
if (!matchedSlash) {
|
|
1022
|
+
startPart = i + 1;
|
|
1023
|
+
break;
|
|
1024
|
+
}
|
|
1025
|
+
continue;
|
|
1026
|
+
}
|
|
1027
|
+
if (end === -1) {
|
|
1028
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
1029
|
+
// extension
|
|
1030
|
+
matchedSlash = false;
|
|
1031
|
+
end = i + 1;
|
|
1032
|
+
}
|
|
1033
|
+
if (code === 46 /*.*/) {
|
|
1034
|
+
// If this is our first dot, mark it as the start of our extension
|
|
1035
|
+
if (startDot === -1)
|
|
1036
|
+
startDot = i;
|
|
1037
|
+
else if (preDotState !== 1)
|
|
1038
|
+
preDotState = 1;
|
|
1039
|
+
} else if (startDot !== -1) {
|
|
1040
|
+
// We saw a non-dot and non-path separator before our dot, so we should
|
|
1041
|
+
// have a good chance at having a non-empty extension
|
|
1042
|
+
preDotState = -1;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
if (startDot === -1 || end === -1 ||
|
|
1047
|
+
// We saw a non-dot character immediately before the dot
|
|
1048
|
+
preDotState === 0 ||
|
|
1049
|
+
// The (right-most) trimmed path component is exactly '..'
|
|
1050
|
+
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
1051
|
+
return '';
|
|
1052
|
+
}
|
|
1053
|
+
return path.slice(startDot, end);
|
|
1054
|
+
},
|
|
1055
|
+
|
|
1056
|
+
format: function format(pathObject) {
|
|
1057
|
+
if (pathObject === null || typeof pathObject !== 'object') {
|
|
1058
|
+
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
1059
|
+
}
|
|
1060
|
+
return _format('/', pathObject);
|
|
1061
|
+
},
|
|
1062
|
+
|
|
1063
|
+
parse: function parse(path) {
|
|
1064
|
+
assertPath(path);
|
|
1065
|
+
|
|
1066
|
+
var ret = { root: '', dir: '', base: '', ext: '', name: '' };
|
|
1067
|
+
if (path.length === 0) return ret;
|
|
1068
|
+
var code = path.charCodeAt(0);
|
|
1069
|
+
var isAbsolute = code === 47 /*/*/;
|
|
1070
|
+
var start;
|
|
1071
|
+
if (isAbsolute) {
|
|
1072
|
+
ret.root = '/';
|
|
1073
|
+
start = 1;
|
|
1074
|
+
} else {
|
|
1075
|
+
start = 0;
|
|
1076
|
+
}
|
|
1077
|
+
var startDot = -1;
|
|
1078
|
+
var startPart = 0;
|
|
1079
|
+
var end = -1;
|
|
1080
|
+
var matchedSlash = true;
|
|
1081
|
+
var i = path.length - 1;
|
|
1082
|
+
|
|
1083
|
+
// Track the state of characters (if any) we see before our first dot and
|
|
1084
|
+
// after any path separator we find
|
|
1085
|
+
var preDotState = 0;
|
|
1086
|
+
|
|
1087
|
+
// Get non-dir info
|
|
1088
|
+
for (; i >= start; --i) {
|
|
1089
|
+
code = path.charCodeAt(i);
|
|
1090
|
+
if (code === 47 /*/*/) {
|
|
1091
|
+
// If we reached a path separator that was not part of a set of path
|
|
1092
|
+
// separators at the end of the string, stop now
|
|
1093
|
+
if (!matchedSlash) {
|
|
1094
|
+
startPart = i + 1;
|
|
1095
|
+
break;
|
|
1096
|
+
}
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
if (end === -1) {
|
|
1100
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
1101
|
+
// extension
|
|
1102
|
+
matchedSlash = false;
|
|
1103
|
+
end = i + 1;
|
|
1104
|
+
}
|
|
1105
|
+
if (code === 46 /*.*/) {
|
|
1106
|
+
// If this is our first dot, mark it as the start of our extension
|
|
1107
|
+
if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
|
|
1108
|
+
} else if (startDot !== -1) {
|
|
1109
|
+
// We saw a non-dot and non-path separator before our dot, so we should
|
|
1110
|
+
// have a good chance at having a non-empty extension
|
|
1111
|
+
preDotState = -1;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
if (startDot === -1 || end === -1 ||
|
|
1116
|
+
// We saw a non-dot character immediately before the dot
|
|
1117
|
+
preDotState === 0 ||
|
|
1118
|
+
// The (right-most) trimmed path component is exactly '..'
|
|
1119
|
+
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
1120
|
+
if (end !== -1) {
|
|
1121
|
+
if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
|
|
1122
|
+
}
|
|
1123
|
+
} else {
|
|
1124
|
+
if (startPart === 0 && isAbsolute) {
|
|
1125
|
+
ret.name = path.slice(1, startDot);
|
|
1126
|
+
ret.base = path.slice(1, end);
|
|
1127
|
+
} else {
|
|
1128
|
+
ret.name = path.slice(startPart, startDot);
|
|
1129
|
+
ret.base = path.slice(startPart, end);
|
|
1130
|
+
}
|
|
1131
|
+
ret.ext = path.slice(startDot, end);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
|
|
1135
|
+
|
|
1136
|
+
return ret;
|
|
1137
|
+
},
|
|
1138
|
+
|
|
1139
|
+
sep: '/',
|
|
1140
|
+
delimiter: ':',
|
|
1141
|
+
win32: null,
|
|
1142
|
+
posix: null
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
posix.posix = posix;
|
|
1146
|
+
|
|
1147
|
+
var pathBrowserify = posix;
|
|
1148
|
+
|
|
648
1149
|
function ensure_list(obj) {
|
|
649
1150
|
const objArray = Array.isArray(obj) ? obj : [obj];
|
|
650
1151
|
return objArray;
|
|
@@ -1267,28 +1768,28 @@ function getAbsolutePath() {
|
|
|
1267
1768
|
function get_dirname(filePath) {
|
|
1268
1769
|
if (!filePath)
|
|
1269
1770
|
return '';
|
|
1270
|
-
return
|
|
1771
|
+
return pathBrowserify.dirname(filePath);
|
|
1271
1772
|
}
|
|
1272
1773
|
function get_basename(filePath) {
|
|
1273
1774
|
if (!filePath)
|
|
1274
1775
|
return '';
|
|
1275
|
-
return
|
|
1776
|
+
return pathBrowserify.basename(filePath);
|
|
1276
1777
|
}
|
|
1277
1778
|
function get_filename(file_path) {
|
|
1278
|
-
const ext =
|
|
1279
|
-
return
|
|
1779
|
+
const ext = pathBrowserify.extname(file_path);
|
|
1780
|
+
return pathBrowserify.basename(file_path, ext);
|
|
1280
1781
|
}
|
|
1281
1782
|
function get_extname(filePath) {
|
|
1282
1783
|
if (!filePath)
|
|
1283
1784
|
return '';
|
|
1284
|
-
return
|
|
1785
|
+
return pathBrowserify.extname(filePath);
|
|
1285
1786
|
}
|
|
1286
1787
|
function get_splitext(filePath) {
|
|
1287
1788
|
if (!filePath)
|
|
1288
1789
|
return { filename: '', extname: '' };
|
|
1289
|
-
const ext =
|
|
1790
|
+
const ext = pathBrowserify.extname(filePath);
|
|
1290
1791
|
// Get the basename without the extension
|
|
1291
|
-
const filename =
|
|
1792
|
+
const filename = pathBrowserify.basename(filePath, ext);
|
|
1292
1793
|
return { filename, ext };
|
|
1293
1794
|
}
|
|
1294
1795
|
/**
|
|
@@ -1346,11 +1847,11 @@ function sanitizeFilename(filename) {
|
|
|
1346
1847
|
.replace(/^-|-$/, ''); // Remove leading/trailing hyphens
|
|
1347
1848
|
}
|
|
1348
1849
|
function get_relative_path(directory, fullPath) {
|
|
1349
|
-
return
|
|
1850
|
+
return pathBrowserify.relative(directory, fullPath);
|
|
1350
1851
|
}
|
|
1351
1852
|
// Safer resolver that strips .. at the front only, but prefer server-side checks.
|
|
1352
1853
|
function get_safe_path(p) {
|
|
1353
|
-
return
|
|
1854
|
+
return pathBrowserify.normalize(p).replace(/^(\.\.[/\\])+/, '');
|
|
1354
1855
|
}
|
|
1355
1856
|
function make_sanitized_path(...paths) {
|
|
1356
1857
|
let real_path = '';
|