Skip to content

Commit 8369807

Browse files
committed
fixup
1 parent 31d8391 commit 8369807

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

javascript/ql/lib/semmle/javascript/Paths.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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
/**

0 commit comments

Comments
 (0)