MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getGlobBaseDirectory

Function getGlobBaseDirectory

src/utils/permissions/pathValidation.ts:57–74  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

55 * For example: "/path/to/*.txt" returns "/path/to"
56 */
57export function getGlobBaseDirectory(path: string): string {
58 const globMatch = path.match(GLOB_PATTERN_REGEX)
59 if (!globMatch || globMatch.index === undefined) {
60 return path
61 }
62
63 // Get everything before the first glob character
64 const beforeGlob = path.substring(0, globMatch.index)
65
66 // Find the last directory separator
67 const lastSepIndex =
68 getPlatform() === 'windows'
69 ? Math.max(beforeGlob.lastIndexOf('/'), beforeGlob.lastIndexOf('\\'))
70 : beforeGlob.lastIndexOf('/')
71 if (lastSepIndex === -1) return '.'
72
73 return beforeGlob.substring(0, lastSepIndex) || '/'
74}
75
76/**
77 * Expands tilde (~) at the start of a path to the user's home directory.

Callers 1

validateGlobPatternFunction · 0.70

Calls 2

getPlatformFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected