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

glmaths

v1.0.4

Published

Linear algebra functions for working with WebGL in TypeScript, aimed to be looking similar to GLSL code. Inspired by [`gl-matrix`](https://glmatrix.net/).

Readme

glmaths

Linear algebra functions for working with WebGL in TypeScript, aimed to be looking similar to GLSL code. Inspired by gl-matrix.

83KB minified, 18KB gzipped

How to install

You can take dist/glmaths.min.js, or install with npm:

npm install glmaths

There are also dist/cjs/ and dist/esm/ builds for different import formats.

Usage Example

// from glmaths[.min].js:
const { vec3, vec4, mat4, quat } = glmaths
// from npm:
import { vec3, vec4, mat4, quat } from 'glmaths'

const vertex = vec3(2, 1, 0)
vertex.rotateX(Math.PI / 3, vec3(0.5))

const proj = mat4.perspective(Math.PI / 2, 16 / 9, 0.001, 1000)
const view = mat4.lookAt(vec3(0, 0, -10), vec3(0), vec3(0, 0, 1))
const ndc = vertex.transformMat4(proj.mult(view))

// All types extend Float32Array, so you can pass them to webgl
gl.uniformMatrix4fv(u_proj, false, proj)

Swizzles!

.xyzw, .rgba, .stpq, .uv swizzles are supported on vec2, vec3, vec4.

0 and 1 on not first symbol are also supported, f.ex: a.x0z, b.rgb1, c.uv01.

Vector packing

You can pass vector in a vector, just like in GLSL: vec4(vec2(0, 1), 2, 3)

Operator Overloading!

If you code in TypeScript, you can opt for a fork of TypeScript to enable operator overloading in code! glmaths implements functions needed to overload these operators: + - * / % == ===

const ndc = proj * view * vertex
let model = mat4()
model *= mat4.fromRotation(Math.PI / 2, vec3(0, 1, 0))
vec4(vec2(1.0, 2.0) / 2.0 + 4.0, 0.0, 1.0) + vec4(1) * vec4(4, 2, 0, 0)

With this done, it totally looks like GLSL! :D

out argument

Like gl-matrix, all functions have out argument, but it is located at the end as an optional argument:

const a = vec3(0, 1, 2)
const b = vec3(2, 3, 4)
const c = vec3()
a.plus(b, /* out = */ c)

The idea behind glmaths is to make tinkering fun — so by default every operation returns a new copy, and you can just write a.plus(b) without thinking about memory. But when you need performance, you can pre-allocate structures and pass them as out, just like you would in gl-matrix.

You can also set glmaths.ALWAYS_COPY = false to make instance methods modify the structure in place by default, skipping the copy entirely. But this can bring confusion, hence why this is not the default:

glmaths.ALWAYS_COPY = false
const a = vec3(0, 1, 2)
const b = a.plus(5)
// a.x === 5, a was modified in place

Other number formats

glmaths supports also float64, int32, uint32 variants:

  • Float64Array: vec2d/dvec2, vec3d/dvec3, vec4d/dvec4, quatd/dquat, quat2d/dquat2, mat2d/mat2x2d/dmat2/dmat2x2, mat3d/mat3x3d/dmat3/dmat3x3, mat4d/mat4x4d/dmat4/dmat4x4
  • Int32Array: vec2i/ivec2, vec3i/ivec3, vec4i/ivec4
  • Uint32Array: vec2u/uvec2, vec3u/uvec3, vec4u/uvec4

Docs

  • EPSILON = 0.000001 — used in a.equals(b) functions
  • RANDOM = Math.random — used in .random() functions
  • ANGLE_ORDER = 'zyx' — used in Quat.fromEuler
  • ALWAYS_COPY = true
  • LEFT_HANDED = false — set to true for left handed geometry, used in mat4

Mat2: mat2, mat2d

Mat2x3: mat2x3, mat2x3d

Mat3: mat3, mat3d

Mat4: mat4, mat4d

Quat: quat, quatd

Quat2: quat2, quat2d

Vec2: vec2, vec2d, vec2i, vec2u

Vec3: vec3, vec3d, vec3i, vec3u

Vec4: vec4, vec4d, vec4i, vec4u