From 43431d0e56b7f661ac59471f91cc86085fe34a70 Mon Sep 17 00:00:00 2001 From: Paul Abbott Date: Thu, 28 May 2020 15:45:27 -0400 Subject: [PATCH] Fix #12 Its not possible to have NO cssPrefix. Also removed invalid and unneeded charset, see https://codepen.io/tigt/post/optimizing-svgs-in-data-uris --- index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 2f266f8..09a9073 100644 --- a/index.js +++ b/index.js @@ -23,25 +23,25 @@ module.exports = function (options) { options = options || {}; // Init default options - if (!options.fileName) { + if (options.fileName == null) { // == null is true for null and undefined, but not empty string. options.fileName = 'icons'; } - if (!options.cssPrefix) { + if (options.cssPrefix == null) { options.cssPrefix = 'icon-'; } - if (!options.cssSelector) { + if (options.cssSelector == null) { options.cssSelector = '.'; } if (!options.addSize) { options.addSize = false; } - if (!options.defaultWidth) { + if (!options.defaultWidth) { // empty string not allowed options.defaultWidth = '16px'; } - if (!options.defaultHeight) { + if (!options.defaultHeight) { // empty string not allowed options.defaultHeight = '16px'; } - if (!options.fileExt) { + if (options.fileExt == null) { options.fileExt = 'css'; } @@ -61,7 +61,7 @@ module.exports = function (options) { .replace(//gmi, '%3E') // > .replace(/#/gmi, '%23') // # - .replace(/\"/gmi, '\''); // " + .replace(/\"/gmi, '\''); // " (replace double-quotes with single-quotes) } /** @@ -75,7 +75,7 @@ module.exports = function (options) { function buildCssRule(normalizedFileName, encodedSvg, width, height) { var cssRule = []; cssRule.push(options.cssSelector + options.cssPrefix + normalizedFileName + ' {'); - cssRule.push(' background-image: url("data:image/svg+xml;charset=utf8, ' + encodedSvg + '");'); + cssRule.push(' background-image: url("data:image/svg+xml,' + encodedSvg + '");'); if (options.addSize) { cssRule.push(' width: ' + width + ';'); cssRule.push(' height: ' + height + ';');