{"id":15311906,"url":"https://github.com/arjunvegda/japanese-moji","last_synced_at":"2025-04-15T01:15:16.472Z","repository":{"id":43684703,"uuid":"456197219","full_name":"arjunvegda/japanese-moji","owner":"arjunvegda","description":"A toolkit to validate Japanese characters","archived":false,"fork":false,"pushed_at":"2022-09-25T00:59:04.000Z","size":2005,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"next","last_synced_at":"2025-03-28T13:11:56.554Z","etag":null,"topics":["cjk","fullwidth","halfwidth","hiragana","japanese","javascript","kana","kanji","regex","toolkit","tree-shakeable","typescript","validation"],"latest_commit_sha":null,"homepage":"https://japanese-moji.arjunvegda.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arjunvegda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-06T15:56:07.000Z","updated_at":"2024-03-27T14:57:14.000Z","dependencies_parsed_at":"2022-09-11T03:32:29.541Z","dependency_job_id":null,"html_url":"https://github.com/arjunvegda/japanese-moji","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunvegda%2Fjapanese-moji","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunvegda%2Fjapanese-moji/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunvegda%2Fjapanese-moji/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunvegda%2Fjapanese-moji/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arjunvegda","download_url":"https://codeload.github.com/arjunvegda/japanese-moji/tar.gz/refs/heads/next","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923724,"owners_count":21183951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cjk","fullwidth","halfwidth","hiragana","japanese","javascript","kana","kanji","regex","toolkit","tree-shakeable","typescript","validation"],"created_at":"2024-10-01T08:35:02.089Z","updated_at":"2025-04-15T01:15:16.454Z","avatar_url":"https://github.com/arjunvegda.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://japanese-moji.arjunvegda.com\"\u003e\n        \u003cimg alt=\"Japanese Moji Logo\" src=\"./docs/logo-light.svg\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.npmjs.com/package/japanese-moji\"\u003e\n      \u003cimg src=\"https://badgen.net/github/release/arjunvegda/japanese-moji/stable?cache=300\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://bundlephobia.com/package/japanese-moji\"\u003e\n      \u003cimg src=\"https://badgen.net/bundlephobia/minzip/japanese-moji@latest?cache=300\u0026color=green\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://bundlephobia.com/package/japanese-moji\"\u003e\n      \u003cimg src=\"https://badgen.net/bundlephobia/dependency-count/japanese-moji@latest?cache=300\u0026color=green\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://bundlephobia.com/package/japanese-moji\"\u003e\n      \u003cimg src=\"https://badgen.net/bundlephobia/tree-shaking/japanese-moji@latest?cache=300\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/arjunvegda/japanese-moji\"\u003e\n      \u003cimg src=\"https://codecov.io/gh/arjunvegda/japanese-moji/branch/main/graph/badge.svg?token=GZ8GBUVYD8\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://japanese-moji.arjunvegda.com\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/website-%F0%9F%8C%8E-green\" alt=\"Website\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"./LICENSE\"\u003e\n      \u003cimg src=\"https://badgen.net/npm/license/japanese-moji?color=blue\"/\u003e\n    \u003c/a\u003e\n\u003chr/\u003e\n\nThe word \"Moji\" translates to \"Character\" in English\n\n**Table of Contents**\n\n- [Features](#-features)\n- [Install](#-install)\n- [Quick start](#-quick-start)\n  - [Kanji](#kanji)\n  - [Kana](#kana)\n  - [Japanese](#japanese)\n- [Types summary](#-types-summary)\n- [Build Your Own Validators](#-build-your-own-validators)\n- [Recipes](#-recipes)\n- [Contributing](#-contributing)\n- [Changelog](#-changelog)\n\n## ✨ Features\n\n- Very small footprint with zero dependencies\n- Supports strict and threshold-based validation for Kanji, Kana, and all the Japanese characters\n  including punctuations\n- Exports easy to use score calculator for Kanji, Kana, and the rest of the Japanese characters\n- Easy to extend with customizable options and custom validator creators\n- Supports both custom single Unicode and Unicode ranges out-of-the-box\n- 100% TypeScript friendly\n- ESM, CJS, and UMD builds\n- Only pay for what you use — it is fully tree-shakable\n\n## 📦 Install\n\n### Yarn\n\n```\nyarn add japanese-moji\n```\n\n### NPM\n\n```\nnpm install --save japanese-moji\n```\n\n## 👨‍💻 Quick start\n\n### Kanji\n\nValidates Rare Kanji, Common and Uncommon Kanji, and Kanji compatibility ideographs \u003cbr/\u003e\u003cbr/\u003e\n\u003ca href=\"https://japanese-moji.arjunvegda.com/demos#kanji\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/demo-%F0%9F%9A%80-green\" alt=\"Demo\" /\u003e \u003c/a\u003e\n\n```ts\nimport { isValidKanji, isKanjiPresent, howMuchKanjiIsPresent } from 'japanese-moji';\n\n// Strict validation\nconst isValidKanjiResult = isValidKanji('some string here');\n\n// Default threshold is 85 (2nd argument)\nconst isKanjiPresentResult = isKanjiPresent('some string here', 90);\n\n// Returns % of Kanji present in a string\nconst howMuchKanjiIsPresentResult = howMuchKanjiIsPresent('some string here');\n```\n\n### Kana\n\nValidates Katakana, Half-width Katakana, and Katakana phonetic extensions \u003cbr/\u003e\u003cbr/\u003e\n\u003ca href=\"https://japanese-moji.arjunvegda.com/demos#kana\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/demo-%F0%9F%9A%80-green\" alt=\"Demo\" /\u003e \u003c/a\u003e\n\n```ts\nimport { isValidKana, isKanaPresent, howMuchKanaIsPresent } from 'japanese-moji';\n\n// Strict validation\nconst isValidKanaResult = isValidKana('some string here');\n\n// Default threshold is 85 (2nd argument)\nconst isKanaPresentResult = isKanaPresent('some string here', 90);\n\n// Returns % of Kana present in a string\nconst howMuchKanaIsPresentResult = howMuchKanaIsPresent('some string here');\n```\n\n### Japanese\n\nValidates CJK punctuations, Hiragana, Katakana, Katakana phonetic extensions, Rare Kanji, Common and\nUncommon Kanji, Kanji compatibility ideographs, Half-width Katakana forms, and Full-width (roman)\nforms including punctuations \u003cbr/\u003e\u003cbr/\u003e\n\u003ca href=\"https://japanese-moji.arjunvegda.com/demos#japanese\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/demo-%F0%9F%9A%80-green\" alt=\"Demo\" /\u003e \u003c/a\u003e\n\n```ts\nimport { isValidJapanese, isJapanesePresent, howMuchJapaneseIsPresent } from 'japanese-moji';\n\n// Strict validation\nconst isValidJapaneseResult = isValidJapanese('some string here');\n\n// Default threshold is 85 (2nd argument)\nconst isJapanesePresentResult = isJapanesePresent('some string here', 90);\n\n// Returns % of Japanese present in a string\nconst howMuchJapaneseIsPresentResult = howMuchJapaneseIsPresent('some string here');\n```\n\n## 📝 Types summary\n\n```ts\nenum CharacterSet {\n  CJKPunctuations = 'CJKPunctuations',\n  Hiragana = 'Hiragana',\n  Katakana = 'Katakana',\n  KatakanaPhoneticExtension = 'KatakanaPhoneticExtension',\n  RareKanji = 'RareKanji',\n  KanjiCompatibilityIdeographs = 'KanjiCompatibilityIdeographs',\n  CommonUncommonKanji = 'CommonUncommonKanji',\n  HalfWidthKatakana = 'HalfWidthKatakana',\n  FullWidthUpperCase = 'FullWidthUpperCase',\n  FullWidthLowerCase = 'FullWidthLowerCase',\n  FullWidthNumbers = 'FullWidthNumbers',\n  FullWidthPunctuations = 'FullWidthPunctuations',\n}\n\ninterface UnicodeRange {\n  start: string;\n  end: string;\n}\n\ninterface CreateValidatorOptions {\n  characterSets: CharacterSet[];\n  customRanges?: UnicodeRange[];\n  customUnicodes?: string[];\n}\n\ntype StrictValidator = (arg: string) =\u003e boolean;\ntype ThresholdBasedValidator = (arg: string, threshold?: number) =\u003e boolean;\ntype MatchScoreCalculator = (arg: string) =\u003e number;\n```\n\n## 🛠 Build Your Own Validators\n\nYou could create custom validators too, should the existing validators not fit your use case.\n\nThere are also ready-to-use, copy-pastable code snippets that may fit your use cases\n[here](./docs/RECIPES.md)\n\n```ts\nimport {\n  // Types\n  UnicodeRange,\n  CreateValidatorOptions,\n  StrictValidator,\n  ThresholdBasedValidator,\n  MatchScoreCalculator,\n  CharacterSet,\n\n  // Functions\n  createStrictValidator,\n  createThresholdBasedValidator,\n  createMatchScoreCalculator,\n} from 'japanese-moji';\n\n// Requires escaped unicode characters\nconst LatinUnicodeRange: UnicodeRange = {\n  start: '\\\\u0020',\n  end: '\\\\u007F',\n};\n\nconst customRanges: UnicodeRange[] = [LatinUnicodeRange];\n\n// Provide escaped unicode characters\nconst customUnicodes = ['\\\\u00A0'];\n\nconst options: CreateValidatorOptions = {\n  // Required\n  characterSets: [\n    CharacterSet.CJKPunctuations,\n    CharacterSet.Hiragana,\n    CharacterSet.Katakana,\n    CharacterSet.KatakanaPhoneticExtension,\n    CharacterSet.RareKanji,\n    CharacterSet.CommonUncommonKanji,\n    CharacterSet.KanjiCompatibilityIdeographs,\n    CharacterSet.HalfWidthKatakana,\n    CharacterSet.FullWidthUpperCase,\n    CharacterSet.FullWidthLowerCase,\n    CharacterSet.FullWidthNumbers,\n    CharacterSet.FullWidthPunctuations,\n  ],\n  customRanges, // Optional\n  customUnicodes, // Optional\n};\n\nconst isValidCustom: StrictValidator = createStrictValidator(options);\nconst isCustomPresent: ThresholdBasedValidator = createThresholdBasedValidator(options);\nconst howMuchIsCustomPresent: MatchScoreCalculator = createMatchScoreCalculator(options);\n\n// Strict validation\nconst isValidCustomResult = isValidCustom('some string here');\n\n// Default threshold is 85 (2nd argument)\nconst isCustomPresentResult = isCustomPresent('some string here', 90);\n\n// Returns % of Japanese present in a string\nconst howMuchIsCustomPresentResult = howMuchIsCustomPresent('some string here');\n```\n\n## 📚 Recipes\n\nFind code snippets containing variety of combinations that makes creating custom validators easy in\n[docs/RECIPES.md](./docs/RECIPES.md) \u003cbr/\u003e\u003cbr/\u003e\n\u003ca href=\"https://japanese-moji.arjunvegda.com/demos#custom-recipes\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/demos-%F0%9F%9A%80-green\" alt=\"Demo\" /\u003e \u003c/a\u003e\n\n## 🙌 Contributing\n\nFind contribution guides, code convention, release flows etc. in\n[CONTRIBUTING.md](./CONTRIBUTING.md)\n\n## 📄 Changelog\n\nFull change log available in the [docs/CHANGELOG.md](./docs/CHANGELOG.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjunvegda%2Fjapanese-moji","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farjunvegda%2Fjapanese-moji","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjunvegda%2Fjapanese-moji/lists"}