postcss-zindex
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -0,1 +1,6 @@ | ||
# 2.0.1 | ||
* Improved performance of the module by sorting/deduplicating values in one pass | ||
instead of per-value (thanks to @pgilad). | ||
# 2.0.0 | ||
@@ -2,0 +7,0 @@ |
@@ -14,9 +14,13 @@ 'use strict'; | ||
}); | ||
// Second pass; optimise | ||
cache.optimizeValues(); | ||
// Second pass; optimize | ||
nodes.forEach(function (decl) { | ||
// Need to coerce to string so that the | ||
// AST is updated correctly | ||
decl.value = '' + cache.convert(decl.value); | ||
var value = cache.getValue(decl.value); | ||
decl.value = String(value); | ||
}); | ||
}; | ||
}); |
'use strict'; | ||
var uniq = require('uniqs'); | ||
function LayerCache () { | ||
@@ -10,6 +12,4 @@ if (!(this instanceof LayerCache)) { | ||
function sortAscending (key) { | ||
return function (a, b) { | ||
return a[key] - b[key]; | ||
}; | ||
function sortAscending (a, b) { | ||
return a - b; | ||
} | ||
@@ -19,3 +19,3 @@ | ||
return { | ||
from: value.from, | ||
from: value, | ||
to: index + 1 | ||
@@ -25,21 +25,32 @@ }; | ||
LayerCache.prototype._filterValues = function (value) { | ||
return this._values.filter(function (index) { | ||
return index.from === parseInt(value, 10); | ||
}); | ||
LayerCache.prototype._findValue = function (value) { | ||
var length = this._values.length; | ||
for (var i = 0; i < length; ++i) { | ||
if (this._values[i].from === value) { | ||
return this._values[i]; | ||
} | ||
} | ||
return false; | ||
}; | ||
LayerCache.prototype._optimiseValues = function () { | ||
this._values = this._values.sort(sortAscending('from')).map(mapValues); | ||
LayerCache.prototype.optimizeValues = function () { | ||
var values = uniq(this._values) | ||
.sort(sortAscending) | ||
.map(mapValues); | ||
this._values = values; | ||
}; | ||
LayerCache.prototype.addValue = function (value) { | ||
if (!this._filterValues(value).length && value > 0) { | ||
this._values.push({ from: parseInt(value, 10) }); | ||
this._optimiseValues(); | ||
var parsedValue = parseInt(value, 10); | ||
// pass only valid values | ||
if (!parsedValue || parsedValue < 0) { | ||
return; | ||
} | ||
this._values.push(parsedValue); | ||
}; | ||
LayerCache.prototype.convert = function (value) { | ||
var match = this._filterValues(value)[0]; | ||
LayerCache.prototype.getValue = function (value) { | ||
var parsedValue = parseInt(value, 10); | ||
var match = this._findValue(parsedValue); | ||
return match && match.to || value; | ||
@@ -46,0 +57,0 @@ }; |
{ | ||
"name": "postcss-zindex", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Reduce z-index values with PostCSS.", | ||
@@ -10,2 +10,7 @@ "main": "index.js", | ||
}, | ||
"files": [ | ||
"LICENSE-MIT", | ||
"index.js", | ||
"lib" | ||
], | ||
"keywords": [ | ||
@@ -22,3 +27,4 @@ "css", | ||
"dependencies": { | ||
"postcss": "^5.0.4" | ||
"postcss": "^5.0.4", | ||
"uniqs": "^2.0.0" | ||
}, | ||
@@ -25,0 +31,0 @@ "devDependencies": { |
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
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
6407
67
2
6
+ Addeduniqs@^2.0.0
+ Addeduniqs@2.0.0(transitive)