@guoyunhe/unique-selector
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@guoyunhe/unique-selector

Compute shortest unique selector for any DOM element in document

Forked from @cypress/unique-selector, which unluckily doesn't support ESM

Installation

npm i -S @guoyunhe/unique-selector

Usage

import unique from '@guoyunhe/unique-selector';

const button1 = document.createElement('button');
button1.classList.add('btn');
document.body.append(button1);
const button2 = document.createElement('a');
button2.classList.add('btn');
document.body.append(button2);
const link = document.createElement('a');
document.body.append(link);

unique(button1); // button
unique(button2); // a.btn
unique(link); // a:nth-child(3)

Readme

Keywords

none

Package Sidebar

Install

npm i @guoyunhe/unique-selector

Weekly Downloads

2

Version

1.0.0

License

none

Unpacked Size

21.7 kB

Total Files

28

Last publish

Collaborators

  • guoyunhe