postcss-url
Advanced tools
Comparing version 5.0.2 to 5.1.0
@@ -0,1 +1,6 @@ | ||
# 5.1.0 - 2016-01-19 | ||
- Added: `filter` option | ||
([#61](https://github.com/postcss/postcss-url/pull/61)) | ||
# 5.0.2 - 2015-10-12 | ||
@@ -2,0 +7,0 @@ |
45
index.js
@@ -14,2 +14,3 @@ /** | ||
var pathIsAbsolute = require("path-is-absolute") | ||
var minimatch = require("minimatch") | ||
/** | ||
@@ -89,2 +90,28 @@ * @typedef UrlRegExp | ||
/** | ||
* Returns wether the given filename matches the given pattern | ||
* Allways returns true if the given pattern is empty | ||
* | ||
* @param {String} filename the processed filename | ||
* @param {String|RegExp|Function} pattern A minimatch string, | ||
* regular expression or function to test the filename | ||
* | ||
* @return {Boolean} | ||
*/ | ||
function matchesFilter(filename, pattern) { | ||
if (typeof pattern === "string") { | ||
pattern = minimatch.filter(pattern) | ||
} | ||
if (pattern instanceof RegExp) { | ||
return pattern.test(filename) | ||
} | ||
if (pattern instanceof Function) { | ||
return pattern(filename) | ||
} | ||
return true | ||
} | ||
/** | ||
* @callback PostcssUrl~DeclProcessor | ||
@@ -111,3 +138,3 @@ * @param {Object} decl declaration | ||
if (isCustom || ! isUrlShouldBeIgnored(oldUrl)) { | ||
if (isCustom || !isUrlShouldBeIgnored(oldUrl)) { | ||
newUrl = cb(result, from, dirname, oldUrl, to, options, decl) | ||
@@ -184,2 +211,3 @@ } | ||
var basePath = options.basePath | ||
var filter = options.filter | ||
var fullFilePath | ||
@@ -219,3 +247,3 @@ | ||
if (!fs.existsSync(file)) { | ||
result.warn("Can't read file '" + file + "', ignoring", {node: decl}) | ||
result.warn("Can't read file '" + file + "', ignoring", { node: decl }) | ||
return | ||
@@ -230,6 +258,10 @@ } | ||
if (!matchesFilter(file, filter)) { | ||
return processFallback() | ||
} | ||
var mimeType = mime.lookup(file) | ||
if (!mimeType) { | ||
result.warn("Unable to find asset mime-type for " + file, {node: decl}) | ||
result.warn("Unable to find asset mime-type for " + file, { node: decl }) | ||
return | ||
@@ -259,3 +291,3 @@ } | ||
if (from === to) { | ||
result.warn("Option `to` of postcss is required, ignoring", {node: decl}) | ||
result.warn("Option `to` of postcss is required, ignoring", { node: decl }) | ||
return | ||
@@ -283,3 +315,3 @@ } | ||
catch (err) { | ||
result.warn("Can't read file '" + filePath + "', ignoring", {node: decl}) | ||
result.warn("Can't read file '" + filePath + "', ignoring", { node: decl }) | ||
return | ||
@@ -331,4 +363,5 @@ } | ||
assetPath = assetPath.replace(/\\/g, "\/") | ||
} | ||
} | ||
return assetPath | ||
} | ||
{ | ||
"name": "postcss-url", | ||
"version": "5.0.2", | ||
"version": "5.1.0", | ||
"description": "PostCSS plugin to rebase or inline on url().", | ||
@@ -17,6 +17,3 @@ "keywords": [ | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/postcss/postcss-url.git" | ||
}, | ||
"repository": "https://github.com/postcss/postcss-url.git", | ||
"files": [ | ||
@@ -29,2 +26,3 @@ "index.js" | ||
"mime": "^1.2.11", | ||
"minimatch": "^3.0.0", | ||
"mkdirp": "^0.5.0", | ||
@@ -35,3 +33,4 @@ "path-is-absolute": "^1.0.0", | ||
"devDependencies": { | ||
"eslint": "^1.1.0", | ||
"eslint": "^1.10.3", | ||
"eslint-config-i-am-meticulous": "^1.0.0", | ||
"postcss-import": "^7.0.0", | ||
@@ -41,4 +40,13 @@ "tape": "^4.0.3" | ||
"scripts": { | ||
"test": "eslint . && tape test" | ||
"lint": "eslint --fix .", | ||
"tests": "tape test", | ||
"test": "npm run lint && npm run tests" | ||
}, | ||
"eslintConfig": { | ||
"extends": "eslint-config-i-am-meticulous", | ||
"parser": "espree", | ||
"rules": { | ||
"no-var": 0 | ||
} | ||
} | ||
} |
@@ -71,9 +71,14 @@ # postcss-url | ||
And should return the transformed url. | ||
And should return the transformed url. | ||
You can use this option to adjust urls for CDN. | ||
#### `maxSize` | ||
_(default: `14`)_ | ||
Specify the maximum file size to inline (in kbytes) | ||
#### `filter` | ||
A regular expression e.g. `/\.svg$/`, a [minimatch string](https://github.com/isaacs/minimatch) e.g. `'**/*.svg'` or a custom filter function to determine wether a file should be inlined. | ||
#### `fallback` | ||
@@ -80,0 +85,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18301
311
121
7
4
2
+ Addedminimatch@^3.0.0