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

vector-math-fp

v1.0.3

Published

A FP style curried vector calculation lib.

Readme

⭐️ What

A FP style curried vector calculation lib. (primarily for css transform rotate resize calculation)

📦 Getting Started

Installation

npm install vector-math-fp
# or
yarn add vector-math-fp

Usage

const {
    minus,
    lenOf,
    angleOf,
    rotate,
    // ...
} = require('vector-math-fp');

minus([2, 7])([3, 9]); // => [1, 2]
lenOf([3, 4]); // => 5
angleOf([1, -1]); // => -45
rotate(90, [2, 1]); // => [-1, 2]

💡 Why

It's for drag-resize-rotate and other canvas positioning calculation.

📖 Description

Rules

All curried, FP style

Vector means Array e.g. [1, 2]
Vector coordinate system is, [right, down], same as mouseEvent

Angle means Number which valid result is degree in range (-180, 180]

  • degree: 180
  • radian: Math.PI

Angle is clockwise, and start from [1, 0], same as css transform rotate

Rotate only support 2d vector

API

  • tools
    • arrToObj (['x', 'y'], [1, 2]) => ({ x: 1, y: 2 })
    • objToArr (['x', 'y'], { x: 1, y: 2 }) => ([1, 2])
    • radianToDegree Radian => Degree
    • degreeToRadian Degree => Radian
    • formatAngle Angle => Angle // in range (-180, 180]
  • math
    • minus (v1, v2) => v3
    • add (v1, v2) => v3
    • times (v1, v2) => v3
    • divide (v1, v2) => v3
    • dot (v1, v2) => Number // as len * len * cos(tha)
    • cross (v1, v2) => Number // as len * len * sin(tha)
  • verctor property
    • lenOf (v) => Number
    • areaOf (v) => Number
    • ratioOf (v) => Number // as (width / height)
  • angle and rotate
    • angleBetween (v1, v2) => Angle // from v1 to v2
    • angleOf (v) => Angle // from [1, 0] to v
    • vectorOf Angle => v // lenOf(v) is 1
    • rotate (Angle, v1) => v2
    • unRotate (Angle, v1) => v2 // === rotate(-Angle, v1)

Notice

minus add times divide support object directly calculation.

minus({ x: 2, y: 7 }, { x: 3, y: 9 }); // => { x: 1, y: 2 }

⌨️ Contribution

# git clone and cd into it
git clone https://github.com/seognil-lab/vector-math-fp

# npm command
npm i
npm run test:watch

📜 References


🕗 TODO