Last active
October 15, 2015 02:58
-
-
Save mike-engel/ca8ce68fb5e72af74d55 to your computer and use it in GitHub Desktop.
Generate a responsive image string based on a filename and some widths
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
function generateResponsiveString (filename, widths, isFallback) { | |
'use strict' | |
const urlPrefix = 'https://res.cloudinary.com/beardfury/image/upload/c_scale,w_' | |
let fullString = '' | |
if (isFallback) { | |
return urlPrefix + widths + filename | |
} | |
widths.forEach(function (width) { | |
fullString += urlPrefix + width + filename + ' ' + width + 'w, ' | |
}) | |
// strip the trailing comma and space | |
return fullString.substr(0, fullString.length - 2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment