postcss-image-inliner
Advanced tools
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 |
10
5
10106
139
- Removedlodash.isstring@^4.0.1
- Removedlodash.last@^3.0.0
- Removedlodash.partialright@^4.2.1
- Removedlodash.reject@^4.6.0
- Removedlodash.result@^4.5.2
- Removedmime@^2.4.4
- Removedobject-hash@^2.0.0
- Removedrequest@^2.88.0
- Removedthen-fs@^2.0.0
- Removedajv@6.12.6(transitive)
- Removedasap@2.0.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.0(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlodash.isstring@4.0.1(transitive)
- Removedlodash.last@3.0.0(transitive)
- Removedlodash.partialright@4.2.1(transitive)
- Removedlodash.reject@4.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedobject-hash@2.2.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpromise@7.3.1(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedthen-fs@2.0.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
Updatedasset-resolver@^1.1.0
Updatedpostcss@^7.0.21
Updatedsvgo@^1.3.2