* Matches pattern with a single star against search. * Star must match at least one character to be considered a match. * * @param patttern for example "foo*" * @param search for example "fooawesomebar" * @returns the part of search that * matches, or undefined if no match.
(pattern: string, search: string)
| 81 | * @returns the part of search that * matches, or undefined if no match. |
| 82 | */ |
| 83 | function matchStar(pattern: string, search: string): string | undefined { |
| 84 | if (search.length < pattern.length) { |
| 85 | return undefined; |
| 86 | } |
| 87 | if (pattern === "*") { |
| 88 | return search; |
| 89 | } |
| 90 | const star = pattern.indexOf("*"); |
| 91 | if (star === -1) { |
| 92 | return undefined; |
| 93 | } |
| 94 | const part1 = pattern.substring(0, star); |
| 95 | const part2 = pattern.substring(star + 1); |
| 96 | if (search.substr(0, star) !== part1) { |
| 97 | return undefined; |
| 98 | } |
| 99 | if (search.substr(search.length - part2.length) !== part2) { |
| 100 | return undefined; |
| 101 | } |
| 102 | return search.substr(star, search.length - part2.length); |
| 103 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…