File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
javascript/ql/lib/semmle/javascript Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,21 @@ class StringAsPath extends string {
135135 bindingset [ this ]
136136 string getExtension ( ) { result = this .regexpCapture ( pathRegex ( ) , 4 ) }
137137
138+ /**
139+ * Holds if this path is relative, in the sense that it should be resolved relative to its enclosing folder.
140+ */
141+ bindingset [ this ]
142+ pragma [ inline_late]
143+ predicate isRelativePath ( ) { this .regexpMatch ( "\\.\\.?(?:[/\\\\].*)?" ) }
144+
145+ /**
146+ * Gets the NPM package name from the beginning of the given import path, e.g.
147+ * gets `foo` from `foo/bar`, and `@example/foo` from `@example/foo/bar`.
148+ */
149+ bindingset [ this ]
150+ string getPackagePrefix ( ) {
151+ result = this .regexpFind ( "^(@[^/\\\\]+[/\\\\])?[^@./\\\\][^/\\\\]*" , _, _)
152+ }
138153}
139154
140155/**
You can’t perform that action at this time.
0 commit comments