Created
December 16, 2014 21:27
-
-
Save Truemedia/10a4a89224568f8c7dd4 to your computer and use it in GitHub Desktop.
Convert directory path to css class names for images using nodeJS
This file contains hidden or 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 path = '/dir1/dir2/img_folder/dir3/dir5/imagename.png'; | |
var path_arr = path.split('/'); | |
var img_dir = 'img_folder'; | |
var img_ext = '.png'; | |
var img_index = path_arr.indexOf(img_dir); | |
var img_dirs = path_arr.splice( (img_index + 1 ) ); | |
var image = img_dirs.pop().replace('.png', ''); | |
var css_class = '.image-' + img_dirs.concat(image).join('-'); | |
console.log(css_class); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment