@putkoff/abstract-utilities 0.1.242 → 0.1.243

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/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { useCallback, useEffect, useRef, useState } from 'react';
2
- import path$1 from 'path';
2
+ import path$2 from 'path';
3
+ import * as path$1 from 'path-browserify';
3
4
  import * as fs from 'node:fs';
4
5
  import * as fsp from 'node:fs/promises';
5
6
  import * as path from 'node:path';
@@ -603,7 +604,7 @@ function get_full_path(partial_path, parent_dir = null) {
603
604
  if (typeof partial_path !== 'string') {
604
605
  throw new Error('partial_path must be a string');
605
606
  }
606
- if (path$1.isAbsolute(partial_path)) {
607
+ if (path$2.isAbsolute(partial_path)) {
607
608
  return partial_path;
608
609
  }
609
610
  return urlJoin(parent_dir, partial_path);
@@ -618,7 +619,7 @@ function path_to_url(filePath, all_paths) {
618
619
  }
619
620
  for (const key in all_paths) {
620
621
  const mapping = all_paths[key];
621
- const normalizedBase = path$1.normalize(mapping.path);
622
+ const normalizedBase = path$2.normalize(mapping.path);
622
623
  if (filePath.startsWith(normalizedBase)) {
623
624
  const relativePath = filePath.substring(normalizedBase.length);
624
625
  return urlJoin(mapping.url, relativePath.replace(/\\/g, '/'));
@@ -644,508 +645,6 @@ function url_to_path(urlStr, all_paths) {
644
645
  return null;
645
646
  }
646
647
 
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
-
1149
648
  function ensure_list(obj) {
1150
649
  const objArray = Array.isArray(obj) ? obj : [obj];
1151
650
  return objArray;
@@ -1768,28 +1267,28 @@ function getAbsolutePath() {
1768
1267
  function get_dirname(filePath) {
1769
1268
  if (!filePath)
1770
1269
  return '';
1771
- return pathBrowserify.dirname(filePath);
1270
+ return path$1.dirname(filePath);
1772
1271
  }
1773
1272
  function get_basename(filePath) {
1774
1273
  if (!filePath)
1775
1274
  return '';
1776
- return pathBrowserify.basename(filePath);
1275
+ return path$1.basename(filePath);
1777
1276
  }
1778
1277
  function get_filename(file_path) {
1779
- const ext = pathBrowserify.extname(file_path);
1780
- return pathBrowserify.basename(file_path, ext);
1278
+ const ext = path$1.extname(file_path);
1279
+ return path$1.basename(file_path, ext);
1781
1280
  }
1782
1281
  function get_extname(filePath) {
1783
1282
  if (!filePath)
1784
1283
  return '';
1785
- return pathBrowserify.extname(filePath);
1284
+ return path$1.extname(filePath);
1786
1285
  }
1787
1286
  function get_splitext(filePath) {
1788
1287
  if (!filePath)
1789
1288
  return { filename: '', extname: '' };
1790
- const ext = pathBrowserify.extname(filePath);
1289
+ const ext = path$1.extname(filePath);
1791
1290
  // Get the basename without the extension
1792
- const filename = pathBrowserify.basename(filePath, ext);
1291
+ const filename = path$1.basename(filePath, ext);
1793
1292
  return { filename, ext };
1794
1293
  }
1795
1294
  /**
@@ -1847,11 +1346,11 @@ function sanitizeFilename(filename) {
1847
1346
  .replace(/^-|-$/, ''); // Remove leading/trailing hyphens
1848
1347
  }
1849
1348
  function get_relative_path(directory, fullPath) {
1850
- return pathBrowserify.relative(directory, fullPath);
1349
+ return path$1.relative(directory, fullPath);
1851
1350
  }
1852
1351
  // Safer resolver that strips .. at the front only, but prefer server-side checks.
1853
1352
  function get_safe_path(p) {
1854
- return pathBrowserify.normalize(p).replace(/^(\.\.[/\\])+/, '');
1353
+ return path$1.normalize(p).replace(/^(\.\.[/\\])+/, '');
1855
1354
  }
1856
1355
  function make_sanitized_path(...paths) {
1857
1356
  let real_path = '';