Skip to content

Commit

Permalink
Simplify the regex used
Browse files Browse the repository at this point in the history
It doesn't matter which path separator is used, no need to save it in a
capturing group.
  • Loading branch information
Arcanemagus committed Dec 3, 2015
1 parent c322a5c commit 0f1b3d4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
import {BufferedProcess} from 'atom'
const extractionRegex = /Installing (.*?) to .* (.*)/
const nameRegexes = [
/(\\|\/)packages(\\|\/)(.*?)(\\|\/)/,
/(\\|\/)([\w-_]+)(\\|\/)(lib|src)(\\|\/)/i,
/(\\|\/)([\w-_]+)(\\|\/)[\w-_]+\..+$/
/[\\\/]packages[\\\/](.*?)[\\\/]/,
/[\\\/]([\w-_]+)[\\\/](?:lib|src)[\\\/]/i,
/[\\\/]([\w-_]+)[\\\/][\w-_]+\..+$/
]

export function guessName(filePath) {
let matches

matches = nameRegexes[0].exec(filePath)
if (matches) {
return matches[3]
return matches[1]
}
matches = nameRegexes[1].exec(filePath)
if (matches) {
return matches[2]
return matches[1]
}
matches = nameRegexes[2].exec(filePath)
if (matches) {
return matches[2]
return matches[1]
}
return null
}
Expand Down

0 comments on commit 0f1b3d4

Please sign in to comment.