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 🙏

© 2024 – Pkg Stats / Ryan Hefner

gmatrix

v1.6.0

Published

A simple library for geometrically manipulating matrices

Downloads

6

Readme

gmatrix

A simple library for geometrically manipulating matrices

Install

npm install gmatrix

Usage

For Node:

const matrix = require("gmatrix");

For browsers:

<script src="/node_modules/gmatrix/dist/gmatrix.min.js"></script>

In either case, create a matrix:

const myMatrix = matrix([
  [0, 1, 2, 3, 4],
  [5, 6, 7, 8, 9],
  [10, 11, 12, 13, 14],
  [15, 16, 17, 18, 19],
  [20, 21, 22, 23, 24]
]);
// myMatrix is now equipped with the geometric functions detailed below

toJSON

const json = myMatrix.toJSON();
// json is a two dimensional array of the matrix

width

const width = myMatrix.width();
// width is 5

height

const height = myMatrix.height();
// height is 5

get

// by index
const value = myMatrix.get(3); 
// 2

// or by row & column index
const value = myMatrix.get(0, 3);
// 3

equals

const a = matrix([
  [1, 2],
  [3, 4]
]);
const b = matrix([
  [5, 6],
  [7, 8]
]);
const equality = a.equals(b);
// false

clone

const clone = myMatrix.clone();
// clone is a new matrix that's a copy of the original

subMatrix

const sub = myMatrix.subMatrix(5, 2, 2);
// sub is a new 2x2 matrix starting from index 4
// [[5, 6],
//  [10, 11]]

surrounding

const surrounding = myMatrix.surrounding(12);
// surrounding is a new 3x3 matrix containing the elements that surrounded index 4
// [[6, 7, 8],
//  [11, 12, 13],
//  [16, 17, 18]]

forEach

myMatrix.forEach((element, index, rowIndex, columnIndex) => {
  // do something with element
  // given element's index, row index, and column index
  // return false to break early
});

forEachRow

myMatrix.forEachRow((row, rowIndex) => {
  // do something with row of elements
  // given row's index
  // return false to break early
});

map

const results = myMatrix.map((element, index, rowIndex, columnIndex) => {
  // similar to forEach but returns a 2d array of results based on what you return in the callback
  // given element's index, row index, and column index
  return element + 1;
});
// results is 2d array of each return 
// [[1, 2, 3, 4, 5], [5, 6, 7, 8, 9], etc...]

flatMap

const results = myMatrix.flatMap((element, index, rowIndex, columnIndex) => {
  // similar to forEach but returns a flattened array of results based on what you return in the callback
  // given element's index, row index, and column index
  return element; // by returning element we will be creating an flattened array of the matrix values
});
// results is flattened array of each return
// [0, 1, 2, 3, 4, 5, 6, 7, 8, etc...]

rotateLeft

const rotatedMatrix = myMatrix.rotateLeft();
// rotatedMatrix is a new matrix rotated 90 degrees to the left

rotateRight

const rotatedMatrix = myMatrix.rotateRight();
// rotatedMatrix is a new matrix rotated 90 degrees to the right

rotate180

const rotatedMatrix = myMatrix.rotate180();
// rotatedMatrix is a new matrix rotated 180 degrees

flipHorizontal

const flippedMatrix = myMatrix.flipHorizontal();
// flippedMatrix is a new matrix flipped over the horizontal axis

flipVertical

const flippedMatrix = myMatrix.flipVertical();
// flippedMatrix is a new matrix flipped over the vertical axis