Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-url

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-url - npm Package Compare versions

Comparing version 7.0.0 to 7.1.0

7

CHANGELOG.md

@@ -0,4 +1,9 @@

# 7.1.0 - 2017-07-19
Added: `optimizeSvgEncode` option for inlined svg ([#103](https://github.com/postcss/postcss-url/issues/103))
Added: `rebase` as fallback in copy ([#104](https://github.com/postcss/postcss-url/issues/104))
# 7.0.0 - 2017-06-05
Added: PostCss 6 support
Added: PostCss 6 support

@@ -5,0 +10,0 @@ # 6.3.0 - 2017-06-04

2

package.json
{
"name": "postcss-url",
"version": "7.0.0",
"version": "7.1.0",
"description": "PostCSS plugin to rebase or inline on url().",

@@ -5,0 +5,0 @@ "keywords": [

@@ -145,2 +145,3 @@ # postcss-url

* `ignoreFragmentWarning` - do not warn when an SVG URL with a fragment is inlined
* `optimizeSvgEncode` - reduce size of inlined svg (IE9+, Android 3+)
* `copy`

@@ -147,0 +148,0 @@ * `basePath` - path or array of paths to search assets (relative to `from`, or absolute)

'use strict';
/**
* Optimize encoding SVG files (IE9+, Android 3+)
* @see https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
*
* @param {String} svgContent
* @returns {String}
*/
const optimizedSvgEncode = (svgContent) => {
const result = encodeURIComponent(svgContent)
.replace(/%3D/g, '=')
.replace(/%3A/g, ':')
.replace(/%2F/g, '/')
.replace(/%22/g, "'")
.replace(/%2C/g, ',')
.replace(/%3B/g, ';');
//
return result.replace(/(%[0-9A-Z]{2})/g, (matched, AZ) => {
return AZ.toLowerCase();
});
};
/**
* Encoding file contents to string

@@ -8,9 +29,11 @@ *

* @param {String} [encodeType=base64|encodeURI|encodeURIComponent]
* @param {Boolean} [shouldOptimizeURIEncode]
* @returns {string}
*/
module.exports = (file, encodeType) => {
const inlineDecl = `data:${file.mimeType}`;
module.exports = (file, encodeType, shouldOptimizeURIEncode) => {
const dataMime = `data:${file.mimeType}`;
if (encodeType === 'base64') {
return `${inlineDecl};base64,${file.contents.toString('base64')}`;
return `${dataMime};base64,${file.contents.toString('base64')}`;
}

@@ -20,5 +43,15 @@

return `${inlineDecl},${encodeFunc(file.contents.toString('utf8'))
const content = file.contents.toString('utf8')
// removing new lines
.replace(/\n+/g, '');
let encodedStr = (shouldOptimizeURIEncode && encodeType === 'encodeURIComponent')
? optimizedSvgEncode(content)
: encodeFunc(content);
encodedStr = encodedStr
.replace(/%20/g, ' ')
.replace(/#/g, '%23')}`;
.replace(/#/g, '%23');
return `${dataMime},${encodedStr}`;
};

@@ -6,2 +6,3 @@ 'use strict';

const processCopy = require('./copy');
const processRebase = require('./rebase');

@@ -25,2 +26,4 @@ const encodeFile = require('../lib/encode');

return processCopy.apply(null, arguments);
case 'rebase':
return processRebase.apply(null, arguments);
default:

@@ -67,3 +70,3 @@ return;

const isSvg = file.mimeType === 'image/svg+xml';
const defaultEncodeType = isSvg ? 'encodeUriComponent' : 'base64';
const defaultEncodeType = isSvg ? 'encodeURIComponent' : 'base64';
const encodeType = options.encodeType || defaultEncodeType;

@@ -79,5 +82,5 @@

const encodedStr = encodeFile(file, encodeType);
const encodedStr = encodeFile(file, encodeType, options.optimizeSvgEncode && isSvg);
return (options.includeUriFragment && asset.hash) ? encodedStr + asset.hash : encodedStr;
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc