@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/cjs/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var path = require('path');
|
|
5
|
-
var path$2 = require('path-browserify');
|
|
6
5
|
var fs = require('node:fs');
|
|
7
6
|
var fsp = require('node:fs/promises');
|
|
8
7
|
var path$1 = require('node:path');
|
|
@@ -26,7 +25,6 @@ function _interopNamespaceDefault(e) {
|
|
|
26
25
|
return Object.freeze(n);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path$2);
|
|
30
28
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
31
29
|
var fsp__namespace = /*#__PURE__*/_interopNamespaceDefault(fsp);
|
|
32
30
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
@@ -670,6 +668,508 @@ function url_to_path(urlStr, all_paths) {
|
|
|
670
668
|
return null;
|
|
671
669
|
}
|
|
672
670
|
|
|
671
|
+
function assertPath(path) {
|
|
672
|
+
if (typeof path !== 'string') {
|
|
673
|
+
throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// Resolves . and .. elements in a path with directory names
|
|
678
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
679
|
+
var res = '';
|
|
680
|
+
var lastSegmentLength = 0;
|
|
681
|
+
var lastSlash = -1;
|
|
682
|
+
var dots = 0;
|
|
683
|
+
var code;
|
|
684
|
+
for (var i = 0; i <= path.length; ++i) {
|
|
685
|
+
if (i < path.length)
|
|
686
|
+
code = path.charCodeAt(i);
|
|
687
|
+
else if (code === 47 /*/*/)
|
|
688
|
+
break;
|
|
689
|
+
else
|
|
690
|
+
code = 47 /*/*/;
|
|
691
|
+
if (code === 47 /*/*/) {
|
|
692
|
+
if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {
|
|
693
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
|
|
694
|
+
if (res.length > 2) {
|
|
695
|
+
var lastSlashIndex = res.lastIndexOf('/');
|
|
696
|
+
if (lastSlashIndex !== res.length - 1) {
|
|
697
|
+
if (lastSlashIndex === -1) {
|
|
698
|
+
res = '';
|
|
699
|
+
lastSegmentLength = 0;
|
|
700
|
+
} else {
|
|
701
|
+
res = res.slice(0, lastSlashIndex);
|
|
702
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
|
|
703
|
+
}
|
|
704
|
+
lastSlash = i;
|
|
705
|
+
dots = 0;
|
|
706
|
+
continue;
|
|
707
|
+
}
|
|
708
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
709
|
+
res = '';
|
|
710
|
+
lastSegmentLength = 0;
|
|
711
|
+
lastSlash = i;
|
|
712
|
+
dots = 0;
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
if (allowAboveRoot) {
|
|
717
|
+
if (res.length > 0)
|
|
718
|
+
res += '/..';
|
|
719
|
+
else
|
|
720
|
+
res = '..';
|
|
721
|
+
lastSegmentLength = 2;
|
|
722
|
+
}
|
|
723
|
+
} else {
|
|
724
|
+
if (res.length > 0)
|
|
725
|
+
res += '/' + path.slice(lastSlash + 1, i);
|
|
726
|
+
else
|
|
727
|
+
res = path.slice(lastSlash + 1, i);
|
|
728
|
+
lastSegmentLength = i - lastSlash - 1;
|
|
729
|
+
}
|
|
730
|
+
lastSlash = i;
|
|
731
|
+
dots = 0;
|
|
732
|
+
} else if (code === 46 /*.*/ && dots !== -1) {
|
|
733
|
+
++dots;
|
|
734
|
+
} else {
|
|
735
|
+
dots = -1;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return res;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
function _format(sep, pathObject) {
|
|
742
|
+
var dir = pathObject.dir || pathObject.root;
|
|
743
|
+
var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
|
|
744
|
+
if (!dir) {
|
|
745
|
+
return base;
|
|
746
|
+
}
|
|
747
|
+
if (dir === pathObject.root) {
|
|
748
|
+
return dir + base;
|
|
749
|
+
}
|
|
750
|
+
return dir + sep + base;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
var posix = {
|
|
754
|
+
// path.resolve([from ...], to)
|
|
755
|
+
resolve: function resolve() {
|
|
756
|
+
var resolvedPath = '';
|
|
757
|
+
var resolvedAbsolute = false;
|
|
758
|
+
var cwd;
|
|
759
|
+
|
|
760
|
+
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
761
|
+
var path;
|
|
762
|
+
if (i >= 0)
|
|
763
|
+
path = arguments[i];
|
|
764
|
+
else {
|
|
765
|
+
if (cwd === undefined)
|
|
766
|
+
cwd = process.cwd();
|
|
767
|
+
path = cwd;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
assertPath(path);
|
|
771
|
+
|
|
772
|
+
// Skip empty entries
|
|
773
|
+
if (path.length === 0) {
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
resolvedPath = path + '/' + resolvedPath;
|
|
778
|
+
resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// At this point the path should be resolved to a full absolute path, but
|
|
782
|
+
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
783
|
+
|
|
784
|
+
// Normalize the path
|
|
785
|
+
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
786
|
+
|
|
787
|
+
if (resolvedAbsolute) {
|
|
788
|
+
if (resolvedPath.length > 0)
|
|
789
|
+
return '/' + resolvedPath;
|
|
790
|
+
else
|
|
791
|
+
return '/';
|
|
792
|
+
} else if (resolvedPath.length > 0) {
|
|
793
|
+
return resolvedPath;
|
|
794
|
+
} else {
|
|
795
|
+
return '.';
|
|
796
|
+
}
|
|
797
|
+
},
|
|
798
|
+
|
|
799
|
+
normalize: function normalize(path) {
|
|
800
|
+
assertPath(path);
|
|
801
|
+
|
|
802
|
+
if (path.length === 0) return '.';
|
|
803
|
+
|
|
804
|
+
var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
|
|
805
|
+
var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
|
|
806
|
+
|
|
807
|
+
// Normalize the path
|
|
808
|
+
path = normalizeStringPosix(path, !isAbsolute);
|
|
809
|
+
|
|
810
|
+
if (path.length === 0 && !isAbsolute) path = '.';
|
|
811
|
+
if (path.length > 0 && trailingSeparator) path += '/';
|
|
812
|
+
|
|
813
|
+
if (isAbsolute) return '/' + path;
|
|
814
|
+
return path;
|
|
815
|
+
},
|
|
816
|
+
|
|
817
|
+
isAbsolute: function isAbsolute(path) {
|
|
818
|
+
assertPath(path);
|
|
819
|
+
return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
|
|
820
|
+
},
|
|
821
|
+
|
|
822
|
+
join: function join() {
|
|
823
|
+
if (arguments.length === 0)
|
|
824
|
+
return '.';
|
|
825
|
+
var joined;
|
|
826
|
+
for (var i = 0; i < arguments.length; ++i) {
|
|
827
|
+
var arg = arguments[i];
|
|
828
|
+
assertPath(arg);
|
|
829
|
+
if (arg.length > 0) {
|
|
830
|
+
if (joined === undefined)
|
|
831
|
+
joined = arg;
|
|
832
|
+
else
|
|
833
|
+
joined += '/' + arg;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
if (joined === undefined)
|
|
837
|
+
return '.';
|
|
838
|
+
return posix.normalize(joined);
|
|
839
|
+
},
|
|
840
|
+
|
|
841
|
+
relative: function relative(from, to) {
|
|
842
|
+
assertPath(from);
|
|
843
|
+
assertPath(to);
|
|
844
|
+
|
|
845
|
+
if (from === to) return '';
|
|
846
|
+
|
|
847
|
+
from = posix.resolve(from);
|
|
848
|
+
to = posix.resolve(to);
|
|
849
|
+
|
|
850
|
+
if (from === to) return '';
|
|
851
|
+
|
|
852
|
+
// Trim any leading backslashes
|
|
853
|
+
var fromStart = 1;
|
|
854
|
+
for (; fromStart < from.length; ++fromStart) {
|
|
855
|
+
if (from.charCodeAt(fromStart) !== 47 /*/*/)
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
858
|
+
var fromEnd = from.length;
|
|
859
|
+
var fromLen = fromEnd - fromStart;
|
|
860
|
+
|
|
861
|
+
// Trim any leading backslashes
|
|
862
|
+
var toStart = 1;
|
|
863
|
+
for (; toStart < to.length; ++toStart) {
|
|
864
|
+
if (to.charCodeAt(toStart) !== 47 /*/*/)
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
var toEnd = to.length;
|
|
868
|
+
var toLen = toEnd - toStart;
|
|
869
|
+
|
|
870
|
+
// Compare paths to find the longest common path from root
|
|
871
|
+
var length = fromLen < toLen ? fromLen : toLen;
|
|
872
|
+
var lastCommonSep = -1;
|
|
873
|
+
var i = 0;
|
|
874
|
+
for (; i <= length; ++i) {
|
|
875
|
+
if (i === length) {
|
|
876
|
+
if (toLen > length) {
|
|
877
|
+
if (to.charCodeAt(toStart + i) === 47 /*/*/) {
|
|
878
|
+
// We get here if `from` is the exact base path for `to`.
|
|
879
|
+
// For example: from='/foo/bar'; to='/foo/bar/baz'
|
|
880
|
+
return to.slice(toStart + i + 1);
|
|
881
|
+
} else if (i === 0) {
|
|
882
|
+
// We get here if `from` is the root
|
|
883
|
+
// For example: from='/'; to='/foo'
|
|
884
|
+
return to.slice(toStart + i);
|
|
885
|
+
}
|
|
886
|
+
} else if (fromLen > length) {
|
|
887
|
+
if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
|
|
888
|
+
// We get here if `to` is the exact base path for `from`.
|
|
889
|
+
// For example: from='/foo/bar/baz'; to='/foo/bar'
|
|
890
|
+
lastCommonSep = i;
|
|
891
|
+
} else if (i === 0) {
|
|
892
|
+
// We get here if `to` is the root.
|
|
893
|
+
// For example: from='/foo'; to='/'
|
|
894
|
+
lastCommonSep = 0;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
var fromCode = from.charCodeAt(fromStart + i);
|
|
900
|
+
var toCode = to.charCodeAt(toStart + i);
|
|
901
|
+
if (fromCode !== toCode)
|
|
902
|
+
break;
|
|
903
|
+
else if (fromCode === 47 /*/*/)
|
|
904
|
+
lastCommonSep = i;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
var out = '';
|
|
908
|
+
// Generate the relative path based on the path difference between `to`
|
|
909
|
+
// and `from`
|
|
910
|
+
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
911
|
+
if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
|
|
912
|
+
if (out.length === 0)
|
|
913
|
+
out += '..';
|
|
914
|
+
else
|
|
915
|
+
out += '/..';
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// Lastly, append the rest of the destination (`to`) path that comes after
|
|
920
|
+
// the common path parts
|
|
921
|
+
if (out.length > 0)
|
|
922
|
+
return out + to.slice(toStart + lastCommonSep);
|
|
923
|
+
else {
|
|
924
|
+
toStart += lastCommonSep;
|
|
925
|
+
if (to.charCodeAt(toStart) === 47 /*/*/)
|
|
926
|
+
++toStart;
|
|
927
|
+
return to.slice(toStart);
|
|
928
|
+
}
|
|
929
|
+
},
|
|
930
|
+
|
|
931
|
+
_makeLong: function _makeLong(path) {
|
|
932
|
+
return path;
|
|
933
|
+
},
|
|
934
|
+
|
|
935
|
+
dirname: function dirname(path) {
|
|
936
|
+
assertPath(path);
|
|
937
|
+
if (path.length === 0) return '.';
|
|
938
|
+
var code = path.charCodeAt(0);
|
|
939
|
+
var hasRoot = code === 47 /*/*/;
|
|
940
|
+
var end = -1;
|
|
941
|
+
var matchedSlash = true;
|
|
942
|
+
for (var i = path.length - 1; i >= 1; --i) {
|
|
943
|
+
code = path.charCodeAt(i);
|
|
944
|
+
if (code === 47 /*/*/) {
|
|
945
|
+
if (!matchedSlash) {
|
|
946
|
+
end = i;
|
|
947
|
+
break;
|
|
948
|
+
}
|
|
949
|
+
} else {
|
|
950
|
+
// We saw the first non-path separator
|
|
951
|
+
matchedSlash = false;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
if (end === -1) return hasRoot ? '/' : '.';
|
|
956
|
+
if (hasRoot && end === 1) return '//';
|
|
957
|
+
return path.slice(0, end);
|
|
958
|
+
},
|
|
959
|
+
|
|
960
|
+
basename: function basename(path, ext) {
|
|
961
|
+
if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
|
|
962
|
+
assertPath(path);
|
|
963
|
+
|
|
964
|
+
var start = 0;
|
|
965
|
+
var end = -1;
|
|
966
|
+
var matchedSlash = true;
|
|
967
|
+
var i;
|
|
968
|
+
|
|
969
|
+
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
970
|
+
if (ext.length === path.length && ext === path) return '';
|
|
971
|
+
var extIdx = ext.length - 1;
|
|
972
|
+
var firstNonSlashEnd = -1;
|
|
973
|
+
for (i = path.length - 1; i >= 0; --i) {
|
|
974
|
+
var code = path.charCodeAt(i);
|
|
975
|
+
if (code === 47 /*/*/) {
|
|
976
|
+
// If we reached a path separator that was not part of a set of path
|
|
977
|
+
// separators at the end of the string, stop now
|
|
978
|
+
if (!matchedSlash) {
|
|
979
|
+
start = i + 1;
|
|
980
|
+
break;
|
|
981
|
+
}
|
|
982
|
+
} else {
|
|
983
|
+
if (firstNonSlashEnd === -1) {
|
|
984
|
+
// We saw the first non-path separator, remember this index in case
|
|
985
|
+
// we need it if the extension ends up not matching
|
|
986
|
+
matchedSlash = false;
|
|
987
|
+
firstNonSlashEnd = i + 1;
|
|
988
|
+
}
|
|
989
|
+
if (extIdx >= 0) {
|
|
990
|
+
// Try to match the explicit extension
|
|
991
|
+
if (code === ext.charCodeAt(extIdx)) {
|
|
992
|
+
if (--extIdx === -1) {
|
|
993
|
+
// We matched the extension, so mark this as the end of our path
|
|
994
|
+
// component
|
|
995
|
+
end = i;
|
|
996
|
+
}
|
|
997
|
+
} else {
|
|
998
|
+
// Extension does not match, so our result is the entire path
|
|
999
|
+
// component
|
|
1000
|
+
extIdx = -1;
|
|
1001
|
+
end = firstNonSlashEnd;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
|
|
1008
|
+
return path.slice(start, end);
|
|
1009
|
+
} else {
|
|
1010
|
+
for (i = path.length - 1; i >= 0; --i) {
|
|
1011
|
+
if (path.charCodeAt(i) === 47 /*/*/) {
|
|
1012
|
+
// If we reached a path separator that was not part of a set of path
|
|
1013
|
+
// separators at the end of the string, stop now
|
|
1014
|
+
if (!matchedSlash) {
|
|
1015
|
+
start = i + 1;
|
|
1016
|
+
break;
|
|
1017
|
+
}
|
|
1018
|
+
} else if (end === -1) {
|
|
1019
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
1020
|
+
// path component
|
|
1021
|
+
matchedSlash = false;
|
|
1022
|
+
end = i + 1;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
if (end === -1) return '';
|
|
1027
|
+
return path.slice(start, end);
|
|
1028
|
+
}
|
|
1029
|
+
},
|
|
1030
|
+
|
|
1031
|
+
extname: function extname(path) {
|
|
1032
|
+
assertPath(path);
|
|
1033
|
+
var startDot = -1;
|
|
1034
|
+
var startPart = 0;
|
|
1035
|
+
var end = -1;
|
|
1036
|
+
var matchedSlash = true;
|
|
1037
|
+
// Track the state of characters (if any) we see before our first dot and
|
|
1038
|
+
// after any path separator we find
|
|
1039
|
+
var preDotState = 0;
|
|
1040
|
+
for (var i = path.length - 1; i >= 0; --i) {
|
|
1041
|
+
var code = path.charCodeAt(i);
|
|
1042
|
+
if (code === 47 /*/*/) {
|
|
1043
|
+
// If we reached a path separator that was not part of a set of path
|
|
1044
|
+
// separators at the end of the string, stop now
|
|
1045
|
+
if (!matchedSlash) {
|
|
1046
|
+
startPart = i + 1;
|
|
1047
|
+
break;
|
|
1048
|
+
}
|
|
1049
|
+
continue;
|
|
1050
|
+
}
|
|
1051
|
+
if (end === -1) {
|
|
1052
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
1053
|
+
// extension
|
|
1054
|
+
matchedSlash = false;
|
|
1055
|
+
end = i + 1;
|
|
1056
|
+
}
|
|
1057
|
+
if (code === 46 /*.*/) {
|
|
1058
|
+
// If this is our first dot, mark it as the start of our extension
|
|
1059
|
+
if (startDot === -1)
|
|
1060
|
+
startDot = i;
|
|
1061
|
+
else if (preDotState !== 1)
|
|
1062
|
+
preDotState = 1;
|
|
1063
|
+
} else if (startDot !== -1) {
|
|
1064
|
+
// We saw a non-dot and non-path separator before our dot, so we should
|
|
1065
|
+
// have a good chance at having a non-empty extension
|
|
1066
|
+
preDotState = -1;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
if (startDot === -1 || end === -1 ||
|
|
1071
|
+
// We saw a non-dot character immediately before the dot
|
|
1072
|
+
preDotState === 0 ||
|
|
1073
|
+
// The (right-most) trimmed path component is exactly '..'
|
|
1074
|
+
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
1075
|
+
return '';
|
|
1076
|
+
}
|
|
1077
|
+
return path.slice(startDot, end);
|
|
1078
|
+
},
|
|
1079
|
+
|
|
1080
|
+
format: function format(pathObject) {
|
|
1081
|
+
if (pathObject === null || typeof pathObject !== 'object') {
|
|
1082
|
+
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
1083
|
+
}
|
|
1084
|
+
return _format('/', pathObject);
|
|
1085
|
+
},
|
|
1086
|
+
|
|
1087
|
+
parse: function parse(path) {
|
|
1088
|
+
assertPath(path);
|
|
1089
|
+
|
|
1090
|
+
var ret = { root: '', dir: '', base: '', ext: '', name: '' };
|
|
1091
|
+
if (path.length === 0) return ret;
|
|
1092
|
+
var code = path.charCodeAt(0);
|
|
1093
|
+
var isAbsolute = code === 47 /*/*/;
|
|
1094
|
+
var start;
|
|
1095
|
+
if (isAbsolute) {
|
|
1096
|
+
ret.root = '/';
|
|
1097
|
+
start = 1;
|
|
1098
|
+
} else {
|
|
1099
|
+
start = 0;
|
|
1100
|
+
}
|
|
1101
|
+
var startDot = -1;
|
|
1102
|
+
var startPart = 0;
|
|
1103
|
+
var end = -1;
|
|
1104
|
+
var matchedSlash = true;
|
|
1105
|
+
var i = path.length - 1;
|
|
1106
|
+
|
|
1107
|
+
// Track the state of characters (if any) we see before our first dot and
|
|
1108
|
+
// after any path separator we find
|
|
1109
|
+
var preDotState = 0;
|
|
1110
|
+
|
|
1111
|
+
// Get non-dir info
|
|
1112
|
+
for (; i >= start; --i) {
|
|
1113
|
+
code = path.charCodeAt(i);
|
|
1114
|
+
if (code === 47 /*/*/) {
|
|
1115
|
+
// If we reached a path separator that was not part of a set of path
|
|
1116
|
+
// separators at the end of the string, stop now
|
|
1117
|
+
if (!matchedSlash) {
|
|
1118
|
+
startPart = i + 1;
|
|
1119
|
+
break;
|
|
1120
|
+
}
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
if (end === -1) {
|
|
1124
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
1125
|
+
// extension
|
|
1126
|
+
matchedSlash = false;
|
|
1127
|
+
end = i + 1;
|
|
1128
|
+
}
|
|
1129
|
+
if (code === 46 /*.*/) {
|
|
1130
|
+
// If this is our first dot, mark it as the start of our extension
|
|
1131
|
+
if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
|
|
1132
|
+
} else if (startDot !== -1) {
|
|
1133
|
+
// We saw a non-dot and non-path separator before our dot, so we should
|
|
1134
|
+
// have a good chance at having a non-empty extension
|
|
1135
|
+
preDotState = -1;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
if (startDot === -1 || end === -1 ||
|
|
1140
|
+
// We saw a non-dot character immediately before the dot
|
|
1141
|
+
preDotState === 0 ||
|
|
1142
|
+
// The (right-most) trimmed path component is exactly '..'
|
|
1143
|
+
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
1144
|
+
if (end !== -1) {
|
|
1145
|
+
if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
|
|
1146
|
+
}
|
|
1147
|
+
} else {
|
|
1148
|
+
if (startPart === 0 && isAbsolute) {
|
|
1149
|
+
ret.name = path.slice(1, startDot);
|
|
1150
|
+
ret.base = path.slice(1, end);
|
|
1151
|
+
} else {
|
|
1152
|
+
ret.name = path.slice(startPart, startDot);
|
|
1153
|
+
ret.base = path.slice(startPart, end);
|
|
1154
|
+
}
|
|
1155
|
+
ret.ext = path.slice(startDot, end);
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
|
|
1159
|
+
|
|
1160
|
+
return ret;
|
|
1161
|
+
},
|
|
1162
|
+
|
|
1163
|
+
sep: '/',
|
|
1164
|
+
delimiter: ':',
|
|
1165
|
+
win32: null,
|
|
1166
|
+
posix: null
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
posix.posix = posix;
|
|
1170
|
+
|
|
1171
|
+
var pathBrowserify = posix;
|
|
1172
|
+
|
|
673
1173
|
function ensure_list(obj) {
|
|
674
1174
|
const objArray = Array.isArray(obj) ? obj : [obj];
|
|
675
1175
|
return objArray;
|
|
@@ -1292,28 +1792,28 @@ function getAbsolutePath() {
|
|
|
1292
1792
|
function get_dirname(filePath) {
|
|
1293
1793
|
if (!filePath)
|
|
1294
1794
|
return '';
|
|
1295
|
-
return
|
|
1795
|
+
return pathBrowserify.dirname(filePath);
|
|
1296
1796
|
}
|
|
1297
1797
|
function get_basename(filePath) {
|
|
1298
1798
|
if (!filePath)
|
|
1299
1799
|
return '';
|
|
1300
|
-
return
|
|
1800
|
+
return pathBrowserify.basename(filePath);
|
|
1301
1801
|
}
|
|
1302
1802
|
function get_filename(file_path) {
|
|
1303
|
-
const ext =
|
|
1304
|
-
return
|
|
1803
|
+
const ext = pathBrowserify.extname(file_path);
|
|
1804
|
+
return pathBrowserify.basename(file_path, ext);
|
|
1305
1805
|
}
|
|
1306
1806
|
function get_extname(filePath) {
|
|
1307
1807
|
if (!filePath)
|
|
1308
1808
|
return '';
|
|
1309
|
-
return
|
|
1809
|
+
return pathBrowserify.extname(filePath);
|
|
1310
1810
|
}
|
|
1311
1811
|
function get_splitext(filePath) {
|
|
1312
1812
|
if (!filePath)
|
|
1313
1813
|
return { filename: '', extname: '' };
|
|
1314
|
-
const ext =
|
|
1814
|
+
const ext = pathBrowserify.extname(filePath);
|
|
1315
1815
|
// Get the basename without the extension
|
|
1316
|
-
const filename =
|
|
1816
|
+
const filename = pathBrowserify.basename(filePath, ext);
|
|
1317
1817
|
return { filename, ext };
|
|
1318
1818
|
}
|
|
1319
1819
|
/**
|
|
@@ -1371,11 +1871,11 @@ function sanitizeFilename(filename) {
|
|
|
1371
1871
|
.replace(/^-|-$/, ''); // Remove leading/trailing hyphens
|
|
1372
1872
|
}
|
|
1373
1873
|
function get_relative_path(directory, fullPath) {
|
|
1374
|
-
return
|
|
1874
|
+
return pathBrowserify.relative(directory, fullPath);
|
|
1375
1875
|
}
|
|
1376
1876
|
// Safer resolver that strips .. at the front only, but prefer server-side checks.
|
|
1377
1877
|
function get_safe_path(p) {
|
|
1378
|
-
return
|
|
1878
|
+
return pathBrowserify.normalize(p).replace(/^(\.\.[/\\])+/, '');
|
|
1379
1879
|
}
|
|
1380
1880
|
function make_sanitized_path(...paths) {
|
|
1381
1881
|
let real_path = '';
|