japanese-utils
v1.0.0
Published
Utility functions for converting between full-width and half-width ASCII characters, katakana, and romaji.
Maintainers
Readme
Japanese Utils
Japanese Utils is a JavaScript library that provides utility functions for manipulating Japanese text. This package includes functions for converting between full-width and half-width ASCII characters, katakana, and romaji, as well as functions for parsing and formatting Japanese era dates.
Features
- Convert between full-width and half-width ASCII characters.
- Convert between half-width and full-width katakana.
- Normalize Unicode strings.
- Normalize spaces in strings.
- Convert between hiragana and katakana.
- Convert romaji to katakana.
- Parse and format Japanese era dates.
Installation
To install the package, use npm:
npm install japanese-utilsUsage
Here are some examples of how to use the functions provided by the library:
Convert Full-width ASCII to Half-width ASCII
import { toHalfWidthAscii } from 'japanese-utils';
const halfWidth = toHalfWidthAscii('Hello World');
console.log(halfWidth); // Output: Hello WorldConvert Half-width Katakana to Full-width Katakana
import { toFullWidthKanaFromHalf } from 'japanese-utils';
const fullWidthKana = toFullWidthKanaFromHalf('キャ');
console.log(fullWidthKana); // Output: キャNormalize Unicode
import { normalizeUnicode } from 'japanese-utils';
const normalized = normalizeUnicode('some string', 'NFKC');
console.log(normalized);Parse Japanese Era Date
import { parseJapaneseEraDate } from 'japanese-utils';
const isoDate = parseJapaneseEraDate('令和3年5月1日');
console.log(isoDate); // Output: 2021-05-01Format Japanese Date
import { formatJapaneseDate } from 'japanese-utils';
const formattedDate = formatJapaneseDate(new Date(), { format: 'jp' });
console.log(formattedDate); // Output: Current date in Japanese formatTesting
To run the tests, use the following command:
npm testContributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.
