Huge News!Announcing our $40M Series B led by Abstract Ventures.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 6.0.2 to 7.0.0-0

26

index.d.ts

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

declare type BaseElements = ParentNode | ArrayLike<ParentNode>;
declare type BaseElements = ParentNode | Iterable<ParentNode>;
/**

@@ -7,3 +7,3 @@ * @param selectors One or more CSS selectors separated by commas

*/
declare function select<T extends keyof HTMLElementTagNameMap>(selectors: T, baseElement?: ParentNode): HTMLElementTagNameMap[T] | null;
declare function select<TElement extends Element>(selectors: string | string[], baseElement?: ParentNode): TElement | undefined;
declare namespace select {

@@ -14,14 +14,2 @@ var last: typeof selectLast;

}
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 | string[], baseElement?: ParentNode): T | null;
declare namespace select {
var last: typeof selectLast;
var exists: typeof selectExists;
var all: typeof selectAll;
}
/**

@@ -32,5 +20,3 @@ * @param selectors One or more CSS selectors separated by commas

*/
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 | string[], baseElement?: ParentNode): T | null;
declare function selectLast<TElement extends Element>(selectors: string | string[], baseElement?: ParentNode): TElement | undefined;
/**

@@ -41,3 +27,3 @@ * @param selectors One or more CSS selectors separated by commas

*/
declare function selectExists(selectors: keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap | string | string[], baseElement?: ParentNode): boolean;
declare function selectExists(selectors: string | string[], baseElement?: ParentNode): boolean;
/**

@@ -48,5 +34,3 @@ * @param selectors One or more CSS selectors separated by commas

*/
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 | string[], baseElements?: BaseElements): T[];
declare function selectAll<TElement extends Element>(selectors: string | string[], baseElement?: BaseElements): TElement | undefined;
export default select;

34

index.js

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

// Types inspired by
// https://github.com/Microsoft/TypeScript/blob/9d3707d/src/lib/dom.generated.d.ts#L10581
// Type predicate for TypeScript

@@ -8,7 +6,8 @@ function isQueryable(object) {

function select(selectors, baseElement) {
var _a;
// Shortcut with specified-but-null baseElement
if (arguments.length === 2 && !baseElement) {
return null;
return;
}
return (baseElement !== null && baseElement !== void 0 ? baseElement : document).querySelector(String(selectors));
return (_a = (baseElement !== null && baseElement !== void 0 ? baseElement : document).querySelector(String(selectors))) !== null && _a !== void 0 ? _a : undefined;
}

@@ -18,3 +17,3 @@ function selectLast(selectors, baseElement) {

if (arguments.length === 2 && !baseElement) {
return null;
return undefined;
}

@@ -30,6 +29,7 @@ const all = (baseElement !== null && baseElement !== void 0 ? baseElement : document).querySelectorAll(String(selectors));

function selectExists(selectors, baseElement) {
if (arguments.length === 2) {
return Boolean(select(selectors, baseElement));
// Shortcut with specified-but-null baseElement
if (arguments.length === 2 && !baseElement) {
return false;
}
return Boolean(select(selectors));
return Boolean((baseElement !== null && baseElement !== void 0 ? baseElement : document).querySelector(String(selectors)));
}

@@ -44,17 +44,11 @@ function selectAll(selectors, baseElements) {

const elements = (baseElements !== null && baseElements !== void 0 ? baseElements : document).querySelectorAll(String(selectors));
return Array.apply(null, elements);
return [...elements];
}
const all = [];
for (let i = 0; i < baseElements.length; i++) {
const current = baseElements[i].querySelectorAll(String(selectors));
for (let ii = 0; ii < current.length; ii++) {
all.push(current[ii]);
const queried = new Set();
for (const baseElement of baseElements) {
for (const element of baseElement.querySelectorAll(String(selectors))) {
queried.add(element);
}
}
// Preserves IE11 support and performs 3x better than `...all` in Safari
const array = [];
all.forEach(function (v) {
array.push(v);
});
return array;
return [...queried]; // Convert to array
}

@@ -61,0 +55,0 @@ select.last = selectLast;

{
"name": "select-dom",
"version": "6.0.2",
"version": "7.0.0-0",
"description": "Extra lightweight DOM selector helper",

@@ -28,3 +28,4 @@ "keywords": [

"prepack": "tsc --sourceMap false",
"test": "tsc && tsd && xo && browserify -p esmify test.js | tape-run",
"test": "tsc && tsd && xo && npm run tape",
"test:tape": "browserify -p esmify test.js | tape-run",
"watch": "tsc --watch"

@@ -37,20 +38,18 @@ },

"rules": {
"@typescript-eslint/prefer-for-of": "off",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"valid-jsdoc": "off",
"prefer-spread": "off",
"prefer-arrow-callback": "off",
"unicorn/no-for-loop": "off"
"prefer-spread": "off"
}
},
"devDependencies": {
"@sindresorhus/tsconfig": "^0.7.0",
"browserify": "^16.5.1",
"@sindresorhus/tsconfig": "^0.8.0",
"browserify": "^17.0.0",
"esmify": "^2.1.1",
"tape": "^5.0.0",
"tape-run": "^7.0.0",
"tsd": "^0.11.0",
"typescript": "^3.8.3",
"xo": "^0.30.0"
"tape": "^5.0.1",
"tape-run": "^8.0.0",
"tsd": "^0.14.0",
"typescript": "^4.1.3",
"xo": "^0.36.1"
},
"dependencies": {
"typed-query-selector": "^2.1.1"
}
}

@@ -29,3 +29,3 @@ # select-dom [![][badge-gzip]][link-npm] [![npm downloads][badge-downloads]][link-npm]

Maps to `baseElement.querySelector(selector)`
Maps to `baseElement.querySelector(selector)`, except it returns `undefined` if it's not found

@@ -38,2 +38,5 @@ ```js

// => <Element>
select('.non-existent', baseElement)
// => undefined
```

@@ -40,0 +43,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