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

immutable2d

v0.0.7

Published

Immutable 2D geometry library for Javascript/Typescript

Downloads

16

Readme

immutable2d

Build Status codecov Downloads Hits Version Dependencies Status GitHub license

Immutable 2D geometry library for Javascript/Typescript.

Features

  • 2D geometry primitives and functions:
    • [X] Vector
    • [ ] Point
    • [ ] Box
    • [ ] Circle
    • [ ] Polygon
  • Type definitions.
  • Composable functions.
  • High performance.
  • 100% Test coverage.

Installation

npm

npm install immutable2d

CommonJS:

const { add, negate, Vector } = require('immutable2d/vector')

Typescript:

import { add, negate, Vector } from 'immutable2d/vector'

ES6 (module):

import { add, negate, Vector } from 'immutable2d/lib-esm/vector'

CDN

For CDN, you can use unpkg:

https://unpkg.com/immutable2d/dist/immutable2d.min.js

Or jsdelivr:

https://cdn.jsdelivr.net/npm/immutable2d/dist/immutable2d.min.js

const { add, negate, Vector } = immutable2d.vector

Usage

Note: This is work in progress.

Vectors

Creation

import { toVector, Vector } from 'immutable2d/vector'

const x = 10
const y = 10

const v1 = new Vector(x, y)
const v2 = new Vector([x, y]) // Tuples
const v3 = new Vector({ x: 10, y: 10 }) // Objects
const v4 = new Vector({ x, y }) // Objects (ES6)

// With functions
const v5 = toVector(x, y)
const v6 = toVector([x, y])
const v7 = toVector({ x, y })

Vectors can also be created with the next functions:

Operations

  • All operations are static for ease of composability.
  • All operations work with VectorLike objects. These objects are either a tuple (an array with at least two elements, in Javascript) or an object with x and y properties.
  • Many operations have corresponding X and Y functions, that only operate over the specified component. e.g. negateX only negates the X component.
import { add, addX, Vector } from 'immutable2d/vector'

const v1 = new Vector(10, 10)

const v3 = add({ x: 20, y: 20 }, v1) // Vector { x: 30, y: 30 }
const v4 = addX(v1, [30, 30]) // Vector { x: 40, y: 10 }
  • Unary operators:
    • flip: Flips the components of the vector.
    • length: Gets the length of the vector.
    • lengthSquared: Gets the squared length of a Vector.
    • negate: Negates both components.
    • normalize: Normalizes a vector.
    • rotate: Rotates the vector by a rotation angle given in degrees.
    • rotateRadians: Same as rotate, but in radians.
  • Binary operators:
    • Basic:
      • add: Adds two vectors component-wise.
      • substract: Substracts a vector from another component-wise.
      • multiply: Multiplies each component by a number.
      • divide: Divides each component by a number.
      • dotProduct: Returns the dot product of two vectors.
    • Functional (curried by default):
      • fold: Applies a binary function with both components of a vector.
      • map: Applies a function to each component of a vector.
      • zipWith: Returns a Vector whose components are the result of applying a binary function component-wise.

The fold, map and zipWith functions let you define custom operators easily. In fact, many operations can be defined in terms of these three:

import { flip, map, toVector, zipWith } from 'immutable2d/vector'

const flip2 = fold((x, y) => toVector(y, x))
const negate2 = map(a => -a)
const add2 = zipWith((a, b) => a + b)

Note that the actual implementations are a little different; this is to allow to define all the map and zipWith based operations in one line.

See map based functions source
See zipWith based functions source