contiago-toolbar
Version:
One of the options for outputting content from contiago xml-server
23 lines (18 loc) • 780 B
JavaScript
import config from '../../config.json';
const escapeImageUrl = (url) => encodeURI(url);
export const convertImagePathToUrl = (imagePath, size) => {
const resultImagePath = size ? makePathWithSize(imagePath, size) : imagePath;
return escapeImageUrl(`'${
localStorage.getItem(config['toolbar.sandbox.attribute.name']) ? config.sandboxImageStorageUrlPrefix : config.imageStorageUrlPrefix
}${resultImagePath}'`);
};
export const makePathWithSize = (imagePath, size) => {
if (imagePath && size) {
const patern = /\..{3,4}$/i;
const result = imagePath.search(patern);
const nameImg = imagePath.substring(0, result);
const extension = imagePath.substring(result);
const imageWithSize = `${nameImg}~${size}${extension}`;
return imageWithSize;
}
};