Socket
Socket
Sign inDemoInstall

postcss-image-inliner

Package Overview
Dependencies
299
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.0.3

34

index.js
'use strict';
const postcss = require('postcss');
const Bluebird = require('bluebird');
const isString = require('lodash.isstring');
const debug = require('debug')('image-inliner');
const defaults = require('lodash.defaults');
const debug = require('debug')('image-inliner');
const escape = require('lodash.escaperegexp');
const last = require('lodash.last');
const reduce = require('lodash.reduce');
const filesize = require('filesize');
const getResource = require('asset-resolver').getResource;
const getDataUri = require('./lib/image').getDataUri;
const {getResource} = require('asset-resolver');
const {getDataUri} = require('./lib/image');

@@ -22,3 +20,3 @@ module.exports = postcss.plugin('postcss-image-inliner', opts => {

if (isString(opts.assetPaths)) {
if (!Array.isArray(opts.assetPaths)) {
opts.assetPaths = [opts.assetPaths];

@@ -33,3 +31,3 @@ }

if (opts.maxFileSize && opts.maxFileSize < size) {
const msg = 'Too big. ' + filesize(size) + ' exceeds the allowed ' + filesize(opts.maxFileSize);
const msg = `Too big. ${filesize(size)} exceeds the allowed ${filesize(opts.maxFileSize)}`;
debug(msg);

@@ -46,4 +44,4 @@ return Bluebird.reject(new Error(msg));

filter: assertSize
}).catch(err => {
debug(err.message, filepath, 'could not be resolved');
}).catch(error => {
debug(error.message, filepath, 'could not be resolved');
});

@@ -54,6 +52,6 @@ }

const matcher = /url\(\s*(?:['"]*)(?!['"]*data:)(.*?)(?:['"]*)\s*\)/gm;
return function (decl) {
return decl => {
let match;
while ((match = matcher.exec(decl.value)) !== null) {
cb(decl, last(match));
cb(decl, match[match.length - 1]);
}

@@ -73,3 +71,3 @@ };

return function (css) {
return css => {
const replacements = {};

@@ -89,4 +87,4 @@ const filter = /^(background(?:-image)?)|(content)|(cursor)/;

if (data[url]) {
const regexp = new RegExp('[\'"]?' + escape(url) + '[\'"]?');
decl.value = decl.value.replace(regexp, '\'' + data[url] + '\'');
const regexp = new RegExp(`['"]?${escape(url)}['"]?`);
decl.value = decl.value.replace(regexp, `'${data[url]}'`);
debug(url, 'successfully replaced with ', data[url]);

@@ -96,10 +94,10 @@ } else {

if (opts.strict) {
throw new Error('No file found for ' + url);
throw new Error(`No file found for ${url}`);
}
}
}));
}).catch(err => {
debug(err);
}).catch(error => {
debug(error);
return new Bluebird((resolve, reject) => {
reject(err);
reject(error);
});

@@ -106,0 +104,0 @@ });

@@ -26,3 +26,3 @@ 'use strict';

function computeDataUri(opts) {
return function (file, key) {
return (file, key) => {
// If the url is SVG, let's compress and use the XML directly

@@ -33,8 +33,8 @@ if (file.mime === 'image/svg+xml' && !opts.b64Svg) {

return {
data: 'data:image/svg+xml;charset=US-ASCII,' + encodeSvg(result.data),
data: `data:image/svg+xml;charset=US-ASCII,${encodeSvg(result.data)}`,
key
};
}).catch(err => {
debug('errored', err.message);
throw err;
}).catch(error => {
debug('errored', error.message);
throw error;
});

@@ -45,3 +45,3 @@ }

return {
data: 'data:' + file.mime + ';base64,' + Buffer.from(file.contents, 'binary').toString('base64'),
data: `data:${file.mime};base64,${Buffer.from(file.contents, 'binary').toString('base64')}`,
key

@@ -48,0 +48,0 @@ };

{
"name": "postcss-image-inliner",
"version": "2.0.2",
"version": "2.0.3",
"description": "PostCSS plugin to inline images into css",

@@ -24,3 +24,3 @@ "keywords": [

"dependencies": {
"asset-resolver": "^1.0.6",
"asset-resolver": "^1.1.0",
"bluebird": "^3.7.1",

@@ -31,29 +31,25 @@ "debug": "^4.1.1",

"lodash.escaperegexp": "^4.1.2",
"lodash.isstring": "^4.0.1",
"lodash.last": "^3.0.0",
"lodash.map": "^4.6.0",
"lodash.partialright": "^4.2.1",
"lodash.reduce": "^4.6.0",
"lodash.reject": "^4.6.0",
"lodash.result": "^4.5.2",
"mime": "^2.4.4",
"object-hash": "^2.0.0",
"postcss": "^7.0.18",
"request": "^2.88.0",
"svgo": "^1.3.0",
"then-fs": "^2.0.0"
"postcss": "^7.0.21",
"svgo": "^1.3.2"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^5.16.0",
"eslint-config-xo": "^0.26.0",
"finalhandler": "^1.1.2",
"mocha": "^6.2.2",
"serve-static": "^1.14.1"
"serve-static": "^1.14.1",
"xo": "^0.24.0"
},
"scripts": {
"eslint": "eslint .",
"xo": "xo",
"mocha": "mocha",
"test": "npm run eslint && npm run mocha"
"test": "npm run xo && npm run mocha"
},
"xo": {
"space": 4,
"rules": {
"capitalized-comments": "off"
}
},
"engines": {

@@ -60,0 +56,0 @@ "node": ">=6.0"

@@ -6,4 +6,4 @@ # PostCSS Image Inliner [![Build Status][ci-img]][ci]

[PostCSS]: https://github.com/postcss/postcss
[ci-img]: https://travis-ci.org/bezoerb/postcss-image-inliner.svg
[ci]: https://travis-ci.org/bezoerb/postcss-image-inliner
[ci-img]: https://github.com/bezoerb/inline-critical/workflows/Tests/badge.svg
[ci]: https://github.com/bezoerb/inline-critical/actions?workflow=Tests

@@ -10,0 +10,0 @@ ```css

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc