UNPKG

@lonelyplanet/dotcom-core

Version:

This package is meant to house some of our more common UI and shared libs across dotcom applications.

70 lines (63 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var sources = { bdc: { domain: "https://lpbookingcom.imgix.net", regex: /https?:\/\/[\w-]+.bstatic.com/ }, gadventures: { domain: "https://lpgadventures.imgix.net", regex: /https?:\/\/media.gadventures.com/ }, hostelworld: { domain: "https://lphostelworld.imgix.net", regex: /https?:\/\/(.*)hwstatic.com/ }, media: { domain: "https://lonelyplanetimages.imgix.net", regex: /https?:\/\/media.lonelyplanet.com/ }, news: { domain: "https://lonelyplanetwpnews.imgix.net", regex: /https?:\/\/www.lonelyplanet.com\/news\/wp-content\/uploads/ }, staticAsset: { domain: "https://lonelyplanetstatic.imgix.net", regex: /https?:\/\/s3.amazonaws.com\/static-asset/ }, staticSites: { domain: "http://lonelyplanetstaticsites.imgix.net", regex: /https?:\/\/s3.amazonaws.com\/lp-static-sites/ }, viator: { domain: "https://lpviator.imgix.net", regex: /https?:\/\/cache-graphicslib.viator.com/ }, wordpress: { domain: "https://lonelyplanetwp.imgix.net", regex: /https?:\/\/www.lonelyplanet.com\/travel-blog\/tip-article\/wordpress_uploads/ } }; /** * Converts an image path to the imgix url with params */ function imgix(src, options, source) { if (options === void 0) { options = {}; } if (source === void 0) { source = "media"; } var match = sources[source || "media"]; if (!match || !match.regex.test(src)) { return src; } var url = src.replace(match.regex, match.domain); var query = Object.keys(options).map(function (k) { return k + "=" + options[k]; }).join("&"); return "" + url + (query ? "?" + query : ""); } exports.default = imgix;