npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dom-selection

v0.3.3

Published

A lightweight (1kb), cross-browser library for DOM selections and ranges. IE9+

Downloads

17

Readme

dom-selection Build Status

A lightweight (1kb), cross-browser library for DOM selections and ranges. IE9+

Install

$ npm install --save dom-selection

Multiple module systems are included:

  • CommonJS (dist/dom-selection.js) - This is the main/default entry. Use as a regular Node module.
  • UMD (dist/dom-selection.min.js) - This is exposed as the umd:main entry. It's also minified & can be used in the browser.
  • ES6 (dist/dom-selection.es.js) - This is exposed as the module entry. Easier for code-splitting bundlers like Rollup or Webpack.

Usage

This package is available as a UMD and a CommonJS module, so you may import it directly into your JavaScript:

const domSel = require('dom-selection');

Or you may import it directly into your HTML markup:

<script src="dist/dom-selection.min.js"></script>
<script>
  // the 'DOMSelection' global is now available
  var range = DOMSelection.getRange();
</script>

API

The parameter [sel] indicates that an existing Selection object may be provided. By default, the current, active Selection will be used if available.

getRange([sel])

Get a Selection's Range. Returns: Range

setRange(saved, [sel])

Restore a Range to a Selection.

saved

Type: Range

The Range to apply.

getRect([sel])

Get a Selection's rectangular bounds. Returns: Object or false

getNodes([sel])

Get all Nodes within a Selection. Returns: Array

getHTML([sel])

Get the inner HTML content of a Selection. Returns: String

isCollapsed([sel])

Is there a Selection active? Returns: Boolean

collapseStart([sel])

Collapse a Selection to its beginning.

collapseEnd([sel])

Collapse a Selection to its endpoint.

isBackwards([sel])

Check if the direction of the Selection was RTL. Returns: Boolean

isWithin(container, [sel])

Is the Selection within given container Node? Returns: Boolean

container

Type: Node

The DOM element to check.

forceWithin(container, [sel])

Force/Restrict a Selection to the container & its children only.

container

Type: Node

The DOM element that should be the boundary.

expandToWord([sel])

Expand the Selection to include the full word that the Caret is (partially) within.

getCaretWord([sel])

Get the full word that the Caret is within. Returns: String

snapSelected([sel])

Force the Selection to include entire words. Can be thought of as "snap to words". No partially-selected words will occur.

License

MIT © Luke Edwards