isn't easier to use require('path.extname(), then slicing based on that? this line seems complex.