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

@haydn/linear-fns

v0.0.4

Published

<div align="center"> <h1> <img src="https://unpkg.com/@haydn/linear-fns/logo.png" alt="linear-fns" width="160" /> </h1> <p>A JavaScript utility library for linear algebra.</p> <p> <img alt="npm bundle size" src="https://img.shields.io/bund

Downloads

13

Readme

Features

  • Lightweight.
  • Pure functions.
  • TypeScript declarations included.
  • ESM package.

Installation

bun add @haydn/linear-fns
deno add npm:@haydn/linear-fns
npm install @haydn/linear-fns
pnpm add @haydn/linear-fns
yarn add @haydn/linear-fns

Usage

import { addVec2, lengthVec2, normalizeVec2 } from "@haydn/linear-fns";

addVec2([1, 2], [3, 4]);
//=> [4, 6]

lengthVec2([3, 4]);
//=> 5

normalizeVec2([3, 4]);
//=> [0.6, 0.8]

:toolbox: Functions

:gear: absVec2

Calculates the absolute value of a two-dimensional vector.

| Function | Type | | ---------- | ---------- | | absVec2 | (v: Vec2) => Vec2 |

Parameters:

  • v: The vector to take the absolute value of.

Returns:

The absolute value of the vector.

Examples:

absVec2([1, -2]);
//=> [1, 2]

:gear: addVec2

Sums two two-dimensional vectors.

| Function | Type | | ---------- | ---------- | | addVec2 | (v1: Vec2, v2: Vec2) => Vec2 |

Parameters:

  • v1: The first vector.
  • v2: The second vector.

Returns:

The sum of the two vectors.

Examples:

addVec2([1, 2], [3, 4]);
//=> [4, 6]

:gear: clampVec2

Clamps a two-dimensional vector between a minimum and maximum vector.

| Function | Type | | ---------- | ---------- | | clampVec2 | (v: Vec2, min: Vec2, max: Vec2) => Vec2 |

Parameters:

  • v: The vector to clamp.
  • min: The minimum vector.
  • max: The maximum vector.

Returns:

A vector with the clamped x and y values.

Examples:

clampVec2([1, 2], [0, 0], [3, 3]);
//=> [1, 2]

:gear: crossVec2

Calculates the cross product of two two-dimensional vectors.

| Function | Type | | ---------- | ---------- | | crossVec2 | (v1: Vec2, v2: Vec2) => number |

Parameters:

  • v1: The first vector.
  • v2: The second vector.

Returns:

The cross product of the two vectors.

Examples:

crossVec2([1, 2], [3, 4]);
//=> -2

:gear: dotVec2

Calculates the dot product of two two-dimensional vectors.

| Function | Type | | ---------- | ---------- | | dotVec2 | (v1: Vec2, v2: Vec2) => number |

Parameters:

  • v1: The first vector.
  • v2: The second vector.

Returns:

The dot product of the two vectors.

Examples:

dotVec2([1, 2], [3, 4]);
//=> 11

:gear: divideVec2

Divides two two-dimensional vectors.

| Function | Type | | ---------- | ---------- | | divideVec2 | (v1: Vec2, v2: Vec2) => Vec2 |

Parameters:

  • v1: The first vector.
  • v2: The second vector.

Returns:

The division of the two vectors.

Examples:

divideVec2([2, 10], [2, 2]);
//=> [1, 5]

:gear: isEqualVec2

Determines if two two-dimensional vectors are equal.

| Function | Type | | ---------- | ---------- | | isEqualVec2 | ([x1, y1]: Vec2, [x2, y2]: Vec2) => boolean |

Parameters:

  • v1: The first vector.
  • v2: The second vector.

Returns:

True if the vectors are equal, false otherwise.

Examples:

isEqualVec2([1, 2], [1, 2]);
//=> true

:gear: floorVec2

Rounds down the components of a two-dimensional vector.

| Function | Type | | ---------- | ---------- | | floorVec2 | (v: Vec2) => Vec2 |

Parameters:

  • v: The vector to round down.

Returns:

The rounded down vector.

Examples:

floorVec2([2.5, 3.7]);
//=> [2, 3]

:gear: lengthVec2

Calculates the length (magnitude) of a two-dimensional vector.

| Function | Type | | ---------- | ---------- | | lengthVec2 | (v: Vec2) => number |

Parameters:

  • v: The vector.

Returns:

The length of the vector.

Examples:

lengthVec2([3, 4]);
//=> 5

:gear: maxVec2

Finds the maximum two-dimensional vector from a list of vectors.

| Function | Type | | ---------- | ---------- | | maxVec2 | (...vectors: Vec2[]) => Vec2 |

Parameters:

  • ...vectors: The vectors to compare.

Returns:

A vector with the maximum x and y values.

Examples:

maxVec2([1, 2], [5, 1], [3, 4]);
//=> [5, 4]

:gear: minVec2

Finds the minimum two-dimensional vector from a list of vectors.

| Function | Type | | ---------- | ---------- | | minVec2 | (...vectors: Vec2[]) => Vec2 |

Parameters:

  • ...vectors: The vectors to compare.

Returns:

A vector with the minimum x and y values.

Examples:

minVec2([1, 2], [5, 1], [3, 4]);
//=> [1, 1]

:gear: modVec2

Finds the modulus of two-dimensional vectors.

| Function | Type | | ---------- | ---------- | | modVec2 | (v1: Vec2, v2: Vec2) => Vec2 |

Parameters:

  • v1: The first vector.
  • v2: The second vector.

Returns:

The modulus of the vectors.

Examples:

modVec2([5, 7], [3, 4]);
//=> [2, 3]

:gear: multiplyVec2

Multiplies two two-dimensional vectors.

| Function | Type | | ---------- | ---------- | | multiplyVec2 | (v1: Vec2, v2: Vec2) => Vec2 |

Parameters:

  • v1: The first vector.
  • v2: The second vector.

Returns:

The product of the vectors.

Examples:

multiplyVec2([2, 3], [4, 5]);
//=> [8, 15]

:gear: normalizeVec2

Normalizes a two-dimensional vector.

| Function | Type | | ---------- | ---------- | | normalizeVec2 | (v: Vec2) => Vec2 |

Parameters:

  • v: The vector.

Returns:

The normalized vector.

Examples:

normalizeVec2([3, 4]);
//=> [0.6, 0.8]

:gear: subtractVec2

Subtracts two two-dimensional vectors.

| Function | Type | | ---------- | ---------- | | subtractVec2 | (v1: Vec2, v2: Vec2) => Vec2 |

Parameters:

  • v1: The first vector.
  • v2: The second vector.

Returns:

The difference of the vectors.

Examples:

subtractVec2([5, 6], [3, 2]);
//=> [2, 4]

:gear: vec2

Constructs a two-dimensional vector.

| Function | Type | | ---------- | ---------- | | vec2 | (x: number, y?: number or undefined) => Vec2 |

Parameters:

  • x: The x-coordinate of the vector.
  • y: The y-coordinate of the vector. If not provided, defaults to the x-coordinate.

Returns:

The constructed vector.

Examples:

vec2(1, 2);
//=> [1, 2]

vec2(1);
//=> [1, 1]

:cocktail: Types

:gear: Vec2

| Type | Type | | ---------- | ---------- | | Vec2 | [number, number] |