Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dom-utils

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-utils - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

7

CHANGELOG.md

@@ -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 @@

2

lib/closest.js

@@ -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));

5

lib/get-attributes.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc