mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
JS: Add two more helpers to FilePath class
This commit is contained in:
@@ -135,6 +135,31 @@ class FilePath extends string {
|
||||
bindingset[this]
|
||||
string getExtension() { result = this.regexpCapture(pathRegex(), 4) }
|
||||
|
||||
/**
|
||||
* Holds if this is a relative path starting with an explicit `./` or similar syntax meaning it
|
||||
* must be resolved relative to its enclosing folder.
|
||||
*
|
||||
* Specifically this holds when the string is `.` or `..`, or starts with `./` or `../` or
|
||||
* `.\` or `..\`.
|
||||
*/
|
||||
bindingset[this]
|
||||
pragma[inline_late]
|
||||
predicate isDotRelativePath() { this.regexpMatch("\\.\\.?(?:[/\\\\].*)?") }
|
||||
|
||||
/**
|
||||
* Gets the NPM package name from the beginning of the given import path.
|
||||
*
|
||||
* Has no result for paths starting with a `.` or `/`
|
||||
*
|
||||
* For example:
|
||||
* - `foo/bar` maps to `foo`
|
||||
* - `@example/foo/bar` maps to `@example/foo`
|
||||
* - `./foo` maps to nothing.
|
||||
*/
|
||||
bindingset[this]
|
||||
string getPackagePrefix() {
|
||||
result = this.regexpFind("^(@[^/\\\\]+[/\\\\])?[^@./\\\\][^/\\\\]*", _, _)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user