Comparing version 0.2.0 to 0.2.1
@@ -0,1 +1,8 @@ | ||
Changelog | ||
========= | ||
### 0.2.1 (April 25, 2016) | ||
* Fix the handling of invalid inputs | ||
### 0.2.0 (April 24, 2016) | ||
@@ -2,0 +9,0 @@ |
@@ -13,2 +13,4 @@ var matches = require('./matches'); | ||
module.exports = function closest(element, selector, shouldCheckSelf) { | ||
if (!(element && element.nodeType == 1 && selector)) return; | ||
var parentElements = | ||
@@ -15,0 +17,0 @@ (shouldCheckSelf ? [element] : []).concat(parents(element)); |
@@ -9,6 +9,9 @@ /** | ||
module.exports = function getAttributes(element) { | ||
var map = element.attributes; | ||
var attrs = {}; | ||
// Validate input. | ||
if (!(element && element.nodeType == 1)) return attrs; | ||
// Return an empty object if there are no attributes. | ||
var map = element.attributes; | ||
if (map.length === 0) return {}; | ||
@@ -15,0 +18,0 @@ |
@@ -36,15 +36,15 @@ var proto = Element.prototype; | ||
module.exports = function matches(element, test) { | ||
// Never match a falsy test object, but don't error either. | ||
if (!test) return false; | ||
// if test is a string or DOM element test it. | ||
if (typeof test == 'string' || test.nodeType == 1) { | ||
return element == test || matchesSelector(element, test); | ||
} | ||
// if it has a length property iterate over the items | ||
// and return true if any match. | ||
else if ('length' in test) { | ||
for (var i = 0, item; item = test[i]; i++) { | ||
if (element == item || matchesSelector(element, item)) return true; | ||
// Validate input. | ||
if (element && element.nodeType == 1 && test) { | ||
// if test is a string or DOM element test it. | ||
if (typeof test == 'string' || test.nodeType == 1) { | ||
return element == test || matchesSelector(element, test); | ||
} | ||
// if it has a length property iterate over the items | ||
// and return true if any match. | ||
else if ('length' in test) { | ||
for (var i = 0, item; item = test[i]; i++) { | ||
if (element == item || matchesSelector(element, item)) return true; | ||
} | ||
} | ||
} | ||
@@ -51,0 +51,0 @@ // Still here? Return false |
{ | ||
"name": "dom-utils", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A small, modular DOM utilities library", | ||
@@ -79,2 +79,12 @@ "scripts": { | ||
"8" | ||
], | ||
[ | ||
"OS X 10.10", | ||
"iPhone", | ||
"9.2" | ||
], | ||
[ | ||
"Linux", | ||
"android", | ||
"4.4" | ||
] | ||
@@ -81,0 +91,0 @@ ] |
@@ -58,8 +58,9 @@ var assert = require('assert'); | ||
it('handles falsy inputs gracefully', function() { | ||
it('handles invalid inputs gracefully', function() { | ||
assert(!closest()); | ||
assert(!closest(null, 'div')); | ||
assert(!closest(document.body)); | ||
assert(!closest(document, '*')); | ||
}); | ||
}); |
@@ -32,3 +32,10 @@ var assert = require('assert'); | ||
it('handles invalid inputs gracefully', function() { | ||
assert.deepEqual(getAttributes(), {}); | ||
assert.deepEqual(getAttributes(null), {}); | ||
assert.deepEqual(getAttributes(document), {}); | ||
}); | ||
}); | ||
@@ -61,6 +61,8 @@ var assert = require('assert'); | ||
it('handles falsy inputs gracefully', function() { | ||
it('handles invalid inputs gracefully', function() { | ||
assert(!matches()); | ||
assert(!matches(fixtures, null)); | ||
assert(!matches(document, '*')); | ||
}); | ||
}); |
@@ -34,4 +34,6 @@ var assert = require('assert'); | ||
it('handles falsy input gracefully', function() { | ||
it('handles invalid input gracefully', function() { | ||
assert.deepEqual(parents(), []); | ||
assert.deepEqual(parents(null), []); | ||
assert.deepEqual(parents(document), []); | ||
}); | ||
@@ -38,0 +40,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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
31645
693
0