• Stars
    star
    1,014
  • Rank 43,551 (Top 0.9 %)
  • Language
    HTML
  • License
    MIT License
  • Created about 6 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CSS Selector Generator ๐Ÿ—บ

Webpod - deploy JavaScript apps

finder

Test

The CSS Selector Generator

Features

  • Generates the shortest selector
  • Unique selectors per page
  • Stable and robust selectors
  • 2kB minified + gzipped

Install

npm install @medv/finder

Usage

import {finder} from '@medv/finder'

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

Example

An example of a generated selector:

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

Configuration

const selector = finder(event.target, {
  root: document.body,          // Root of search, defaults to document.body.
  idName: (name) => true,       // Check if this ID can be used.
  className: (name) => true,    // Check if this class name can be used.
  tagName: (name) => true,      // Check if tag name can be used.
  attr: (name, value) => false, // Check if attr name can be used.
  seedMinLength: 1,           
  optimizedMinLength: 2,
  threshold: 1000,
  maxNumberOfTries: 10_000,
})

seedMinLength

Minimum length of levels in fining selector. Starts from 1. For more robust selectors give this param value around 4-5 depending on depth of you DOM tree. If finder hits the root, this param is ignored.

optimizedMinLength

Minimum length for optimising selector. Starts from 2. For example selector body > div > div > p can be optimised to body p.

threshold

Max number of selectors to check before falling into nth-child usage. Checking for uniqueness of selector is very costly operation, if you have DOM tree depth of 5, with 5 classes on each level, that gives you more than 3k selectors to check. Default 1000 is good enough in most cases.

maxNumberOfTries

Max number of tries for the optimization. This is a trade-off between optimization and efficiency. Default 10_000 is good enough in most cases.

License

MIT

More Repositories

1

fx

Terminal JSON viewer
Go
16,770
star
2

expr

Expression language and expression evaluation for Go
Go
3,910
star
3

monkberry

Monkberry is a JavaScript library for building web user interfaces
JavaScript
1,496
star
4

codejar

An embeddable code editor for the browser ๐Ÿฏ
TypeScript
1,489
star
5

red

Terminal log analysis tools
Go
1,436
star
6

llama

Terminal file manager
Go
1,421
star
7

countdown

Terminal countdown timer
Go
948
star
8

numbr

Notepad + calculator
TypeScript
319
star
9

eat

Eats anything, spits out JSON ๐Ÿง€
JavaScript
287
star
10

console

Web PHP Console
PHP
268
star
11

gofx

๐Ÿพ fx-like command-line JSON processing tool
Go
233
star
12

ultra-tiny-compiler

Ultra Tiny Compiler
CoffeeScript
180
star
13

jsize

Find out minified and gzipped npm package size
JavaScript
177
star
14

fx-completion

Bash completion for fx
JavaScript
168
star
15

watch

watch tool rewritten in go
Go
153
star
16

spark

GitHub Stars Sparklines โšก๏ธ
JavaScript
129
star
17

cherimola

A very useful things.
PHP
108
star
18

silicone-skeleton

Silicone Skeleton is Silex Framework Edition Skeleton.
PHP
106
star
19

purephp

PurePHP Key-Value Storage
PHP
88
star
20

tinysh

A tiny spawn wrapper for Node.js
JavaScript
57
star
21

chat

PHP Chat Example
JavaScript
54
star
22

fast-json

Fast extraction of part of JSON
JavaScript
52
star
23

ll

Opinionated ls rewrite in Go ๐Ÿงฆ
Go
41
star
24

golang-expression-evaluation-comparison

Go expression evaluation comparison
Go
39
star
25

asciitree

Draw vertical ASCII tree
JavaScript
34
star
26

homer

Internet search engine on React PHP
JavaScript
28
star
27

damka

Russian checkers game
Go
17
star
28

svg-embed

Embed SVG code into DOM. 600 Bytes (gzip)
HTML
16
star
29

year

All unix epoch dates
JavaScript
13
star
30

silicone

Silicone - Organic Silex Framework Edition
PHP
10
star
31

gatsby-source-google-analytics-reporting-api

Gatsby source for Google Anatytics Reporting API
JavaScript
10
star
32

list

Immutable lists in JavaScript without [] and {}
JavaScript
8
star
33

is-it-cloudy

Command line tool to printing weather info ๐ŸŒฆ
JavaScript
8
star
34

prettyjson

๐Ÿงข Pretty print JSON
JavaScript
8
star
35

fx-theme-monokai

Monokai theme for fx
JavaScript
8
star
36

granula

Granula ORM
PHP
7
star
37

kot

๐ŸฑIt's a kot!
JavaScript
7
star
38

fx-theme-night

Night theme for fx
JavaScript
6
star
39

mustcheck

Must & Check
Go
5
star
40

find-npm-name

Find available npm name
JavaScript
5
star
41

lazy-chain

lazy-chain is a JavaScript utility library for ES6
JavaScript
5
star
42

morrow

A text-based role-paying game
TypeScript
3
star
43

sshlogger

SSH Logger
Go
3
star
44

numbr.dev

Numbr Private Code
1
star
45

tto

Tic-Tac-Toe game buid with @medv/list
JavaScript
1
star