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

@utilityjs/vector

v2.0.0

Published

An implementation of a 2D/3D Vector.

Downloads

14

Readme

UtilityJS | Vector

A 2D/3D vector implementation with mathematical operations.

Features

  • 2D and 3D Support: Works with both 2D and 3D vectors
  • Mathematical Operations: Add, subtract, multiply, dot product, cross product
  • Vector Utilities: Normalize, reflect, lerp, distance, angle calculation
  • Method Chaining: Fluent API for composing operations
  • Static Methods: Class-level operations for functional style

Installation

npm install @utilityjs/vector

or

pnpm add @utilityjs/vector

Usage

Creating Vectors

import { Vector } from "@utilityjs/vector";

const v2d = new Vector(3, 4); // 2D vector
const v3d = new Vector(1, 2, 3); // 3D vector

Basic Operations

const v1 = new Vector(1, 2);
const v2 = new Vector(3, 4);

v1.add(v2); // v1 is now (4, 6)
v1.subtract(v2); // v1 is now (1, 2)
v1.multiply(2); // v1 is now (2, 4)

Vector Math

const v1 = new Vector(3, 4);

v1.magnitude(); // 5
v1.normalize(); // unit vector
v1.dotProduct(new Vector(1, 0)); // dot product

const v2 = new Vector(1, 0, 0);
const v3 = new Vector(0, 1, 0);
v2.crossProduct(v3); // (0, 0, 1)

Static Methods

const v1 = new Vector(1, 2);
const v2 = new Vector(3, 4);

Vector.distance(v1, v2);
Vector.lerp(v1, v2, 0.5);
Vector.fromAngle(Math.PI / 4);
Vector.fromArray([1, 2, 3]);

API

Vector

Constructor

  • new Vector(x: number, y: number) - Creates a 2D vector
  • new Vector(x: number, y: number, z: number) - Creates a 3D vector

Instance Methods

  • getX(): number / setX(x): Vector - X component accessor
  • getY(): number / setY(y): Vector - Y component accessor
  • getZ(): number / setZ(z): Vector - Z component accessor
  • setAxes(x, y, z?): Vector - Set all components
  • add(vector): Vector - Add another vector
  • subtract(vector): Vector - Subtract another vector
  • multiply(vectorOrScalar): Vector - Multiply by vector or scalar
  • dotProduct(vector): number - Calculate dot product
  • crossProduct(vector): Vector - Calculate cross product
  • distance(vector): number - Calculate distance to another vector
  • angleBetween(vector): number - Calculate angle in radians
  • lerp(vector, t): Vector - Linear interpolation
  • normalize(): Vector - Normalize to unit length
  • reflect(surfaceNormal): Vector - Reflect across surface
  • reverse(): Vector - Reverse direction
  • setMagnitude(magnitude): Vector - Set magnitude preserving direction
  • magnitude(): number - Get vector length
  • squaredMagnitude(): number - Get squared length (efficient)
  • equalsTo(vector): boolean - Check equality
  • clone(): Vector - Create a copy
  • toString(): string - String representation
  • toArray(): [number, number, number] - Convert to array
  • toObject(): { x, y, z } - Convert to object

Static Methods

  • Vector.add(v1, v2): Vector - Add two vectors
  • Vector.subtract(v1, v2): Vector - Subtract vectors
  • Vector.multiply(v1, v2OrScalar): Vector - Multiply vectors
  • Vector.dotProduce(v1, v2): number - Dot product
  • Vector.crossProduct(v1, v2): Vector - Cross product
  • Vector.distance(v1, v2): number - Distance between vectors
  • Vector.lerp(v1, v2, t): Vector - Linear interpolation
  • Vector.fromAngle(angle, magnitude?): Vector - Create from angle
  • Vector.fromArray(array): Vector - Create from array

Contributing

Read the contributing guide to learn about our development process, how to propose bug fixes and improvements, and how to build and test your changes.

License

This project is licensed under the terms of the MIT license.