908
909
extname(path: string): string {
910
>
validateString(path, 'path');
path.ts
911
>
let start = 0;
912
>
let startDot = -1;
913
>
let startPart = 0;
914
>
let end = -1;
915
>
let matchedSlash = true;
916
>
// Track the state of characters (if any) we see before our first dot and
917
>
// after any path separator we find
918
>
let preDotState = 0;
919
>
920
>
// Check for a drive letter prefix so as not to mistake the following
921
>
// path separator as an extra separator at the end of the path that can be
922
>
// disregarded
923
>
924
>
if (path.length >= 2 &&
925
>
path.charCodeAt(1) === CHAR_COLON &&
926
>
isWindowsDeviceRoot(path.charCodeAt(0))) {
927
>
start = startPart = 2;
928
>
}
929
>
930
>
for (let i = path.length - 1; i >= start; --i) {
931
>
const code = path.charCodeAt(i);
932
>
if (isPathSeparator(code)) {
933
>
// If we reached a path separator that was not part of a set of path
934
>
// separators at the end of the string, stop now
935
>
if (!matchedSlash) {
936
>
startPart = i + 1;
937
>
break;
938
>
}
939
>
continue;
940
>
}
941
>
if (end === -1) {
942
>
// We saw the first non-path separator, mark this as the end of our
943
>
// extension
944
>
matchedSlash = false;
945
>
end = i + 1;
946
>
}
947
>
if (code === CHAR_DOT) {
948
>
// If this is our first dot, mark it as the start of our extension
949
>
if (startDot === -1) {
950
>
startDot = i;
951
>
}
952
>
else if (preDotState !== 1) {
953
>
preDotState = 1;
954
>
}
955
>
} else if (startDot !== -1) {
956
>
// We saw a non-dot and non-path separator before our dot, so we should
957
>
// have a good chance at having a non-empty extension
958
>
preDotState = -1;
959
>
}
960
>
}
961
>
962
>
if (startDot === -1 ||
963
>
end === -1 ||
964
>
// We saw a non-dot character immediately before the dot
965
>
preDotState === 0 ||
966
>
// The (right-most) trimmed path component is exactly '..'
967
>
(preDotState === 1 &&
968
>
startDot === end - 1 &&
969
>
startDot === startPart + 1)) {
970
>
return '';
971
>
}
972
>
return path.slice(startDot, end);
973
>
},
974
975
format: _format.bind(null, '\\'),