postcss-base64
Advanced tools
Comparing version 0.3.3 to 0.4.1
var fs = require('fs'), | ||
postcss = require('postcss'), | ||
Promise = require('promise'); | ||
postcss = require('postcss'); | ||
@@ -24,4 +23,5 @@ function getUrl(value) { | ||
function replaceInline(string) { | ||
function replaceInline(string, opts) { | ||
output = new Buffer(string).toString('base64'); | ||
if(opts.prepend) output = opts.prepend + output; | ||
return output; | ||
@@ -58,3 +58,3 @@ } | ||
css.replaceValues(search, function (string) { | ||
return replaceInline(string); | ||
return replaceInline(string, opts); | ||
}); | ||
@@ -61,0 +61,0 @@ } |
{ | ||
"name": "postcss-base64", | ||
"version": "0.3.3", | ||
"version": "0.4.1", | ||
"description": "Replace values in url() statements with base64 encoded strings.", | ||
@@ -17,4 +17,3 @@ "author": "Jelmer de Maat", | ||
"fs": "0.0.2", | ||
"postcss": "^5.0.12", | ||
"promise": "^7.0.4" | ||
"postcss": "^5.0.12" | ||
}, | ||
@@ -21,0 +20,0 @@ "repository": "git@github.com:jelmerdemaat/postcss-base64.git", |
@@ -21,16 +21,21 @@ postcss-base64, a [PostCSS](https://github.com/postcss/postcss/) plugin, replaces urls or values inside `url()` functions with their base64 encoded strings. | ||
`extensions` | ||
#### extensions | ||
An array of extensions of files that have to be encoded, including the leading dot. | ||
_Example: `['.svg']`_ | ||
_Example: `extensions: ['.svg']`_ | ||
`pattern` | ||
#### pattern | ||
A valid regex pattern to match against the string inside `url()` definitions to encode. Can not match file urls (use `extensions` for this). | ||
_Example: `/<svg.*<\/svg>/i`_ | ||
_Example: `pattern: /<svg.*<\/svg>/i`_ | ||
#### prepend | ||
String value to prepend before the outputted base64 code. Works only in combination with the pattern approach, for now. | ||
_Example: `prepend: 'data:image/svg+xml;base64,'`_ | ||
### NodeJS | ||
@@ -58,3 +63,3 @@ Using PostCSS in NodeJS, the approach would be as follows: | ||
base64({ | ||
files: ['.svg'] | ||
extensions: ['.svg'] | ||
}) | ||
@@ -73,3 +78,3 @@ ])) | ||
.selector { | ||
background-image: url('data:image/svg+xml;base64,<svg>...</svg>'); | ||
background-image: url('<svg>...</svg>'); | ||
} | ||
@@ -80,3 +85,4 @@ ``` | ||
var opts = { | ||
pattern: /<svg.*<\/svg>/i | ||
pattern: /<svg.*<\/svg>/i, | ||
prepend: 'data:image/svg+xml;base64,' | ||
} | ||
@@ -83,0 +89,0 @@ ``` |
Sorry, the diff of this file is not supported yet
9744
2
14
121
92
4
- Removedpromise@^7.0.4
- Removedasap@2.0.6(transitive)
- Removedpromise@7.3.1(transitive)