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 🙏

© 2025 – Pkg Stats / Ryan Hefner

veca

v1.0.0

Published

A simple 2D and 3D vector library.

Readme

veca

Veca is a simple library implementing 2-D and 3-D vectors.

Installation

From NodeJS

First, use npm install to get veca. Second, require veca like so:

const v = require('veca')

You may now use veca's v() function.

From the Browser

Simply download the file v.js from this repository, and then include it using:

<script src='v.js'></script>

You can also use RawGit's CDN:

<script src="https://cdn.rawgit.com/emctague/veca/2cae9b9a/v.js"></script>

Usage

Creating a Vector

You can create both 2-Dimensional and 3-Dimensional vectors using the v function.

v(10, 20)
// => x: 10, y: 20

v(30, 40, 50)
// => x: 30, y: 40, z: 50

Converting a Vector to a String

The str method can be used to convert a vector to a simple, readable string:

v(30, 20, 49).str()
// => "x: 30, y: 20, z: 49"

The vector will also be implicitly converted to a string:

'The vector is:' + v(5, 15)
// => "The vector is: x: 5, y: 15"

Using the Values from a Vector

You can use the x, y, and z properties to interact directly with a vector's values.

const vector = v(5, 3, 9)

vector.x
// => 5

vector.y
// => 3

vector.z
// => 9

vector.z = 10
vector.str()
// => "x: 5, y: 3, z: 10"

Getting the Number of Dimensions in a Vector

The dimens method will return 2 or 3, depending on whether or not the vector is 3-Dimensional.

v(3, 6).dimens()
// => 2

v(3, 6, 9).dimens()
// => 3

Converting a Vector to an Array or Object

The arr method converts the vector to an array.

v(93, 2).arr()
// => [ 93, 2 ]

Similarly, the obj method will convert the vector to a simple object.

v(20, 39, 42).obj()
// => { x: 20, y: 39, z: 42 }

Basic Mathematical Operations

A number of basic operations can be used on a vector to manipulate its values. Each of these methods can be called with either another vector, in which case each value will be modified using the equivalent value in the other vector, or with a single number, which will be used to modify each of the vector values.

Division is done with the div method:

v(2, 4, 6).div(2)
// => x: 1, y: 2, z: 3

v(2, 4, 6).div(v(2, 4, 3))
// => x: 1, y: 1, z: 2

Multiplication is done with the mult method:

v(2, 4, 6).mult(2)
// => x: 4, y: 8, z: 12

v(2, 4, 6).mult(v(2, 4, 3))
// => x: 4, y: 16, z: 18

Addition is done with the add method:

v(2, 4, 6).add(2)
// => x: 4, y: 6, z: 8

v(2, 4, 6).add(v(2, 4, 3))
// => x: 4, y: 8, z: 9

Subtraction is done with the sub method:

v(2, 4, 6).sub(2)
// => x: 0, y: 2, z: 4

v(2, 4, 6).div(v(2, 4, 3))
// => x: 0, y: 0, z: 3

Powers are done with the pow method:

v(2, 4, 6).pow(2)
// => x: 4, y: 16, z: 36

v(2, 4, 6).div(v(2, 4, 3))
// => x: 4, y: 256, z: 216

Modulo is done with the mod method:

v(2, 4, 6).mod(3)
// => x: 2, y: 1, z: 0

v(2, 4, 6).mod(v(2, 4, 3))
// => x: 0, y: 0, z: 0

Dot Product

The dot product can be gotten using the dot method.

v(5, 10, 15).dot(v(3, 6, 9))
// => 210

Custom Iterative Methods

Custom iterative methods, which behave in the same way as the "Basic Mathematical Operations" specified above, can be created using the iter method:

const modify = v(3, 6).iter((a, b) => a**(b/2))

modify(4)
// => x: 9, y: 36

modify(v(4, 6))
// => x: 9, y: 216