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

@medv/finder

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@medv/finder

CSS Selector Generator

  • 4.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
105K
decreased by-4.06%
Maintainers
1
Weekly downloads
 
Created
Source

finder

finder

The CSS Selector Generator

Test JSR

Features

  • Generates shortest CSS selectors
  • Unique CSS selectors per page
  • Stable and robust CSS selectors
  • Size: 1.5kb (minified & gzipped)

Install

npm install @medv/finder

Usage

import { finder } from '@medv/finder';

document.addEventListener('click', (event) => {
  const selector = finder(event.target);
});

Example

An example of a generated selector:

.blog > article:nth-of-type(3) .add-comment

Configuration

const selector = finder(event.target, {
  root: document.body,
  timeoutMs: 1000,
});

root

Defines the root of the search. Defaults to document.body.

timeoutMs

Timeout to search for a selector. Defaults to 1000ms. After the timeout, finder fallbacks to nth-child selectors.

className

Function that determines if a class name may be used in a selector. Defaults to a word-like class names.

You can extend the default behaviour wrapping the className function:

import { finder, className } from '@medv/finder';

finder(event.target, {
  className: name => className(name) || name.startsWith('my-class-'),
});

tagName

Function that determines if a tag name may be used in a selector. Defaults to () => true.

attr

Function that determines if an attribute may be used in a selector. Defaults to a word-like attribute names and values.

You can extend the default behaviour wrapping the attr function:

import { finder, attr } from '@medv/finder';

finder(event.target, {
  attr: (name, value) => attr(name, value) || name.startsWith('data-my-attr-'),
});

idName

Function that determines if an id name may be used in a selector. Defaults to a word-like id names.

seedMinLength

Minimum length of levels in fining selector. Defaults to 3.

optimizedMinLength

Minimum length for optimising selector. Defaults to 2.

License

MIT

Keywords

FAQs

Package last updated on 13 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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