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

simple-matrix-js

v1.0.0

Published

A simple matrix library for sudoku and board games

Readme

simple-matrix

一个用于数独和棋类游戏的简单矩阵操作库。

安装

npm install simple-matrix

使用

import { SimpleMatrix } from 'simple-matrix';

// 创建一个矩阵(支持空值配置)
const matrix = new SimpleMatrix([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
], { emptyValue: 0 }); // 配置空值为 0

// 基本操作
const row = matrix.getRow(0); // 获取第0行
const col = matrix.getCol(1); // 获取第1列
const around = matrix.getRound([1, 1]); // 获取周围8个元素
const subGrid = matrix.getSubGrid([1, 1], 3); // 获取3x3宫格

// 斜线操作(五子棋场景)
const diagonal = matrix.getDiagonalBidirectional([2, 2], 2, 2); // 左上2格+右下2格

// 值操作
matrix.setValue([0, 0], 10); // 设置值
matrix.clearValue([0, 0]); // 清空值(自动使用 emptyValue: 0)

// 批量操作
matrix.forEach((val, x, y) => console.log(val, x, y));
const doubled = matrix.map(v => v * 2);
const evens = matrix.filter(v => v % 2 === 0);

// 查找和统计
const found = matrix.find(v => v > 5);
const count = matrix.countValue(5); // 统计值为5的元素数量

// 行列修改
matrix.insertRow(1, [10, 11, 12]);
matrix.deleteRow(0);
matrix.insertCol(1, [20, 21, 22]);
matrix.deleteCol(0);

// 拷贝操作
const cloned = matrix.clone(); // 深拷贝
const array = matrix.toArray(); // 导出为数组

✨ 主要功能

基本操作

  • ✅ 获取行、列、周围元素
  • ✅ 获取相对位置元素
  • ✅ 获取九宫格(子矩阵)

斜线和行列操作

  • ✅ 获取斜线元素(四个方向)
  • ✅ 带范围限制的线获取(五子棋友好)
  • ✅ 双向行/列获取

元素操作

  • ✅ 元素移动和交换
  • ✅ 设置和清空值
  • ✅ 空值配置(emptyValue)

批量操作

  • ✅ forEach、map、filter
  • ✅ find、findAll
  • ✅ count、countValue

结构操作

  • ✅ 插入/删除行
  • ✅ 插入/删除列

工具功能

  • ✅ 深拷贝(clone)
  • ✅ 导出为数组(toArray)
  • ✅ 格式化打印矩阵

API 文档

详细 API 文档:https://www.yuque.com/leeyamaster/simple-matrix.js/

本地文档:查看 doc/API.mddoc/demo.html

License

MIT