@alidev/text-select
v1.0.1
Published
A library to select any text on a web page without dependencies
Downloads
11
Maintainers
Readme
text-select
text-select
is a tiny library to select text on web page.
Compared to other solutions, text-select
can not only select text of HTML elements but you can also select a substring.
text-select
can also be used in end-to-end tests (e.g. using Protractor or TestCafe) to select text during tests.
Features
- Works in browsers and NPM-based projects (e.g. React applications)
- Select whole text of an element or just select part of it
- TypeScript support (e.g. handy for Angular projects)
- Can be used in end-to-end tests
- Tiny size (~1 KB)
Installation
- If you are using NPM:
npm install @alidev/text-select
- You can also include the script directly. Just download the script from the dist folder.
Get started
- Usage in NPM:
import {selectElementText, selectText} from '@alidev/text-select/dist';
selectElementText(document.getElementById('intro-header'));
- Usage in the browser:
<script src="text-select.bundle.js"></script>
TextSelect.selectElementText(document.getElementById('intro-header'));
Compatibility:
- Every decent web browser (Chrome, Firefox, Safari, Opera, Microsoft Edge, IE11)
Examples
- See the demo.html file for a simple example.
Local development setup
- Download the repository.
- Get Node.js and install it if you haven't already.
- Use
npm install
to install the necessary dependencies. - The source code is written in TypeScript in the
src
directory. - Run
npm run build
to build the library. - Run
npm test
to run the e2e tests.
Contribution
Pull requests and feature requests are welcome!