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 5.0.2 to 5.1.0

28

index.d.ts

@@ -1,3 +0,2 @@

declare type BaseElement = ParentNode | Window;
declare type BaseElements = BaseElement | BaseElement[] | Iterable<BaseElement> | NodeList;
declare type BaseElements = ParentNode | ArrayLike<ParentNode>;
/**

@@ -8,14 +7,17 @@ * @param selectors One or more CSS selectors separated by commas

*/
declare function select<T extends keyof HTMLElementTagNameMap>(selectors: T, baseElement?: BaseElement): HTMLElementTagNameMap[T] | null;
declare function select<T extends keyof HTMLElementTagNameMap>(selectors: T, baseElement?: ParentNode): HTMLElementTagNameMap[T] | null;
declare namespace select {
var last: typeof selectLast;
var exists: typeof selectExists;
var all: typeof selectAll;
}
declare function select<T extends keyof SVGElementTagNameMap>(selectors: T, baseElement?: BaseElement): SVGElementTagNameMap[T] | null;
declare function select<T extends keyof SVGElementTagNameMap>(selectors: T, baseElement?: ParentNode): SVGElementTagNameMap[T] | null;
declare namespace select {
var last: typeof selectLast;
var exists: typeof selectExists;
var all: typeof selectAll;
}
declare function select<T extends HTMLElement = HTMLElement>(selectors: string, baseElement?: BaseElement): T | null;
declare function select<T extends HTMLElement = HTMLElement>(selectors: string, baseElement?: ParentNode): T | null;
declare namespace select {
var last: typeof selectLast;
var exists: typeof selectExists;

@@ -27,5 +29,13 @@ var all: typeof selectAll;

* @param [baseElement] The element to look inside of
* @return The element found, if any
*/
declare function selectLast<T extends keyof HTMLElementTagNameMap>(selectors: T, baseElement?: ParentNode): HTMLElementTagNameMap[T] | null;
declare function selectLast<T extends keyof SVGElementTagNameMap>(selectors: T, baseElement?: ParentNode): SVGElementTagNameMap[T] | null;
declare function selectLast<T extends HTMLElement = HTMLElement>(selectors: string, baseElement?: ParentNode): T | null;
/**
* @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 selectExists<T extends HTMLElement = HTMLElement>(selectors: keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap | string, baseElement?: BaseElement): boolean;
declare function selectExists(selectors: keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap | string, baseElement?: ParentNode): boolean;
/**

@@ -36,5 +46,5 @@ * @param selectors One or more CSS selectors separated by commas

*/
declare function selectAll<T extends keyof HTMLElementTagNameMap>(selectors: T, baseElements?: BaseElements): HTMLElementTagNameMap[T][];
declare function selectAll<T extends keyof SVGElementTagNameMap>(selectors: T, baseElements?: BaseElements): SVGElementTagNameMap[T][];
declare function selectAll<T extends keyof HTMLElementTagNameMap>(selectors: T, baseElements?: BaseElements): Array<HTMLElementTagNameMap[T]>;
declare function selectAll<T extends keyof SVGElementTagNameMap>(selectors: T, baseElements?: BaseElements): Array<SVGElementTagNameMap[T]>;
declare function selectAll<T extends HTMLElement = HTMLElement>(selectors: string, baseElements?: BaseElements): T[];
export default select;
export = select;
"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 });
// Type predicate for TypeScript
function isQueryable(object) {
return typeof object.querySelectorAll === 'function';
}
function select(selectors, baseElement) {

@@ -12,2 +15,15 @@ // Shortcut with specified-but-null baseElement

}
function selectLast(selectors, baseElement) {
// Shortcut with specified-but-null baseElement
if (arguments.length === 2 && !baseElement) {
return null;
}
const all = (baseElement || document).querySelectorAll(selectors);
return all[all.length - 1];
}
/**
* @param selectors One or more CSS selectors separated by commas
* @param [baseElement] The element to look inside of
* @return Whether it's been found
*/
function selectExists(selectors, baseElement) {

@@ -25,4 +41,5 @@ if (arguments.length === 2) {

// Can be: select.all('selectors') or select.all('selectors', singleElementOrDocument)
if (!baseElements || typeof baseElements.querySelectorAll === 'function') {
return new Array(...(baseElements || document).querySelectorAll(selectors));
if (!baseElements || isQueryable(baseElements)) {
const elements = (baseElements || document).querySelectorAll(selectors);
return Array.apply(null, elements);
}

@@ -36,3 +53,3 @@ const all = [];

}
// Preserves IE11 support and performs 3x better then ...all in Safari
// Preserves IE11 support and performs 3x better than `...all` in Safari
const arr = [];

@@ -44,6 +61,6 @@ all.forEach(function (v) {

}
select.last = selectLast;
select.exists = selectExists;
select.all = selectAll;
module.exports = select;
exports.default = select;
//# sourceMappingURL=index.js.map
{
"name": "select-dom",
"version": "5.0.2",
"version": "5.1.0",
"description": "Extra lightweight DOM selector helper",
"scripts": {
"test": "tsc && tsd-check && xo && browserify -p esmify test.js | tape-run",
"test": "tsc && tsd && xo && browserify -p esmify test.js | tape-run",
"prepublish-only": "tsc",

@@ -12,10 +12,10 @@ "build": "tsc",

"devDependencies": {
"@sindresorhus/tsconfig": "^0.2.1",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"@sindresorhus/tsconfig": "^0.3.0",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"browserify": "^16.2.2",
"eslint-config-xo-typescript": "^0.8.0",
"eslint-config-xo-typescript": "^0.12.0",
"esmify": "^2.1.1",
"tape": "^4.9.0",
"tape-run": "^4.0.0",
"tsd-check": "^0.3.0",
"tape-run": "^6.0.0",
"tsd": "^0.7.3",
"typescript": "^3.3.3333",

@@ -47,3 +47,5 @@ "xo": "*"

"valid-jsdoc": 0,
"prefer-arrow-callback": 0
"prefer-spread": 0,
"prefer-arrow-callback": 0,
"@typescript-eslint/prefer-for-of": 0
}

@@ -50,0 +52,0 @@ },

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

## Examples
```js

@@ -26,4 +24,15 @@ const select = require('select-dom')

### `select()`
```js
import select from 'select-dom';
```
## API
**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))
### `select(selector[, baseElement = document])`
Maps to `baseElement.querySelector(selector)`
```js

@@ -37,4 +46,10 @@ select('.foo a[href=bar]')

### `select.exists()`
### `select.last(selector[, baseElement = document])`
Like `select()`, except that it returns the last matching item on the page instead of the first one.
### `select.exists(selector[, baseElement = document])`
Tests the existence of one or more elements matching the selector. It's like `select()`, except it returns a `boolean`.
```js

@@ -48,42 +63,21 @@ select.exists('.foo a[href=bar]')

### `select.all()`
### `select.all(selector[, baseElements = document])`
Maps to `baseElements.querySelectorAll(selector)` plus:
* it always returns an array
* `baseElements` can be a list of elements to query
```js
select.all('.foo a[href=bar]')
select.all('.foo')
// => [<Element>, <Element>, <Element>]
select.all('.foo a[href=bar]', baseElement)
select.all('.foo', baseElement)
// => [<Element>, <Element>, <Element>]
select.all('.foo a[href=bar]', [baseElement1, baseElement2])
select.all('.foo', [baseElement1, baseElement2])
// => [<Element>, <Element>, <Element>]
// This is similar to jQuery([baseElement1, baseElement2]).find('.foo')
```
## API
**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))
### `select(selector[, baseElement = document])`
Maps to `baseElement.querySelector(selector)`
### `select.exists(selector[, baseElement = document])`
Tests the existence of one or more elements matching the selector.
### `select.all(selector[, baseElements = document])`
Maps to `baseElements.querySelectorAll(selector)` plus:
* it always returns an array
* baseElements can be an element, an array of elements, or NodeList
This lets you search through an existing list of elements, like:
```js
const baseElements = select.all('.baseElements').filter(Math.random);
select.all('.foo a[href=bar]', baseElements);
```
## Related

@@ -90,0 +84,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