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

input-selection-model

v1.1.1

Published

A class for handling HTML input selection range tasks.

Downloads

4

Readme

input-selection-model

npm NPM npm bundle size

A class for handling HTML input selection range tasks.

Highlights

  • Supports TypeScript!
  • Supports Node and browser
  • Includes full JSDoc documentation
  • Very lightweight!
  • Contains tests

Installation

NodeJS

npm install input-selection-model --save

Browser

Import the script:

<script src="https://joker876.github.io/input-selection-model/input-selection-model.min.js">

And import the class from a global object:

new InputSelectionModel.SelectionModel(/* initial value */);

Documentation

More detailed documentation available here.

Exported members

  • SelectionModel - a class for dealing with the selection in HTML inputs and textareas
  • SelectionCoordinates - a class for dealing with line & column based coordinates in an HTML textarea
  • SelectionDirection - an enum-like object and type respresenting the direction of the selection
  • SelectionRange<T> - a type representing an object { start: T, end: T }
  • LineAndColumn - a type representing an object { line: number, col: number }
  • caretPosToLineColumn and lineColumnToCaretPos - a set of functions for converting between a singular caret position and line & column based coordinates and back
  • isSelectionRange - a type-guard function for checking if a value is a valid SelectionRange
  • posToRange - a function for unifying number and SelectionRange values (always returns a SelectionRange).

Basic Usage

import { SelectionModel } from 'input-selection-model';

const selectionModel = new SelectionModel();

SelectionModel constructor takes a single initializer that sets the selection start and end.

  • undefined - both start and end will be set to -1 (invalid state).
  • number - both start and end will be set to the provided value
  • SelectionRange<number> - the start and end values will be copied from the SelectionRange object.
  • SelectionModel - the start and end values will be copied from the other instance of SelectionModel.

Properties

  • start: number - the start position of the selection.
  • end: number - the end position of the selection.
  • previous: SelectionRange<number> - the selection range from before the last update.
  • direction: SelectionDirection - (getter) the selection direction. Can be any of none, forward, and backward.
  • size: number - (getter) the absolute difference between start and end position of the selection.

Methods

  • get(): SelectionRange - returns the selection range.

  • getOrdered(): SelectionRange - returns the selection range, with the start property always being the less than or equal to the end.

  • getPrevious(): SelectionRange - returns the selection range from before the last update.

  • set(value, direction) - sets the selection start and end to a single pos, or a range, following the direction.

  • expand(value) - expands the selection up to the provided position. Accepts a single position or a selection range.

  • setEnd(value) - sets the selection end to the provided value.

  • offset(value) - offsets the whole selection by a value, or start and end properties by their respective values from a range.

  • save() - saves the current selection so that it can be restored later.

  • restore() - restores the previously saved selection.