### Installation and Import (WanaKana) Source: https://github.com/wanikani/wanakana/blob/master/README.md Provides instructions for installing the WanaKana library using npm and demonstrates how to import its functionalities in both ES Modules and Node.js environments. This covers the basic setup for using WanaKana in modern Javascript projects. ```shell npm install wanakana ``` ```javascript import * as wanakana from 'wanakana'; // or import { toKana, isRomaji } from 'wanakana'; ``` ```javascript const wanakana = require('wanakana'); ``` -------------------------------- ### Japanese Text Conversion Utilities (WanaKana) Source: https://github.com/wanikani/wanakana/blob/master/README.md Illustrates the core text conversion functions in WanaKana: `toKana`, `toHiragana`, `toKatakana`, and `toRomaji`. It provides examples of converting between different scripts and demonstrates the use of options like `customKanaMapping`, `passRomaji`, and `useObsoleteKana`. ```javascript wanakana.toKana('ONAJI buttsuuji') // => 'オナジ ぶっつうじ' wanakana.toKana('座禅‘zazen’スタイル') // => '座禅「ざぜん」スタイル' wanakana.toKana('batsuge-mu') // => 'ばつげーむ' wanakana.toKana('wanakana', { customKanaMapping: { na: 'に', ka: 'bana' }) }); // => 'わにbanaに' wanakana.toHiragana('toukyou, オオサカ') // => 'とうきょう、 おおさか' wanakana.toHiragana('only カナ', { passRomaji: true }) // => 'only かな' wanakana.toHiragana('wi', { useObsoleteKana: true }) // => 'ゐ' wanakana.toKatakana('toukyou, おおさか') // => 'トウキョウ、 オオサカ' wanakana.toKatakana('only かな', { passRomaji: true }) // => 'only カナ' wanakana.toKatakana('wi', { useObsoleteKana: true }) // => 'ヰ' wanakana.toRomaji('ひらがな カタカナ') // => 'hiragana katakana' wanakana.toRomaji('ひらがな カタカナ', { upcaseKatakana: true }) // => 'hiragana KATAKANA' wanakana.toRomaji('つじぎり', { customRomajiMapping: { じ: 'zi', つ: 'tu', り: 'li' }) }; // => 'tuzigili' ``` -------------------------------- ### Browser Usage without Build Step (WanaKana) Source: https://github.com/wanikani/wanakana/blob/master/README.md Demonstrates how to include and use the WanaKana library directly in an HTML file for browser-based applications without a build process. It shows how to bind WanaKana's functionality to an input element for automatic text conversion. ```html ``` -------------------------------- ### Configuration Options for WanaKana Source: https://context7.com/wanikani/wanakana/llms.txt Illustrates the various configuration options available for customizing WanaKana's behavior, including kana usage, romaji handling, conversion specifics, and custom mappings. ```javascript // DefaultOptions type definition const options = { // Use obsolete kana characters (ゐ, ゑ, etc.) useObsoleteKana: false, // Pass through romaji in mixed syllabary conversions passRomaji: false, // Convert ー to extended vowels in toHiragana convertLongVowelMark: true, // Output katakana as uppercase romaji in toRomaji upcaseKatakana: false, // IME mode: true, 'toHiragana', or 'toKatakana' IMEMode: false, // Romanization system (currently only 'hepburn') romanization: 'hepburn', // Custom kana mapping for toKana customKanaMapping: { na: 'に', ka: 'bana' }, // Custom romaji mapping for toRomaji customRomajiMapping: { じ: 'zi', つ: 'tu' } }; ``` -------------------------------- ### Browser Usage with UMD Bundle Source: https://context7.com/wanikani/wanakana/llms.txt Demonstrates how to use the WanaKana UMD bundle in a web page for real-time Romaji to Japanese conversion and text detection. It includes binding to an input element and using conversion/detection functions. ```html
``` -------------------------------- ### UI Utility Functions for Layout and Resizing Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html Uses jQuery to manage UI responsiveness, specifically autosizing textareas and synchronizing table column widths between documentation sections. ```javascript function libraryColumnWidth() { var columnWidth = $('#documentation th:first-child').width(); $('#ports th:first-child').css('width', columnWidth); } $(document).ready(function () { $('form textarea').autosize(); libraryColumnWidth(); }); $(window).resize(function () { libraryColumnWidth(); }); ``` -------------------------------- ### Bind IME-style Input Handling Source: https://context7.com/wanikani/wanakana/llms.txt Attaches event listeners to DOM input elements to convert Romaji to Kana in real-time. Includes options for specific Kana modes and custom mappings. ```javascript import { bind, unbind } from 'wanakana'; const input = document.getElementById('japanese-input'); // Bind input for automatic conversion bind(input, { IMEMode: 'toKatakana' }); // Remove binding when no longer needed unbind(input); ``` -------------------------------- ### Implement Real-time Transliteration Event Listeners Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html Sets up event listeners on input fields to convert text in real-time using Wanakana methods. The output is rendered into designated HTML elements upon every input change. ```javascript var inputKana = document.getElementById('kana-to-romaji'); var outputRomaji = document.getElementById('kana-to-romaji-output'); function inputChangedKana(e) { outputRomaji.innerHTML = (wanakana.toRomaji(inputKana.value) + ' '); } inputKana.addEventListener('input', inputChangedKana); ``` -------------------------------- ### DOM Manipulation Helpers (WanaKana) Source: https://github.com/wanikani/wanakana/blob/master/README.md Details the DOM helper functions provided by WanaKana for managing text input elements. It explains how to automatically convert text using event listeners with `bind` and how to remove these listeners using `unbind`. ```javascript /*** DOM HELPERS ***/ // Automatically converts text using an eventListener on input // Sets option: { IMEMode: true } with toKana() as converter by default wanakana.bind(domElement [, options]); // Removes event listener wanakana.unbind(domElement); ``` -------------------------------- ### Bind IME to Input Element (JavaScript) Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html This snippet demonstrates how to automatically bind the IME (Input Method Editor) functionality to an HTML input element using WanaKana.js. It requires the WanaKana library to be included in the project. The `wanakana.bind()` function takes the target element as an argument. ```javascript var input = document.getElementById('ime'); wanakana.bind(input); ``` -------------------------------- ### IME Binding Functions Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html Functions for automatically binding and unbinding IME (toKana) functionality to form elements. ```APIDOC ## WanaKana IME Binding ### Description Functions to manage the Input Method Editor (IME) functionality for Japanese characters within form elements. ### bind(element [, options]) #### Description Automatically bind IME (toKana) functionality to a form textarea or input. #### Parameters - **element** (HTMLElement) - Required - The HTML element (textarea or input) to bind IME to. - **options** (object) - Optional - Configuration options for the IME binding. ### unbind(element) #### Description Unbind IME functionality from a given HTML element. #### Parameters - **element** (HTMLElement) - Required - The HTML element to unbind IME from. ``` -------------------------------- ### Bind Wanakana to HTML Elements (JavaScript) Source: https://github.com/wanikani/wanakana/blob/master/cypress/fixtures/test-input.html This JavaScript function `wkbind` demonstrates how to bind the Wanakana library to HTML input and textarea elements. It shows basic binding and binding with IME mode set to 'toKatakana'. This function is intended for use in the browser's developer console for quick testing. ```javascript // This is not used in cypress tests, this is just here as a shortcut // if you want to open this page and pop wkbind() in devtools console // to enable the inputs without having to write this out each page refresh. wkbind = () => { wanakana.bind(document.getElementById("input"), {}, true); wanakana.bind( document.getElementById("input2"), { IMEMode: "toKatakana" }, true ); wanakana.bind(document.getElementById("textarea"), {}, true); }; ``` -------------------------------- ### Conversion Functions Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html Functions for converting Japanese text between Romaji, Hiragana, and Katakana, with various options. ```APIDOC ## WanaKana Conversion Functions ### Description Functions to convert Japanese text between different writing systems (Romaji, Hiragana, Katakana) with customizable options. ### toKana(string [, options]) #### Description Converts Romaji to Kana. Outputs Hiragana by default. Uppercase input Romaji outputs Katakana. #### Parameters - **string** (string) - Required - The Romaji string to convert. - **options** (object) - Optional - Configuration options for the conversion. - **IMEMode** (boolean | 'toHiragana' | 'toKatakana') - Set true, 'toHiragana', or 'toKatakana' to convert input from a text input as it is typed. - **useObsoleteKana** (boolean) - Set true to use obsolete characters, such as ゐ and ゑ. - **passRomaji** (boolean) - Pass through romaji characters when converting. - **upcaseKatakana** (boolean) - Convert katakana to uppercase when using toRomaji(). - **convertLongVowelMark** (boolean) - Convert 'ー' (e.g., スー to すう) with toHiragana(). - **customKanaMapping** (object) - A custom map to be merged with the default kana mapping. - **customRomajiMapping** (object) - A custom map to be merged with the default romaji mapping. ### toHiragana(string [, options]) #### Description Converts Katakana or Romaji to Hiragana. #### Parameters - **string** (string) - Required - The string to convert. - **options** (object) - Optional - Configuration options (see `toKana` for available options). ### toKatakana(string [, options]) #### Description Converts Hiragana or Romaji to Katakana. #### Parameters - **string** (string) - Required - The string to convert. - **options** (object) - Optional - Configuration options (see `toKana` for available options). ### toRomaji(string [, options]) #### Description Converts Kana to Romaji. #### Parameters - **string** (string) - Required - The Kana string to convert. - **options** (object) - Optional - Configuration options (see `toKana` for available options). - **upcaseKatakana** (boolean) - Convert katakana to uppercase when using toRomaji(). - **convertLongVowelMark** (boolean) - Convert 'ー' (e.g., スー to すう) with toHiragana(). - **customKanaMapping** (object) - A custom map to be merged with the default kana mapping. - **customRomajiMapping** (object) - A custom map to be merged with the default romaji mapping. ### stripOkurigana(string [, options]) #### Description Removes trailing kana characters from a string. #### Parameters - **string** (string) - Required - The string to process. - **options** (object) - Optional - Configuration options. ### tokenize(string [, options]) #### Description Splits text into language/kana tokens. #### Parameters - **string** (string) - Required - The string to tokenize. - **options** (object) - Optional - Configuration options. ``` -------------------------------- ### Extra Utilities (WanaKana) Source: https://github.com/wanikani/wanakana/blob/master/README.md Details additional utility functions provided by WanaKana, including `stripOkurigana`, `tokenize`. `stripOkurigana` removes okurigana from Japanese words, with options for handling leading characters and matching kanji. `tokenize` splits Japanese text into meaningful segments. ```javascript /*** EXTRA UTILITIES ***/ wanakana.stripOkurigana('お祝い') // => 'お祝' wanakana.stripOkurigana('踏み込む') // => '踏み込' wanakana.stripOkurigana('お腹', { leading: true }); // => '腹' wanakana.stripOkurigana('ふみこむ', { matchKanji: '踏み込む' }); // => 'ふみこ' wanakana.stripOkurigana('おみまい', { matchKanji: 'お祝い', leading: true }); // => 'みまい' wanakana.tokenize('ふふフフ') // => ['ふふ', 'フフ'] wanakana.tokenize('hello 田中さん') // => ['hello', ' ', '田中', 'さん'] wanakana.tokenize('I said 私はすごく悲しい', { compact: true }) // => [ 'I said ', '私はすごく悲しい'] ``` -------------------------------- ### Bind Wanakana IME to Input Element Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html Initializes the Wanakana IME on a specific HTML input element. This allows users to type in Japanese characters directly into the designated field. ```javascript var inputIME = document.getElementById('ime'); wanakana.bind(inputIME); ``` -------------------------------- ### Japanese Text Checking Utilities (WanaKana) Source: https://github.com/wanikani/wanakana/blob/master/README.md Showcases the utility functions in WanaKana for identifying different types of Japanese characters and Romaji. These functions include `isJapanese`, `isKana`, `isHiragana`, `isKatakana`, `isKanji`, and `isRomaji`, useful for text validation. ```javascript wanakana.isJapanese('泣き虫。!〜2¥zenkaku') // => true wanakana.isKana('あーア') // => true wanakana.isHiragana('すげー') // => true wanakana.isKatakana('ゲーム') // => true wanakana.isKanji('切腹') // => true wanakana.isKanji('勢い') // => false wanakana.isRomaji('Tōkyō and Ōsaka') // => true ``` -------------------------------- ### Tokenize Japanese Text Source: https://context7.com/wanikani/wanakana/llms.txt Splits strings into arrays of tokens based on character type. Supports compact mode to group similar tokens and detailed mode to return objects containing type metadata. ```javascript import { tokenize } from 'wanakana'; // Basic tokenization tokenize('感じ'); // ['感', 'じ'] // Detailed mode with type information tokenize('5romaji', { detailed: true }); // => [{ type: 'englishNumeral', value: '5' }, { type: 'en', value: 'romaji' }] ``` -------------------------------- ### Strip Okurigana from Text Source: https://context7.com/wanikani/wanakana/llms.txt Removes trailing or leading hiragana (okurigana) from Japanese words. Can be configured to match against specific kanji patterns to ensure accurate stripping. ```javascript import { stripOkurigana } from 'wanakana'; // Remove trailing okurigana stripOkurigana('踏み込む'); // '踏み込' // Remove leading okurigana stripOkurigana('お腹', { leading: true }); // '腹' ``` -------------------------------- ### Convert Kana to Romaji (JavaScript) Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html Converts a string containing Japanese Kana (Hiragana and/or Katakana) back to its Romaji representation. Options can be provided to customize the conversion, such as `upcaseKatakana`. ```javascript wanakana.toRomaji(str); ``` -------------------------------- ### Convert Romaji to Hiragana (JavaScript) Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html Specifically converts a Romaji string to Hiragana. This function can also convert Katakana input to Hiragana. Options can be passed to modify the conversion behavior, such as `passRomaji`. ```javascript wanakana.toHiragana(str); ``` -------------------------------- ### Character Validation Functions Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html Utility functions to check if a given string contains only Hiragana, Katakana, or a mix of both. ```APIDOC ## WanaKana Character Validation ### Description Functions to validate the character types within a given string. ### isKana(string) #### Description Returns true if the string contains only Hiragana and/or Katakana characters. #### Parameters - **string** (string) - Required - The string to validate. ### isHiragana(string) #### Description Returns true if the string contains only Hiragana characters. Returns false if the string contains mixed characters (e.g., Hiragana and Katakana) or non-Hiragana characters. #### Parameters - **string** (string) - Required - The string to validate. ### isKatakana(string) #### Description Returns true if the string contains only Katakana characters. Returns false if the string contains mixed characters (e.g., Hiragana and Katakana) or non-Katakana characters. #### Parameters - **string** (string) - Required - The string to validate. ``` -------------------------------- ### Convert Romaji to Kana with WanaKana Source: https://context7.com/wanikani/wanakana/llms.txt The toKana function converts Romaji to Kana, mapping lowercase to Hiragana and uppercase to Katakana. It supports advanced features like long vowel handling, obsolete kana, and custom character mappings. ```javascript import { toKana } from 'wanakana'; toKana('hiragana'); // => 'ひらがな' toKana('KATAKANA'); // => 'カタカナ' toKana('onaji BUTTSUUJI'); // => 'おなじ ブッツウジ' toKana('batsuge-mu'); // => 'ばつげーむ' toKana('we', { useObsoleteKana: true }); // => 'ゑ' toKana('wanakana', { customKanaMapping: { na: 'に', ka: 'bana' } }); // => 'わにbanaに' ``` -------------------------------- ### Convert Romaji to Kana (JavaScript) Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html Converts a given string from Romaji to Japanese Kana (Hiragana or Katakana). The output defaults to Hiragana, but uppercase input or specific options can result in Katakana. This function is a core part of the IME functionality. ```javascript wanakana.toKana(str); ``` -------------------------------- ### Validate Japanese Character Types with WanaKana Source: https://context7.com/wanikani/wanakana/llms.txt Functions to verify if strings consist exclusively of Katakana, Kanji, or Romaji characters. These utilities return boolean values based on the character content of the input string. ```javascript import { isKatakana, isKanji, isRomaji, isMixed } from 'wanakana'; // Katakana check isKatakana('ゲーム'); // true // Kanji check isKanji('切腹'); // true // Romaji check with optional regex for custom characters isRomaji('a!b&cーd', /[!ー]/); // true // Mixed content check (Romaji and Kana) isMixed('Abあア'); // true ``` -------------------------------- ### Convert Romaji to Katakana (JavaScript) Source: https://github.com/wanikani/wanakana/blob/master/gh-pages/index.html Converts a Romaji string to Katakana. Similar to `toHiragana`, this function can also convert Hiragana input to Katakana. Options like `upcaseKatakana` can influence the output. ```javascript wanakana.toKatakana(str); ``` -------------------------------- ### Convert Text to Katakana Source: https://context7.com/wanikani/wanakana/llms.txt The toKatakana function converts Romaji or Hiragana text into Katakana. It supports selective conversion to preserve Romaji and handles obsolete kana characters. ```javascript import { toKatakana } from 'wanakana'; toKatakana('toukyou'); // => 'トウキョウ' toKatakana('ひらがな'); // => 'ヒラガナ' toKatakana('only かな', { passRomaji: true }); // => 'only カナ' toKatakana('wi', { useObsoleteKana: true }); // => 'ヰ' ``` -------------------------------- ### Convert Kana to Romaji Source: https://context7.com/wanikani/wanakana/llms.txt The toRomaji function converts Hiragana and Katakana into Hepburn romanization. It provides flags for uppercase Katakana output and supports custom Romaji mapping. ```javascript import { toRomaji } from 'wanakana'; toRomaji('ひらがな'); // => 'hiragana' toRomaji('カタカナ', { upcaseKatakana: true }); // => 'KATAKANA' toRomaji('つじぎり', { customRomajiMapping: { じ: 'zi', つ: 'tu', り: 'li' } }); // => 'tuzigili' ``` -------------------------------- ### Validate Japanese Characters Source: https://context7.com/wanikani/wanakana/llms.txt These functions test if input strings contain specific Japanese character sets. isJapanese checks for Kanji, Kana, and zenkaku symbols, while isKana and isHiragana provide more granular validation. ```javascript import { isJapanese, isKana, isHiragana } from 'wanakana'; isJapanese('泣き虫'); // => true isJapanese('泣き虫.!~$'); // => false isKana('あア'); // => true isHiragana('げーむ'); // => true ``` -------------------------------- ### Convert Text to Hiragana Source: https://context7.com/wanikani/wanakana/llms.txt The toHiragana function transforms Romaji or Katakana input into Hiragana. It includes options to preserve Romaji characters and control the conversion of long vowel marks. ```javascript import { toHiragana } from 'wanakana'; toHiragana('toukyou'); // => 'とうきょう' toHiragana('カタカナ'); // => 'かたかな' toHiragana('only カナ', { passRomaji: true }); // => 'only かな' toHiragana('ラーメン', { convertLongVowelMark: false }); // => 'らーめん' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.