File tree 1 file changed +25
-0
lines changed
javascript/ql/lib/semmle/javascript 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,31 @@ class FilePath extends string {
135
135
bindingset [ this ]
136
136
string getExtension ( ) { result = this .regexpCapture ( pathRegex ( ) , 4 ) }
137
137
138
+ /**
139
+ * Holds if this is a relative path starting with an explicit `./` or similar syntax meaning it
140
+ * must be resolved relative to its enclosing folder.
141
+ *
142
+ * Specifically this holds when the string is `.` or `..`, or starts with `./` or `../` or
143
+ * `.\` or `..\`.
144
+ */
145
+ bindingset [ this ]
146
+ pragma [ inline_late]
147
+ predicate isDotRelativePath ( ) { this .regexpMatch ( "\\.\\.?(?:[/\\\\].*)?" ) }
148
+
149
+ /**
150
+ * Gets the NPM package name from the beginning of the given import path.
151
+ *
152
+ * Has no result for paths starting with a `.` or `/`
153
+ *
154
+ * For example:
155
+ * - `foo/bar` maps to `foo`
156
+ * - `@example/foo/bar` maps to `@example/foo`
157
+ * - `./foo` maps to nothing.
158
+ */
159
+ bindingset [ this ]
160
+ string getPackagePrefix ( ) {
161
+ result = this .regexpFind ( "^(@[^/\\\\]+[/\\\\])?[^@./\\\\][^/\\\\]*" , _, _)
162
+ }
138
163
}
139
164
140
165
/**
You can’t perform that action at this time.
0 commit comments