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

textlint-rule-ja-allowed-kanji

v1.0.1

Published

textlint rule that allows only specified kanji characters for Japanese.

Downloads

13

Readme

textlint-rule-ja-allowed-kanji

textlint rule that allows only specified kanji characters for Japanese.

許可された漢字のみを使用するように指摘するtextlint用ルールです。

Refs:

漢字として判定される文字については以下のリンクを参照してください。

Unicode Utilities: UnicodeSet - Han

Install

Install with npm:

Required: Node.js >= 16.0

npm install textlint-rule-ja-allowed-kanji

Usage

Via .textlintrc.json(Recommended)

{
  "rules": {
    "ja-allowed-kanji": true
  }
}

Via CLI

textlint --rule ja-allowed-kanji README.md

Options

{
    /**
     * どの漢字セットを使用するかのオプションです。
     * オプションが指定されていない場合は常用漢字のみになります。
     *
     * 人名用漢字は常用漢字を含むので、
     * 常用漢字と人名用漢字を許可する場合は`forename`を`true`にするだけでOKです。
     *
     * すべて`false`にすると「々」「〇」のみ許可されるプリセットが作成されます。
     *
     * - regular: 常用漢字
     * - forename: 人名用漢字
     * - jis1: JIS第1水準(JIS X0213)
     * - jis2: JIS第2水準(JIS X0213)
     */
    preset? : {
        regular? : boolean;
        forename? : boolean;
        jis1? : boolean;
        jis2? : boolean;
    }
    /**
     * プリセットから漢字を除外するオプションです。
     * 文字列、または文字列の配列で指定します。
     *
     * - 文字列中に改行や空白があっても問題ありません。
     * - 配列の要素は1文字だけでなくても構いません。
     */
    exclude? : string | string[];
    /**
     * プリセットに存在しない漢字を許可するオプションです。
     * 文字列、または文字列の配列で指定します。
     *
     * - 文字列中に改行や空白があっても問題ありません。
     * - 配列の要素は1文字だけでなくても構いません。
     */
    allowKanji? : string | string[];
    /**
     * プリセットに存在しない漢字を特定パターンのみ許可するオプションです。
     * 文字列の配列で指定します。
     * 
     * 正規表現を文字列として指定できます。
     * 例:"/炒(?=め)/"
     */
    allowPatterns? : string[];
}

※ 踊り字、漢数字のゼロ、二の字点、同上記号

踊り字「々」と漢数字の「〇」はどの漢字セットにも含まれませんが、自動的にプリセットに追加されます。
不要な場合はexcludeオプションで除外してください。

二の字点「〻」と同上記号「仝」はプリセットに含まれません。
必要に応じてallowKanjiオプションで許可してください。

許可する漢字を完全にコントールしたい場合

  • プリセットオプション内をすべてfalseにする
  • excludeオプションで"々〇"を指定する
  • allowKanjiオプションに使いたい漢字を設定

Options Example

たとえば、NHKの 新用字用語辞典の概要まとまる(1)[PDF] を参考に、「濫」を「氾濫」のみに限定し、「諜」を許可したいとします。
また、「炒」を「炒め」の場合のみ許可したいとします。「炒る」「炒飯」などは不許可です。

{
  "rules": {
    "ja-allowed-kanji": {
      // 常用漢字のみを使うのでpresetは指定しなくてもいい
      "exclude": "濫",
      "allowKanji": "諜",
      "allowPatterns": [
        "氾濫",
        "/炒(?=め)/"
      ]
    }
  }
}

この場合、次のテキストはいくつかのエラーが出力されます。

職権濫用の諜報から得た情報です。
川が氾濫したそうですが、今日のおかずは野菜炒めです。炒飯もあります。

豆を炒るのは明日です。

エラーの内容:

1:3   error  「濫」は "氾濫" 以外のパターンでは許可されていない漢字です。        ja-allowed-kanji
2:27  error  「炒」は "/炒(?=め)/" 以外のパターンでは許可されていない漢字です。  ja-allowed-kanji
4:3   error  「炒」は "/炒(?=め)/" 以外のパターンでは許可されていない漢字です。  ja-allowed-kanji

Build

Builds source codes for publish to the lib folder.

npm run build

Tests

Run test code in test folder. Test textlint rule by textlint-tester.

npm test

License

MIT © matori

Related rules