Convert Japanese characters between full-width (全角) and half-width (半角) including Katakana, numbers, and punctuation
npm install japanese-fullhalf-convertbash
npm install japanese-fullhalf-convert
`
$3
`html
`
$3
`javascript
import { toHalfWidth, toFullWidth } from 'japanese-fullhalf-convert';
`
Usage
$3
`javascript
const { toHalfWidth, toFullWidth } = require('japanese-fullhalf-convert');
// Convert full-width to half-width
const fullWidth = 'カタカナ123';
const halfWidth = toHalfWidth(fullWidth);
console.log(halfWidth); // Output: カタカナ123
// Convert half-width to full-width
const halfWidth2 = 'カタカナ123';
const fullWidth2 = toFullWidth(halfWidth2);
console.log(fullWidth2); // Output: カタカナ123
// Examples with different character types
console.log(toHalfWidth('HELLO')); // Output: HELLO
console.log(toFullWidth('hello')); // Output: hello
console.log(toHalfWidth(' ')); // Full-width space -> half-width space
console.log(toFullWidth(' ')); // Half-width space -> full-width space
`
$3
`javascript
import { toHalfWidth, toFullWidth } from 'japanese-fullhalf-convert';
const result = toHalfWidth('カタカナ123');
console.log(result); // Output: カタカナ123
`
$3
`html
`
$3
`html
`
API
$3
Converts full-width Japanese characters to half-width.
Parameters:
- str (string): Input string with full-width characters
Returns:
- (string): String with half-width characters
Example:
`javascript
toHalfWidth('カタカナ123'); // Returns: 'カタカナ123'
`
$3
Converts half-width Japanese characters to full-width.
Parameters:
- str (string): Input string with half-width characters
Returns:
- (string): String with full-width characters
Example:
`javascript
toFullWidth('カタカナ123'); // Returns: 'カタカナ123'
``