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

@feldhaus/vector

v1.1.2

Published

A simple vector utility library

Downloads

12

Readme

@feldhaus/vector

A lightweight vector 2D utility library that provides commonly used vector operations for JavaScript and TypeScript applications.

Installation

You can install the package via npm:

npm install @feldhaus/vector

Available Functions

  • add: Adds two vectors. Source
  • sub: Subtracts the second vector from the first. Source
  • mult: Multiplies a vector by a scalar. Source
  • div: Divides a vector by a scalar. Source
  • mag: Calculates the magnitude of a vector. Source
  • magSqr: Calculates the squared magnitude of a vector. Source
  • angleBetween: Calculates the angle between two vectors. Source
  • distanceBetween: Calculates the distance between two vectors. Source
  • normalize: Normalizes a vector to have a magnitude of 1. Source
  • dot: Calculates the dot product of two vectors. Source
  • cross: Calculates the cross product of two vectors. Source
  • lerp: Linearly interpolates between two vectors. Source

Available Constants

  • VECTOR_ZERO: A constant representing the zero vector { x: 0, y: 0 }.
  • VECTOR_UP: A constant representing the unit vector pointing up { x: 0, y: 1 }.
  • VECTOR_DOWN: A constant representing the unit vector pointing down { x: 0, y: -1 }.
  • VECTOR_LEFT: A constant representing the unit vector pointing left { x: -1, y: 0 }.
  • VECTOR_RIGHT: A constant representing the unit vector pointing right { x: 1, y: 0 }.

Examples

import { add, sub, mult, div } from '@feldhaus/vector';

const vectorA = { x: 1, y: 2 };
const vectorB = { x: 3, y: 4 };

const addedVector = add(vectorA, vectorB); // Output: { x: 4, y: 6 }
const subtractedVector = sub(vectorA, vectorB); // Output: { x: -2, y: -2 }
const multipliedVector = mult(vectorA, 2); // Output: { x: 2, y: 4 }
const dividedVector = div(vectorA, 2); // Output: { x: 0.5, y: 1 }
import { mag, magSqr } from '@feldhaus/vector';

const vectorA = { x: 1, y: 2 };
const vectorB = { x: 3, y: 4 };

const magnitude = mag(vectorA); // Output: 2.23606797749979
const magnitudeSquared = magSqr(vectorA); // Output: 5
import { angleBetween, distanceBetween, fromAngle } from '@feldhaus/vector';

const vectorA = { x: 1, y: 0 };
const vectorB = { x: 0, y: 1 };

const angle = angleBetween(vectorA, vectorB); // Output: 1.5707963267948966 (which is π/2 radians or 90 degrees)
const distance = distanceBetween(vectorA, vectorB); // Output: : 1.41
const vector = fromAngle(Math.PI); // Output: { x: -1, y: 0 }
import { dot, cross } from '@feldhaus/vector';

const vectorA = { x: 1, y: 2 };
const vectorB = { x: 3, y: 4 };

const dotProduct = dot(vectorA, vectorB); // Output: 11
const crossProduct = dot(vectorA, vectorB); // Output: -2
import { lerp } from '@feldhaus/vector';

const vectorA = { x: 0, y: 0 };
const vectorB = { x: 10, y: 10 };

const interpolateVector = lerp(vectorA, vectorB, 0.5); // Output: { x: 5, y: 5 }

Usage in Browser

You can also include the library directly in your HTML file using a UMD build:

<script src="https://unpkg.com/@feldhaus/vector/dist/index.umd.js"></script>

This will expose the library as FVector on the global window object, allowing you to use the functions like this:

<script>
  const vectorA = { x: 1, y: 2 };
  const vectorB = { x: 3, y: 4 };
  const addedVector = FVector.add(vectorA, vectorB);
  console.log(addedVector); // Output: { x: 4, y: 6 }
</script>

License

MIT