New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

select-dom

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

select-dom - npm Package Compare versions

Comparing version 4.2.1 to 5.0.0-0

license

82

index.d.ts

@@ -1,47 +0,37 @@

// https://github.com/Microsoft/TypeScript/blob/9d3707d671592d030386956c9ce39e539b8d0972/src/lib/dom.generated.d.ts#L10581
type BaseElement = Element | DocumentFragment;
type BaseElements = Element | Element[] | NodeList | DocumentFragment;
export interface SelectDom {
<K extends keyof HTMLElementTagNameMap>(
selectors: K,
baseElement?: BaseElement
): HTMLElementTagNameMap[K] | null;
<K extends keyof SVGElementTagNameMap>(
selectors: K,
baseElement?: BaseElement
): SVGElementTagNameMap[K] | null;
<E extends HTMLElement = HTMLElement>(
selectors: string,
baseElement?: BaseElement
): E | null;
exists<K extends keyof HTMLElementTagNameMap>(
selectors: K,
baseElement?: BaseElement
): boolean;
exists<K extends keyof SVGElementTagNameMap>(
selectors: K,
baseElement?: BaseElement
): boolean;
exists<E extends HTMLElement = HTMLElement>(
selectors: string,
baseElement?: BaseElement
): boolean;
all<K extends keyof HTMLElementTagNameMap>(
selectors: K,
baseElements?: BaseElements
): HTMLElementTagNameMap[K][];
all<K extends keyof SVGElementTagNameMap>(
selectors: K,
baseElements?: BaseElements
): SVGElementTagNameMap[K][];
all<E extends HTMLElement = HTMLElement>(
selectors: string,
baseElements?: BaseElements
): E[];
declare type BaseElement = Element | DocumentFragment | Document | Window;
declare type BaseElements = Element | Element[] | NodeList | DocumentFragment | Document | Window;
/**
* @param selectors One or more CSS selectors separated by commas
* @param [baseElement] The element to look inside of
* @return The element found, if any
*/
declare function select<T extends keyof HTMLElementTagNameMap>(selectors: T, baseElement?: BaseElement): HTMLElementTagNameMap[T] | null;
declare namespace select {
var exists: typeof exists;
var all: typeof all;
}
declare const select: SelectDom;
export default select
declare function select<T extends keyof SVGElementTagNameMap>(selectors: T, baseElement?: BaseElement): SVGElementTagNameMap[T] | null;
declare namespace select {
var exists: typeof exists;
var all: typeof all;
}
declare function select<T extends HTMLElement = HTMLElement>(selectors: string, baseElement?: BaseElement): T | null;
declare namespace select {
var exists: typeof exists;
var all: typeof all;
}
/**
* @param selectors One or more CSS selectors separated by commas
* @param [baseElement] The element to look inside of
* @return Whether it's been found
*/
declare function exists<T extends HTMLElement = HTMLElement>(selectors: keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap | string, baseElement?: BaseElement): boolean;
/**
* @param selectors One or more CSS selectors separated by commas
* @param [baseElements] The element or list of elements to look inside of
* @return An array of elements found
*/
declare function all<T extends keyof HTMLElementTagNameMap>(selectors: T, baseElements?: BaseElements): HTMLElementTagNameMap[T][];
declare function all<T extends keyof SVGElementTagNameMap>(selectors: T, baseElements?: BaseElements): SVGElementTagNameMap[T][];
declare function all<T extends HTMLElement = HTMLElement>(selectors: string, baseElements?: BaseElements): T[];
export default select;

@@ -1,67 +0,45 @@

'use strict';
/**
* @param {string} selectors One or more CSS selectors separated by commas
* @param {Element} [baseElement] The element to look inside of
* @return {?Element} The element found, if any
*/
"use strict";
// Types inspired by
// https://github.com/Microsoft/TypeScript/blob/9d3707d/src/lib/dom.generated.d.ts#L10581
Object.defineProperty(exports, "__esModule", { value: true });
function select(selectors, baseElement) {
// Shortcut with specified-but-null baseElement
if (arguments.length === 2 && !baseElement) {
return null;
}
return (baseElement || document).querySelector(selectors);
// Shortcut with specified-but-null baseElement
if (arguments.length === 2 && !baseElement) {
return null;
}
return (baseElement || document).querySelector(selectors);
}
/**
* @param {string} selectors One or more CSS selectors separated by commas
* @param {Element} [baseElement] The element to look inside of
* @return {boolean} Whether it's been found
*/
select.exists = function (selectors, baseElement) {
if (arguments.length === 2) {
return Boolean(select(selectors, baseElement));
}
return Boolean(select(selectors));
};
/**
* @param {string} selectors One or more CSS selectors separated by commas
* @param {Element|Element[]} [baseElements] The element or list of elements to look inside of
* @return {Element[]} An array of elements found
*/
select.all = function (selectors, baseElements) {
// Shortcut with specified-but-null baseElements
if (arguments.length === 2 && !baseElements) {
return [];
}
// Can be: select.all('selectors') or select.all('selectors', singleElementOrDocument)
if (!baseElements || typeof baseElements.querySelectorAll === 'function') {
return Array.apply(null, (baseElements || document).querySelectorAll(selectors));
}
var current;
var i;
var ii;
var all;
for (i = 0; i < baseElements.length; i++) {
current = baseElements[i].querySelectorAll(selectors);
if (!all) {
all = Array.apply(null, current);
continue;
}
for (ii = 0; ii < current.length; ii++) {
if (all.indexOf(current[ii]) < 0) {
all.push(current[ii]);
}
}
}
return all;
};
function exists(selectors, baseElement) {
if (arguments.length === 2) {
return Boolean(select(selectors, baseElement));
}
return Boolean(select(selectors));
}
function all(selectors, baseElements) {
// Shortcut with specified-but-null baseElements
if (arguments.length === 2 && !baseElements) {
return [];
}
// Can be: select.all('selectors') or select.all('selectors', singleElementOrDocument)
if (!baseElements || typeof baseElements.querySelectorAll === 'function') {
return new Array(...(baseElements || document).querySelectorAll(selectors));
}
const all = new Set();
for (let i = 0; i < baseElements.length; i++) {
const current = baseElements[i].querySelectorAll(selectors);
for (let ii = 0; ii < current.length; ii++) {
all.add(current[ii]);
}
}
// Preserves IE11 support and performs 3x better then ...all in Safari
const arr = [];
all.forEach(function (v) {
arr.push(v);
});
return arr;
}
select.exists = exists;
select.all = all;
module.exports = select;
exports.default = select;
//# sourceMappingURL=index.js.map
{
"name": "select-dom",
"version": "4.2.1",
"version": "5.0.0-0",
"description": "Extra lightweight DOM selector helper",
"main": "index.js",
"scripts": {
"test": "xo && browserify test.js | tape-run"
"test": "tsc && tsd-check && xo && browserify test.js | tape-run",
"prepublish-only": "tsc",
"build": "tsc",
"watch": "tsc --watch"
},
"devDependencies": {
"@sindresorhus/tsconfig": "^0.2.1",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"browserify": "^16.2.2",
"eslint-config-xo-typescript": "^0.8.0",
"tape": "^4.9.0",
"tape-run": "^4.0.0",
"tsd-check": "^0.3.0",
"typescript": "^3.3.3333",
"xo": "*"

@@ -26,7 +33,17 @@ },

],
"files": [
"index.js",
"index.d.ts"
],
"xo": {
"extends": "xo-typescript",
"extensions": [
"ts"
],
"envs": "browser",
"esnext": false,
"rules": {
"valid-jsdoc": "error"
"valid-jsdoc": 0,
"prefer-arrow-callback": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-require-imports": 0
}

@@ -33,0 +50,0 @@ },

@@ -12,2 +12,4 @@ # select-dom [![gzipped size][badge-gzip]](#no-link) [![Travis build status][badge-travis]][link-travis] [![npm version][badge-version]][link-npm] [![npm downloads][badge-downloads]][link-npm]

Version 5+ only supports browsers with [`Set` support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#Browser_compatibility). If you need IE 10- support, stick to [`select-dom@4`](https://github.com/bfred-it/select-dom/tree/v4.2.1)
## Install

@@ -22,3 +24,3 @@

```js
var select = require('select-dom')
const select = require('select-dom')
```

@@ -61,3 +63,3 @@

**Note:** if a falsy value is passed as `baseElement`, you'll always get an empty result (bd578b9)
**Note:** if a falsy value is passed as `baseElement`, you'll always get an empty result ([bd578b9](https://github.com/bfred-it/select-dom/commit/bd578b975e35d9f802cb43a900a6d3c83095c76a))

@@ -64,0 +66,0 @@ ### `select(selector[, baseElement = document])`

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