Created
September 18, 2017 17:58
-
-
Save its-poole/08fda6cce88a726ecd5ec498cfcfc4a6 to your computer and use it in GitHub Desktop.
Returns the basename of a feature file minus its extension (for client side/browser)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var FEATURE_FILE_EXTENSION = /\.feature$/; | |
function featureFileBasenameWithoutExtension(featureFilePath) { | |
var lastDirectoryIndex = featureFilePath.lastIndexOf('/') | |
var filenameIndex = lastDirectoryIndex > -1 ? lastDirectoryIndex + 1 : 0; | |
var filename = featureFilePath.substring(filenameIndex); | |
return filename.replace(FEATURE_FILE_EXTENSION, ''); | |
} | |
var trial1 = featureFileBasenameWithoutExtension('features/tasty/my_New_FEATure_file.feature.feature'); | |
var trial2 = featureFileBasenameWithoutExtension('ben.feature'); | |
var trial3 = featureFileBasenameWithoutExtension('features/tasty/bobby.feature.feature'); | |
console.log(trial1); | |
console.log(trial2); | |
console.log(trial3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment