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

@kuriyota/locale-matcher

v0.2.0

Published

`@kuriyota/locale-matcher`

Downloads

210

Readme

Locale Matcher

@kuriyota/locale-matcher

npm

GitHub

智能语言标签匹配库,用于匹配和排序最符合用户偏好的语言标签。

A smart language tag matcher library for matching and sorting the most suitable language tags for users.

功能特性 Features

  • 支持语言-脚本-地区三级匹配(如 zh-Hans-CN
  • 基于优先级的智能排序
  • 内置常见语言变体规则(中文繁简、西里尔/拉丁字母等)
  • 100% 测试覆盖率
  • Supports language-script-region matching (e.g. zh-Hans-CN)
  • Smart sorting
  • Built-in rules for common language variants (e.g. Chinese simplified/traditional, Cyrillic/Latin letters, etc.)
  • 100% test coverage

<script> + CDN

<script src="https://cdn.jsdelivr.net/npm/@kuriyota/locale-matcher/dist/index.iife.js"></script>
<script src="https://unpkg.com/@kuriyota/locale-matcher/dist/index.iife.js"></script>
<script>
  const { matchLanguages } = window.LocaleMatcher;
  console.log(matchLanguages('zh-CN', ['zh-Hans', 'zh-Hant', 'en']));
</script>

安装 Install

npm install @kuriyota/locale-matcher
# 或
pnpm add @kuriyota/locale-matcher

使用示例 Usage

import { rank, match } from '@kuriyota/locale-matcher';

// 基本匹配 Basic Match
match('zh-CN', ['zh-Hans', 'zh-Hant', 'en']);
// => ['zh-Hans', 'zh-Hant']

// 自动推断脚本 Auto Detect Script
match('zh-TW', ['zh-Hans', 'zh-Hant', 'zh']);
// => ['zh-Hant', 'zh', 'zh-Hans']

// 多语言场景 Multi-language
match('fr', ['fr-CA', 'fr-FR', 'es']);
// => ['fr-FR', 'fr-CA']

rank('zh-TW', ['zh-Hans', 'zh-Hant', 'zh']);
/*
[
  {
    language: 'zh',
    script: 'Hant',
    region: undefined,
    fullTag: 'zh-Hant',
    score: 1000,
    matchReason: {
      scriptMatched: true,
      regionMatched: false,
      isAffinitiveRegion: false
    }
  },
  {
    language: 'zh',
    script: undefined,
    region: undefined,
    fullTag: 'zh',
    score: 500,
    matchReason: {
      scriptMatched: false,
      regionMatched: false,
      isAffinitiveRegion: false
    }
  },
  ...
]
*/

匹配规则 Match Rules

  1. 语言匹配:首先过滤出相同语言的候选
  2. 脚本匹配(优先级最高):
    • 完全匹配 +1000 分
    • 无脚本 +500 分
  3. 地区匹配
    • 完全匹配 +500 分
    • 关联地区匹配 +300 分
  4. 排序规则
    • 按总分降序
    • 按内置脚本优先级(如 Hans > Hant
    • 按内置地区优先级(如 CN > TW > HK
    • 按字母顺序