gonzales-pe
Advanced tools
Comparing version 3.0.0-29 to 3.0.0-30
@@ -25,2 +25,3 @@ module.exports = { | ||
EscapedStringType: 'escapedString', | ||
ExtendType: 'extend', | ||
ExpressionType: 'expression', | ||
@@ -27,0 +28,0 @@ FunctionType: 'function', |
@@ -43,2 +43,25 @@ /** | ||
/** | ||
* @param {String} type Node type | ||
* @param {Function} callback Function to call for every found node | ||
*/ | ||
eachFor: function(type, callback) { | ||
if (!Array.isArray(this.content)) return; | ||
if (typeof type !== 'string') callback = type, type = null; | ||
var l = this.content.length; | ||
var i = l; | ||
var breakLoop; | ||
for (var i = l; i--;) { | ||
if (breakLoop === null) break; | ||
if (!type || this.content[i] && this.content[i].type === type) | ||
breakLoop = callback(this.content[i], i, this); | ||
} | ||
if (breakLoop === null) return null; | ||
}, | ||
/** | ||
* @param {String} type | ||
@@ -69,7 +92,12 @@ * @return {Node} First child node | ||
var l = this.content.length; | ||
var breakLoop; | ||
for (; i < l; i++) { | ||
if (breakLoop === null) break; | ||
if (!type || this.content[i] && this.content[i].type === type) | ||
callback(this.content[i], i); | ||
breakLoop = callback(this.content[i], i, this); | ||
} | ||
if (breakLoop === null) return null; | ||
}, | ||
@@ -120,11 +148,24 @@ | ||
*/ | ||
map: function(callback) { | ||
callback(this); | ||
traverse: function(type, callback, i, parent) { | ||
if (typeof type === 'function') callback = type, type = null; | ||
if (!type || this.type === type) callback(this, i, parent); | ||
if (!Array.isArray(this.content)) return; | ||
this.content.forEach(function(node) { | ||
if (node instanceof Node) | ||
node.map(callback); | ||
}); | ||
var i = 0; | ||
var l = this.content.length; | ||
var breakLoop; | ||
for (; i < l; i++) { | ||
breakLoop = this.content[i].traverse(type, callback, i, this); | ||
if (!breakLoop === null) break; | ||
// If some nodes were removed or added: | ||
var x = this.content.length - l; | ||
l += x; | ||
i += x; | ||
} | ||
if (breakLoop === null) return null; | ||
}, | ||
@@ -131,0 +172,0 @@ |
@@ -17,4 +17,6 @@ var fs = require('fs'); | ||
function parse(css, options) { | ||
if (!css || typeof css !== 'string') | ||
if (typeof css !== 'string') | ||
throw new Error('Please, pass a string to parse'); | ||
else if (!css) | ||
return require('./empty')(); | ||
@@ -21,0 +23,0 @@ var syntax = options && options.syntax || Defaults.SYNTAX; |
{ | ||
"name": "gonzales-pe", | ||
"description": "Gonzales Preprocessor Edition (fast CSS parser)", | ||
"version": "3.0.0-29", | ||
"version": "3.0.0-30", | ||
"homepage": "http://github.com/tonyganch/gonzales-pe", | ||
@@ -6,0 +6,0 @@ "bugs": "http://github.com/tonyganch/gonzales-pe/issues", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
475327
34
13190