MCPcopy Create free account
hub / github.com/microsoft/typescript-go / ParseNodeModuleFromPath

Function ParseNodeModuleFromPath

internal/module/util.go:28–41  ·  view source on GitHub ↗
(resolved string, isFolder bool)

Source from the content-addressed store, hash-verified

26}
27
28func ParseNodeModuleFromPath(resolved string, isFolder bool) string {
29 path := tspath.NormalizePath(resolved)
30 idx := strings.LastIndex(path, "/node_modules/")
31 if idx == -1 {
32 return ""
33 }
34
35 indexAfterNodeModules := idx + len("/node_modules/")
36 indexAfterPackageName := moveToNextDirectorySeparatorIfAvailable(path, indexAfterNodeModules, isFolder)
37 if path[indexAfterNodeModules] == '@' {
38 indexAfterPackageName = moveToNextDirectorySeparatorIfAvailable(path, indexAfterPackageName, isFolder)
39 }
40 return path[:indexAfterPackageName]
41}
42
43func ParsePackageName(moduleName string) (packageName, rest string) {
44 idx := strings.Index(moduleName, "/")

Calls 3

NormalizePathFunction · 0.92
lenFunction · 0.85

Tested by 1