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

gb-mahjong-js

v2.2.1

Published

gb-mahjong-js是一个国标麻将的js库,实现了麻将中的一些基本类型的封装,提供了算番、计算听牌等多种实用工具。

Readme

gb-mahjong-js NPM version Build Status Dependency Status Coverage percentage

gb-mahjong-js 是一个国标麻将 Node.js 库,提供手牌字符串解析、听牌计算、和牌判断与算番能力。

Installation

npm install --save gb-mahjong-js

Usage

算番示例

const { Fan, Handtiles } = require("gb-mahjong-js");

const handtiles = new Handtiles();
handtiles.StringToHandtiles("[EEE,2][SSSS,1]WWWNN55pN|EE1000");

const fan = new Fan();
fan.CountFan(handtiles);

console.log(handtiles.HandtilesToString());
console.log(fan.tot_fan_res);
console.log(fan.CalcTing(handtiles).map(tile => tile.GetId()));

向听数计算示例

const { Handtiles, Shanten } = require("gb-mahjong-js");

const handtiles = new Handtiles();
handtiles.StringToHandtiles("23468m25s3888899p ");

console.log("手牌:", handtiles.HandtilesToString());

const result = Shanten.calcAll(handtiles);

console.log("向听数:");
console.log("  一般型:", result.normal);
console.log("  七对子:", result.qidui);
console.log("  十三幺:", result.shisanyao);
console.log("  全不靠:", result.quanbukao);
console.log("  组合龙:", result.zuhelong);

console.log("进张信息:");
if (result.waits.length > 0) {
  console.log("  最优进张:", result.waits[0]);
}

API

  • Handtiles
    • StringToHandtiles(input):解析国标麻将字符串,成功返回 0,失败返回与 C++ 版一致的错误码。
    • HandtilesToString():输出标准化后的手牌字符串。
    • DrawTile(tile) / SetTile(tile) / DiscardTile():操作最后一张立牌。
  • Fan
    • JudgeHu(handtiles):判断当前是否和牌。
    • JudgeHuTile(handtiles, tile):判断补上某张牌后是否和牌。
    • CalcTing(handtiles):计算听牌。
    • CountFan(handtiles):计算番种,并把结果写入 tot_fan_resfan_table_res
  • Shanten
    • calcAll(handtiles, opt):计算所有牌型的向听数,返回 { normal, qidui, shisanyao, quanbukao, zuhelong, waits, details }
      • opt.modes:可选,指定计算的牌型,如 ["normal", "qidui"]
      • opt.remain:可选,指定剩余牌数数组。
    • 返回值:
      • normal:一般型向听数。
      • qidui:七对子向听数。
      • shisanyao:十三幺向听数。
      • quanbukao:全不靠向听数。
      • zuhelong:组合龙向听数。
      • waits:进张信息数组。
      • details:各牌型详细信息。

详细API文档请参考 docs/shanten-api.md

Notes

  • 当前 Fan 层通过本地 C++ bridge 调用 third_party/GB-Mahjong 核心,以保持与上游规则和测试结果一致。
  • HandtilesTilePack 与常量层已在 Node.js 侧提供兼容接口。

License

MIT © Choimoe