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 🙏

© 2026 – Pkg Stats / Ryan Hefner

line2

v0.2.1

Published

perform operations on infinite lines in 2 dimensions

Readme

line2

install

npm install line2

or include it in a script tag in the browser

use


var Line = require('line2');

var l = new Line(0, 0, 10, 10);

console.log(l.slope(), l.yintercept(), l.xintercept()); // 1 0 0

api surface

Line2(x1, y1, x2, y2) or Line2(slope, yIntercept)

returns a new Line2

change(fn)

add an observer that will be notified of any change.

callback signature: function(line) {}

ignore([fn])

Removes a listener, if no fn is passed remove them all.

notify()

Call all of the listeners, manually.

yintercept([y])

return the computed y-intercept or null if verical

When y is passed it will set the y-intercept of this line and the x-intercept if appropriate (not horizontal)

xintercept([x])

return the computed x-intercept or null if horizontal

when x is passed it will set the x-intercept of this line and the y-intercept if appropriate (not vertical)

slope([slope])

return the computed slope.

When slope is passed it will set the slope of this line

note: this will be Infinity if the line is vertical

intersectSegment(x1, y1, x2, y2)

returns:

  • true when the segment is colinear with this line
  • false when the segment does not intersect with this line
  • Vec2 representing where the point of interesection

createPerpendicular(vec2)

returns a new line instance that is perpendicular to this line and goes through the provided point

intersectCircle(vec2, radius)

returns an array of Vec2s which represent the intersections.

a length of:

  • 0 means no intersections
  • 1 means the line is tangent to the provided circle
  • 2 means the line fully intersects

solveForX(y)

return the x coordinate using the provided y

solveForY(x)

return the y coordinate using the provided x

intersect(line2) or intersect(x1, y1, x2, y2)

returns a Vec2 representing the point of intersection if there was one.

If the lines are colinear, it returns true

If there is no intersection, it returns false

isHorizontal()

return boolean

isVertical()

return boolean

closestPointTo(vec2)

returns the a Vec2 representing the closest point on this line to the provided vec2

containsPoint(vec2)

returns true if the provided vec2 is on this line

license

MIT (see: license.txt)