MCPcopy
hub / github.com/htmlhint/HTMLHint / parseGlob

Function parseGlob

src/cli/parse-glob.ts:3–36  ·  view source on GitHub ↗
(target: string)

Source from the content-addressed store, hash-verified

1import * as isGlob from 'is-glob'
2
3export function parseGlob(target: string): {
4 base: string
5 glob: string
6 is: {
7 glob: boolean
8 }
9 path: {
10 basename: string
11 }
12} {
13 const recursiveTokenIndex = Math.max(
14 target.indexOf('**/'),
15 target.indexOf('**\\')
16 )
17 const lastSlashIndex = Math.max(
18 target.lastIndexOf('/'),
19 target.lastIndexOf('\\')
20 )
21 const baseGlobSepIndex =
22 recursiveTokenIndex >= 0 ? recursiveTokenIndex : Math.max(lastSlashIndex, 0)
23
24 return {
25 base: target.substring(0, baseGlobSepIndex).replace(/[/\\]$/, '') || '.',
26 glob: target.substring(baseGlobSepIndex).replace(/^[/\\]/, ''),
27 is: {
28 glob: isGlob(target),
29 },
30 path: {
31 basename: target
32 .substring(Math.max(lastSlashIndex, 0))
33 .replace(/^[/\\]/, ''),
34 },
35 }
36}

Callers 2

getGlobInfoFunction · 0.90
parse-glob.spec.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected