getUrl.js 598 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. module.exports = function (url, options) {
  3. if (!options) {
  4. options = {};
  5. }
  6. if (!url) {
  7. return url;
  8. }
  9. url = String(url.__esModule ? url.default : url); // If url is already wrapped in quotes, remove them
  10. if (/^['"].*['"]$/.test(url)) {
  11. url = url.slice(1, -1);
  12. }
  13. if (options.hash) {
  14. url += options.hash;
  15. } // Should url be wrapped?
  16. // See https://drafts.csswg.org/css-values-3/#urls
  17. if (/["'() \t\n]|(%20)/.test(url) || options.needQuotes) {
  18. return "\"".concat(url.replace(/"/g, '\\"').replace(/\n/g, "\\n"), "\"");
  19. }
  20. return url;
  21. };