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

vectorx

v3.3.1

Published

2d and 3d vector using the same code

Downloads

63

Readme

Vector2D and Vector3D class for all your vector needs

A vector2D and vector3D class that hold probably any vector operation that you would ever need(knock on wood).
1 feature that javascript doesn't have is is generics or templates which is what i was hoping to work around using javascript classes.
nearly all methods return themselve again so chaining methods together is more than possible.

example to invert a vector and add 3 to it

//var Vector2 = require('vectorx').Vector2
var Vector3 = require('vectorx').Vector3

var myVector = new Vector3(10,5,2);
var changedVecor = myVector.c().scale(-1).add(new Vector3(3,0,0))

notice the .c() that method makes a copy of myVector otherwise myVector and changedVector wuld point to the same object.

shared methods

add(vector)
adds another vector to this one modifying itself

sub(vector)
subtracts another vector from this one modifiying itself

scale(number)
scales this factor by a number(scalar) modifying itself

normalize()
sets this vectors length to 1

length()
calculates the length of this vector

lerp(vector, weight)
linearly interpolates to the second vector

project(vector)
projects this vector onto another one modifying itself

dot(vector)
calculates the dot product of this and the other vector

c()
make a copy of this vector and returns the copy

equals(vector)
returns true if all fieds are equal to the other vector and false otherwise

overwrite(vector)
sets this vector's values to the other one

iterate(callback(i))
calls the callback as many times as the vector has dimensions. mainly meant to replace this code construct

for(var i = 0; i < this.dimensions;i++){
    console.log(this.get(i))
}

with this

return this.iterate((i) => console.log(this.get(i)))

loop(callback(array))
calls the callback once with each possible combination of the values. very useful with 2d vectors and 2d arrays so you dont have to write that nested for loop. replaces this code construct

for(int x = 0; x < vector.x; x++){
    for(int y = 0; y < vector.y; y++){
        //some code that can now be replaced with the callback
        console.log(`x:${x}, y:${y}`)
    }
}

becomes

myvector.loop((array) => {
    console.log(`x:${array[0]}, y:${array[1]}`)
})

get(i)
gets the corresponding value of the vector x being 0, y 1 and z 2 very useful in combination with iterate

set(i, value)
sets the corresponding value of the vector just like get and sets it to the passed in value very useful in combination with iterate

toArray()
returns an the vector in array form

static fromArray(array)
turns an array into a vector

2d

draw(2DcanvasContext)
draws the vector on the passed in graphicsContect

3d

cross(vector)
calculates the cross product and returns it as a new vector