JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 902506
  • Score
    100M100P100Q204822F
  • License MIT

CSS Selector Generator

Package Exports

  • @medv/finder

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@medv/finder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

finder

finder

Build Status

CSS Selector Generator

Features

  • Generates shortest selectors
  • Unique selectors per page
  • Stable and robust selectors

Install

npm install @medv/finder

Usage

import finder from '@medv/finder'

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

Example

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

Comparison with optimal-select

optimal-select fails to generate selectors some times, and some times generates not unique selectors. finder generates more shortest selectors than optimal-select. Also optimal-select now does not have tests and we have :)

For example, on github.com page:

finder optimal-select
fails 0 42
shortest 404 38
longest .story:nth-child(3) .d-lg-flex:nth-child(2) > .width-full:nth-child(1) [class="circle d-flex flex-column flex-justify-center text-center p-4 mx-auto mt-6 mb-3 m-md-3 bg-orange box-shadow-extra-large"] [class="d-block f0-light text-white lh-condensed-ultra mb-2"]

License

MIT