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

marker-index

v4.0.1

Published

A data structure to track logical text annotations.

Downloads

120

Readme

marker-index

This module is used by Atom to efficiently track logical locations in a text buffer as the contents of the buffer are changed.

Example

import MarkerIndex from 'marker-index'

let index = new MarkerIndex

// associate a marker id with two ordered start and end points
index.insert(1, {row: 2, column: 5}, {row: 4, column: 10})
// splice represents a change to the text file
// you pass it a starting point, then points representing the old and new extent
index.splice({row: 3, column: 5}, {row: 0, column: 0}, {row: 1, column: 0})
// the marker's end point was updated by the splice
index.getEnd(1) // => {row: 5, column: 10}

MarkerIndex API

insert (id, start, end)

Associates the given non-negative integer with a range represented by two {row: number, column: number} objects.

splice (start, oldExtent, newExtent)

Update the locations of all markers based on the description of a change to the text. The range of the replaced text is described by traversing from start by oldExtent. The range of the new text is described by traversing from start to newExtent.

Traversal means that beginning with the start location, we arrive at a new location by performing X line feeds and carriage returns and then walk forward Y columns, where X is the row of the given traversal extent and Y is its column. So basically start, oldExtent, and newExtent describe two ranges in the file, basically the spatial before and after effects of a change.

This method returns an object that describes what markers were invalidated by the change based on various invalidation strategies. If a marker is in a set for a given strategy, it was invalidated according to that strategy. The strategies are as follows:

  • touch Contains markers that the change touched in any way.
  • inside Contains markers that the change touched, but not markers with endpoints immediately adjacent to the change.
  • overlap Contains markers that had one or both of their endpoints surrounded by the change.
  • surround Contains markers that had both endpoints surrounded by the change.

setExclusive (markerId, boolean)

This method allows to control the behavior of a marker when splices start and/or end at the marker's endpoints.

By default, we consider markers to be inclusive: that is, splices exactly at the beginning of the marked range will be considered to begin inside the marker (meaning that the marker's start position will not move), and splices exactly at the end of the marked range will be considered to end inside the marker (meaning that the marker's end position will move).

Exclusive markers, on the other hand, exhibit a slightly different behavior: in fact, splices exactly at the beginning of the marked range will be considered to begin outside the marker (meaning that the marker's start position will move), and splices exactly at the end of the marked range will be considered to end outside the marker (meaning that the marker's end position will not move).

Please note that, independently of whether a marker is inclusive or exclusive, its end will always be moved when its start gets moved as a result of a splice.

isExclusive (markerId)

Returns whether the given marker id has been set to behave exclusively via setExclusive.

delete (markerId)

Removes the specified marker from the index.

getRange (markerId)

Returns the range for the given marker id, in the form of an object with start and end points.

getStart (markerId)

Returns a {row: number, column: number} object representing the start of the specified marker.

getEnd (markerId)

Returns a {row: number, column: number} object representing the end of the specified marker.

dump ()

Returns the current location of every marker in the index, represented as an object mapping marker ids to range objects. For example:

{
  '1': {start: {row: 2, column: 5}, end: {row: 5, column: 10}},
  '2': {start: {row: 4, column: 10}, end: {row: 6, column: 3}}
}

findIntersecting (start, end = start)

Returns a set with the ids of all markers intersecting the specified point range.

findContaining (start, end = start)

Returns a set with the ids of all markers intersecting the specified point range.

findContainedIn (start, end)

Returns a set with the ids of all markers contained in the specified point range.

findStartingIn (start, end)

Returns a set with the ids of all markers starting in the specified point range.

findEndingIn (start, end)

Returns a set with the ids of all markers ending in the specified point range.

findStartingAt (position)

Returns a set with the ids of all markers starting at the specified point.

findEndingAt (position)

Returns a set with the ids of all markers ending at the specified point.