Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@koozaki/romaji-conv

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@koozaki/romaji-conv - npm Package Compare versions

Comparing version 1.0.6 to 2.0.0

.github/ISSUE_TEMPLATE/bug_report.md

13

bin/romaji-conv.js

@@ -9,8 +9,13 @@ #!/usr/bin/env node

program
.option('--katakana')
.action((someString, options) => {
const instance = romajiConv(someString);
console.log(options.katakana ? instance.toKatakana() : instance.toHiragana());
});
program
.version(package.version)
.arguments('<romaji>')
.action(romaji => {
console.log(romajiConv(romaji));
})
.arguments('<someString>')
.parse(process.argv);
const romajiConv = require('../lib/index');
window['romajiConv'] = romajiConv;
window['romajiConv'] = romajiConv;

@@ -10,3 +10,3 @@ /* global test, expect */

test('window で動作する', () => {
expect(window.romajiConv('hoge')).toBe('ほげ');
expect(window.romajiConv('hoge').toHiragana()).toBe('ほげ');
});
/*!
* @name @koozaki/romaji-conv
* @version 1.0.6
* @desc Convert romaji into hiragana
* @version 2.0.0
* @desc Convert romaji into kana
* @author Kojiro Ozaki <koujirou0111@gmail.com> (https://koozaki.com/)
* @see {@link https://koozaki.com/romaji-conv/}
* @license MIT
*/!function(e){var y={};function o(u){if(y[u])return y[u].exports;var t=y[u]={i:u,l:!1,exports:{}};return e[u].call(t.exports,t,t.exports,o),t.l=!0,t.exports}o.m=e,o.c=y,o.d=function(e,y,u){o.o(e,y)||Object.defineProperty(e,y,{enumerable:!0,get:u})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,y){if(1&y&&(e=o(e)),8&y)return e;if(4&y&&"object"==typeof e&&e&&e.__esModule)return e;var u=Object.create(null);if(o.r(u),Object.defineProperty(u,"default",{enumerable:!0,value:e}),2&y&&"string"!=typeof e)for(var t in e)o.d(u,t,function(y){return e[y]}.bind(null,t));return u},o.n=function(e){var y=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(y,"a",y),y},o.o=function(e,y){return Object.prototype.hasOwnProperty.call(e,y)},o.p="",o(o.s=0)}([function(e,y,o){var u=o(1);window.romajiConv=u},function(e,y,o){var u=o(2);e.exports=function(e){return Object.keys(u).reduce((function(e,y){var o=u[y],t=new RegExp(y,"gi");return e.replace(t,o)}),e)}},function(e,y){e.exports={nn:"ん",mb:"んb",mm:"んm",mp:"んp",bb:"っb",cc:"っc",dd:"っd",ff:"っf",gg:"っg",hh:"っh",jj:"っj",kk:"っk",ll:"っl",pp:"っp",qq:"っq",rr:"っr",ss:"っs",tt:"っt",vv:"っv",ww:"っw",xx:"っx",yy:"っy",zz:"っz",ltsu:"っ",xtsu:"っ",hwyu:"ふゅ",vya:"ゔゃ",vyi:"ゔぃ",vyu:"ゔゅ",vye:"ゔぇ",vyo:"ゔょ",kya:"きゃ",kyi:"きぃ",kyu:"きゅ",kye:"きぇ",kyo:"きょ",kwa:"くぁ",kwi:"くぃ",kwu:"くぅ",kwe:"くぇ",kwo:"くぉ",gya:"ぎゃ",gyi:"ぎぃ",gyu:"ぎゅ",gye:"ぎぇ",gyo:"ぎょ",gwa:"ぐぁ",gwi:"ぐぃ",gwu:"ぐぅ",gwe:"ぐぇ",gwo:"ぐぉ",sya:"しゃ",syi:"しぃ",syu:"しゅ",sye:"しぇ",syo:"しょ",sha:"しゃ",shi:"し",shu:"しゅ",she:"しぇ",sho:"しょ",jya:"じゃ",jyi:"じぃ",jyu:"じゅ",jye:"じぇ",jyo:"じょ",zya:"じゃ",zyi:"じぃ",zyu:"じゅ",zye:"じぇ",zyo:"じょ",tsa:"つぁ",tsi:"つぃ",tsu:"つ",tse:"つぇ",tso:"つぉ",tya:"ちゃ",tyi:"ちぃ",tyu:"ちゅ",tye:"ちぇ",tyo:"ちょ",tha:"てゃ",thi:"てぃ",thu:"てゅ",the:"てぇ",tho:"てょ",cya:"ちゃ",cyi:"ちぃ",cyu:"ちゅ",cye:"ちぇ",cyo:"ちょ",cha:"ちゃ",chi:"ち",chu:"ちゅ",che:"ちぇ",cho:"ちょ",twa:"とぁ",twi:"とぃ",twu:"とぅ",twe:"とぇ",two:"とぉ",dya:"ぢゃ",dyi:"ぢぃ",dyu:"ぢゅ",dye:"ぢぇ",dyo:"ぢょ",dha:"でゃ",dhi:"でぃ",dhu:"でゅ",dhe:"でぇ",dho:"でょ",nya:"にゃ",nyi:"にぃ",nyu:"にゅ",nye:"にぇ",nyo:"にょ",hya:"ひゃ",hyi:"ひぃ",hyu:"ひゅ",hye:"ひぇ",hyo:"ひょ",hwa:"ふぁ",hwi:"ふぃ",hwe:"ふぇ",hwo:"ふぉ",fya:"ふゃ",fyu:"ふゅ",fyo:"ふょ",bya:"びゃ",byi:"びぃ",byu:"びゅ",bye:"びぇ",byo:"びょ",pya:"ぴゃ",pyi:"ぴぃ",pyu:"ぴゅ",pye:"ぴぇ",pyo:"ぴょ",mya:"みゃ",myi:"みぃ",myu:"みゅ",mye:"みぇ",myo:"みょ",rya:"りゃ",ryi:"りぃ",ryu:"りゅ",rye:"りぇ",ryo:"りょ",wha:"うぁ",whi:"うぃ",whu:"う",whe:"うぇ",who:"うぉ",ltu:"っ",xtu:"っ",lya:"ゃ",lyi:"ぃ",lyu:"ゅ",lye:"ぇ",lyo:"ょ",xya:"ゃ",xyi:"ぃ",xyu:"ゅ",xye:"ぇ",xyo:"ょ",lwa:"ゎ",xwa:"ゎ",ka:"か",ki:"き",ku:"く",ke:"け",ko:"こ",sa:"さ",si:"し",su:"す",se:"せ",so:"そ",ca:"か",ci:"し",cu:"く",ce:"せ",co:"こ",ta:"た",ti:"ち",tu:"つ",te:"て",to:"と",na:"な",ni:"に",nu:"ぬ",ne:"ね",no:"の",ha:"は",hi:"ひ",hu:"ふ",he:"へ",ho:"ほ",ma:"ま",mi:"み",mu:"む",me:"め",mo:"も",ya:"や",yu:"ゆ",yo:"よ",ra:"ら",ri:"り",ru:"る",re:"れ",ro:"ろ",wa:"わ",wi:"うぃ",wu:"う",we:"うぇ",wo:"を",qa:"くぁ",qi:"くぃ",qu:"く",qe:"くぇ",qo:"くぉ",fa:"ふぁ",fi:"ふぃ",fu:"ふ",fe:"ふぇ",fo:"ふぉ",va:"ゔぁ",vi:"ゔぃ",vu:"ゔ",ve:"ゔぇ",vo:"ゔぉ",ga:"が",gi:"ぎ",gu:"ぐ",ge:"げ",go:"ご",za:"ざ",zi:"じ",zu:"ず",ze:"ぜ",zo:"ぞ",ja:"じゃ",ji:"じ",ju:"じゅ",je:"じぇ",jo:"じょ",da:"だ",di:"ぢ",du:"づ",de:"で",do:"ど",ba:"ば",bi:"び",bu:"ぶ",be:"べ",bo:"ぼ",pa:"ぱ",pi:"ぴ",pu:"ぷ",pe:"ぺ",po:"ぽ",la:"ぁ",li:"ぃ",lu:"ぅ",le:"ぇ",lo:"ぉ",xa:"ぁ",xi:"ぃ",xu:"ぅ",xe:"ぇ",xo:"ぉ",a:"あ",i:"い",u:"う",e:"え",o:"お",n:"ん",0:"0",1:"1",2:"2",3:"3",4:"4",5:"5",6:"6",7:"7",8:"8",9:"9","-":"ー",",":"、","\\.":"。","\\!":"!","\\?":"?"}}]);
*/!function(e){var t={};function n(o){if(t[o])return t[o].exports;var a=t[o]={i:o,l:!1,exports:{}};return e[o].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(o,a,function(t){return e[t]}.bind(null,a));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){var o=n(1);window.romajiConv=o},function(e,t,n){function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}var a=n(2),r=n(3),i=n(4),u=a(i),y=function(){function e(t){if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),"string"!=typeof t)throw new TypeError('"'.concat(t,'" is not a string.'));this.someString=t,this.hiragana=this.convert(this.someString,r),this.hiragana=this.convert(this.hiragana,u),this.katakana=this.convert(this.hiragana,i)}var t,n,a;return t=e,(n=[{key:"string",value:function(){return this.someString}},{key:"convert",value:function(e,t){return Object.keys(t).reduce((function(e,n){var o=t[n],a=new RegExp(n,"gi");return e.replace(a,o)}),e)}},{key:"toHiragana",value:function(){return this.hiragana}},{key:"toKatakana",value:function(){return this.katakana}}])&&o(t.prototype,n),a&&o(t,a),e}();e.exports=function(e){return new y(e)},e.exports.toHiragana=function(e){return new y(e).toHiragana()},e.exports.toKatakana=function(e){return new y(e).toKatakana()}},function(e,t){e.exports=function(e){var t={};return Object.keys(e).forEach((function(n){var o=e[n],a=n;t[o]=a})),t}},function(e,t){e.exports={nn:"ん",mb:"んb",mm:"んm",mp:"んp",bb:"っb",cc:"っc",dd:"っd",ff:"っf",gg:"っg",hh:"っh",jj:"っj",kk:"っk",ll:"っl",pp:"っp",qq:"っq",rr:"っr",ss:"っs",tt:"っt",vv:"っv",ww:"っw",xx:"っx",yy:"っy",zz:"っz",ltsu:"っ",xtsu:"っ",hwyu:"ふゅ",vya:"ゔゃ",vyi:"ゔぃ",vyu:"ゔゅ",vye:"ゔぇ",vyo:"ゔょ",kya:"きゃ",kyi:"きぃ",kyu:"きゅ",kye:"きぇ",kyo:"きょ",kwa:"くぁ",kwi:"くぃ",kwu:"くぅ",kwe:"くぇ",kwo:"くぉ",gya:"ぎゃ",gyi:"ぎぃ",gyu:"ぎゅ",gye:"ぎぇ",gyo:"ぎょ",gwa:"ぐぁ",gwi:"ぐぃ",gwu:"ぐぅ",gwe:"ぐぇ",gwo:"ぐぉ",sya:"しゃ",syi:"しぃ",syu:"しゅ",sye:"しぇ",syo:"しょ",sha:"しゃ",shi:"し",shu:"しゅ",she:"しぇ",sho:"しょ",jya:"じゃ",jyi:"じぃ",jyu:"じゅ",jye:"じぇ",jyo:"じょ",zya:"じゃ",zyi:"じぃ",zyu:"じゅ",zye:"じぇ",zyo:"じょ",tsa:"つぁ",tsi:"つぃ",tsu:"つ",tse:"つぇ",tso:"つぉ",tya:"ちゃ",tyi:"ちぃ",tyu:"ちゅ",tye:"ちぇ",tyo:"ちょ",tha:"てゃ",thi:"てぃ",thu:"てゅ",the:"てぇ",tho:"てょ",cya:"ちゃ",cyi:"ちぃ",cyu:"ちゅ",cye:"ちぇ",cyo:"ちょ",cha:"ちゃ",chi:"ち",chu:"ちゅ",che:"ちぇ",cho:"ちょ",twa:"とぁ",twi:"とぃ",twu:"とぅ",twe:"とぇ",two:"とぉ",dya:"ぢゃ",dyi:"ぢぃ",dyu:"ぢゅ",dye:"ぢぇ",dyo:"ぢょ",dha:"でゃ",dhi:"でぃ",dhu:"でゅ",dhe:"でぇ",dho:"でょ",nya:"にゃ",nyi:"にぃ",nyu:"にゅ",nye:"にぇ",nyo:"にょ",hya:"ひゃ",hyi:"ひぃ",hyu:"ひゅ",hye:"ひぇ",hyo:"ひょ",hwa:"ふぁ",hwi:"ふぃ",hwe:"ふぇ",hwo:"ふぉ",fya:"ふゃ",fyu:"ふゅ",fyo:"ふょ",bya:"びゃ",byi:"びぃ",byu:"びゅ",bye:"びぇ",byo:"びょ",pya:"ぴゃ",pyi:"ぴぃ",pyu:"ぴゅ",pye:"ぴぇ",pyo:"ぴょ",mya:"みゃ",myi:"みぃ",myu:"みゅ",mye:"みぇ",myo:"みょ",rya:"りゃ",ryi:"りぃ",ryu:"りゅ",rye:"りぇ",ryo:"りょ",wha:"うぁ",whi:"うぃ",whu:"う",whe:"うぇ",who:"うぉ",ltu:"っ",xtu:"っ",lya:"ゃ",lyi:"ぃ",lyu:"ゅ",lye:"ぇ",lyo:"ょ",xya:"ゃ",xyi:"ぃ",xyu:"ゅ",xye:"ぇ",xyo:"ょ",lwa:"ゎ",xwa:"ゎ",ka:"か",ki:"き",ku:"く",ke:"け",ko:"こ",sa:"さ",si:"し",su:"す",se:"せ",so:"そ",ca:"か",ci:"し",cu:"く",ce:"せ",co:"こ",ta:"た",ti:"ち",tu:"つ",te:"て",to:"と",na:"な",ni:"に",nu:"ぬ",ne:"ね",no:"の",ha:"は",hi:"ひ",hu:"ふ",he:"へ",ho:"ほ",ma:"ま",mi:"み",mu:"む",me:"め",mo:"も",ya:"や",yu:"ゆ",yo:"よ",ra:"ら",ri:"り",ru:"る",re:"れ",ro:"ろ",wa:"わ",wi:"うぃ",wu:"う",we:"うぇ",wo:"を",qa:"くぁ",qi:"くぃ",qu:"く",qe:"くぇ",qo:"くぉ",fa:"ふぁ",fi:"ふぃ",fu:"ふ",fe:"ふぇ",fo:"ふぉ",va:"ゔぁ",vi:"ゔぃ",vu:"ゔ",ve:"ゔぇ",vo:"ゔぉ",ga:"が",gi:"ぎ",gu:"ぐ",ge:"げ",go:"ご",za:"ざ",zi:"じ",zu:"ず",ze:"ぜ",zo:"ぞ",ja:"じゃ",ji:"じ",ju:"じゅ",je:"じぇ",jo:"じょ",da:"だ",di:"ぢ",du:"づ",de:"で",do:"ど",ba:"ば",bi:"び",bu:"ぶ",be:"べ",bo:"ぼ",pa:"ぱ",pi:"ぴ",pu:"ぷ",pe:"ぺ",po:"ぽ",la:"ぁ",li:"ぃ",lu:"ぅ",le:"ぇ",lo:"ぉ",xa:"ぁ",xi:"ぃ",xu:"ぅ",xe:"ぇ",xo:"ぉ",a:"あ",i:"い",u:"う",e:"え",o:"お",n:"ん",0:"0",1:"1",2:"2",3:"3",4:"4",5:"5",6:"6",7:"7",8:"8",9:"9","-":"ー",",":"、","\\.":"。","\\!":"!","\\?":"?"}},function(e,t){e.exports={"あ":"ア","い":"イ","う":"ウ","え":"エ","お":"オ","か":"カ","き":"キ","く":"ク","け":"ケ","こ":"コ","さ":"サ","し":"シ","す":"ス","せ":"セ","そ":"ソ","た":"タ","ち":"チ","つ":"ツ","て":"テ","と":"ト","な":"ナ","に":"ニ","ぬ":"ヌ","ね":"ネ","の":"ノ","は":"ハ","ひ":"ヒ","ふ":"フ","へ":"ヘ","ほ":"ホ","ま":"マ","み":"ミ","む":"ム","め":"メ","も":"モ","や":"ヤ","ゆ":"ユ","よ":"ヨ","ら":"ラ","り":"リ","る":"ル","れ":"レ","ろ":"ロ","わ":"ワ","を":"ヲ","ん":"ン","ゔ":"ヴ","が":"ガ","ぎ":"ギ","ぐ":"グ","げ":"ゲ","ご":"ゴ","ざ":"ザ","じ":"ジ","ず":"ズ","ぜ":"ゼ","ぞ":"ゾ","だ":"ダ","ぢ":"ヂ","づ":"ヅ","で":"デ","ど":"ド","ば":"バ","び":"ビ","ぶ":"ブ","べ":"ベ","ぼ":"ボ","ぱ":"パ","ぴ":"ピ","ぷ":"プ","ぺ":"ペ","ぽ":"ポ","ぁ":"ァ","ぃ":"ィ","ぅ":"ゥ","ぇ":"ェ","ぉ":"ォ","ゃ":"ャ","ゅ":"ュ","ょ":"ョ","ゎ":"ヮ","っ":"ッ"}}]);

@@ -1,19 +0,100 @@

const map = require('./map');
const reverseMap = require('./reverseMap');
const mapRomaji2Hiragana = require('./map/romaji2hiragana');
const mapHiragana2Katakana = require('./map/hiragana2katakana');
const mapKatakana2Hiragana = reverseMap(mapHiragana2Katakana);
class RomajiConv {
/**
* コンストラクタ
*
* @param string someString - 変換対象の文字列
*/
constructor (someString) {
if (typeof someString !== 'string') throw new TypeError(`"${someString}" is not a string.`);
this.someString = someString;
this.hiragana = this.convert(this.someString, mapRomaji2Hiragana);
this.hiragana = this.convert(this.hiragana, mapKatakana2Hiragana);
this.katakana = this.convert(this.hiragana, mapHiragana2Katakana);
}
/**
* 変換前の文字列を返す
*
* @return string - 変換前の文字列
*/
string () {
return this.someString;
}
/**
* 文字列の変換
*
* @param string someString - ローマ字 or ひらがな or カタカナ
* @param object mapObject - マッピングオブジェクト
* @return string outputString - ひらがな or カタカナ
*/
convert (someString, mapObject) {
const outputString = Object.keys(mapObject).reduce((processingString, pattern) => {
const replacement = mapObject[pattern];
const regex = new RegExp(pattern, 'gi');
return processingString.replace(regex, replacement);
}, someString);
return outputString;
}
/**
* 変換後のひらがなを返す
*
* @return string - 変換後のひらがな
*/
toHiragana () {
return this.hiragana;
}
/**
* 変換後のカタカナを返す
*
* @return string - 変換後のカタカナ
*/
toKatakana () {
return this.katakana;
}
}
/**
* romajiConv
* RomajiConv のインスタンスを返す
*
* @param string romaji - ローマ字
* @return string hiragana - ひらがな
* @param string someString - 変換対象の文字列
* @return instance - RomajiConv のインスタンス
*/
const romajiConv = romaji => {
const hiragana = Object.keys(map).reduce((romajiHiragana, pattern) => {
const replacement = map[pattern];
const regex = new RegExp(pattern, 'gi');
return romajiHiragana.replace(regex, replacement);
}, romaji);
const romajiConv = someString => new RomajiConv(someString);
return hiragana;
/**
* 変換後のひらがなを返す
*
* @param string someString - 変換対象の文字列
* @return string - 変換後のひらがな
*/
const toHiragana = someString => {
const instance = new RomajiConv(someString);
return instance.toHiragana();
};
/**
* 変換後のカタカナを返す
*
* @param string someString - 変換対象の文字列
* @return string - 変換後のカタカナ
*/
const toKatakana = someString => {
const instance = new RomajiConv(someString);
return instance.toKatakana();
};
module.exports = romajiConv;
module.exports.toHiragana = toHiragana;
module.exports.toKatakana = toKatakana;

@@ -1,42 +0,116 @@

/* global test, expect */
const romajiConv = require('../lib/index');
/* global describe, test, beforeEach, expect */
const romajiConv = require('./index');
const { toHiragana, toKatakana } = romajiConv;
test('基本的な五十音の確認', () => {
expect(romajiConv('aiueo')).toBe('あいうえお');
expect(romajiConv('kakikukeko')).toBe('かきくけこ');
expect(romajiConv('sashisuseso')).toBe('さしすせそ');
expect(romajiConv('tachitsuteto')).toBe('たちつてと');
expect(romajiConv('naninuneno')).toBe('なにぬねの');
expect(romajiConv('hahifuheho')).toBe('はひふへほ');
expect(romajiConv('mamimumemo')).toBe('まみむめも');
expect(romajiConv('yayuyo')).toBe('やゆよ');
expect(romajiConv('rarirurero')).toBe('らりるれろ');
expect(romajiConv('wawiwuwewo')).toBe('わうぃううぇを');
expect(romajiConv('n')).toBe('ん');
expect(romajiConv('nn')).toBe('ん');
test('romajiConv は function 型', () => {
expect(typeof romajiConv).toBe('function');
});
test('基本的なIO確認', () => {
expect(romajiConv('hoge')).toBe('ほげ');
test('romajiConv は string 型の引数のみ受け付ける', () => {
expect(() => romajiConv()).toThrow(TypeError);
expect(() => romajiConv(1)).toThrow(TypeError);
expect(() => romajiConv({})).toThrow(TypeError);
});
test('訓令式とローマ式の混合', () => {
expect(romajiConv('anoinutyauchautocyauntyau?')).toBe('あのいぬちゃうちゃうとちゃうんちゃう?');
test('romajiConv インスタンスは string メソッドを持つ', () => {
expect(typeof romajiConv('hoge').string).toBe('function');
});
test('『ん』対応:nnやnyoの対応', () => {
test('romajiConv インスタンスの string メソッドは romajiConv に渡した引数を返す', () => {
const input = 'hogehoge';
expect(romajiConv(input).string()).toBe(input);
});
describe('基本的な五十音の確認', () => {
let romaji, hiragana, katakana;
let romajiInstance, hiraganaInstance, katakanaInstance;
beforeEach(() => {
romaji = '' +
'aiueokakikukekosashisusesotachitsutetonaninuneno' +
'hahifuhehomamimumemoyayuyorarirurerowawiwuwewonnn';
hiragana = '' +
'あいうえおかきくけこさしすせそたちつてとなにぬねの' +
'はひふへほまみむめもやゆよらりるれろわうぃううぇをんん';
katakana = '' +
'アイウエオカキクケコサシスセソタチツテトナニヌネノ' +
'ハヒフヘホマミムメモヤユヨラリルレロワウィウウェヲンン'
romajiInstance = romajiConv(romaji);
hiraganaInstance = romajiConv(hiragana);
katakanaInstance = romajiConv(katakana);
});
test('ローマ字→ひらがな', () => {
expect(romajiInstance.toHiragana()).toBe(hiragana);
});
test('ローマ字→ひらがな(関数版)', () => {
expect(toHiragana(romaji)).toBe(hiragana);
});
test('ローマ字→カタカナ', () => {
expect(romajiInstance.toKatakana()).toBe(katakana);
});
test('ローマ字→カタカナ(関数版)', () => {
expect(toKatakana(romaji)).toBe(katakana);
});
test('ひらがな→ひらがな', () => {
expect(hiraganaInstance.toHiragana()).toBe(hiragana);
});
test('ひらがな→ひらがな(関数版)', () => {
expect(toHiragana(hiragana)).toBe(hiragana);
});
test('ひらがな→カタカナ', () => {
expect(hiraganaInstance.toKatakana()).toBe(katakana);
});
test('ひらがな→カタカナ(関数版)', () => {
expect(toKatakana(hiragana)).toBe(katakana);
});
test('カタカナ→ひらがな', () => {
expect(katakanaInstance.toHiragana()).toBe(hiragana);
});
test('カタカナ→ひらがな(関数版)', () => {
expect(toHiragana(katakana)).toBe(hiragana);
});
test('カタカナ→カタカナ', () => {
expect(katakanaInstance.toKatakana()).toBe(katakana);
});
test('カタカナ→カタカナ(関数版)', () => {
expect(toKatakana(katakana)).toBe(katakana);
});
});
test('toHiragana: 訓令式とローマ式の混合', () => {
expect(
romajiConv('anoinutyauchautocyauntyau?').toHiragana()
).toBe('あのいぬちゃうちゃうとちゃうんちゃう?');
});
test('toHiragana: 『ん』対応:nnやnyoの対応', () => {
// 原因
expect(romajiConv('genin')).toBe('げにん');
expect(romajiConv('gennin')).toBe('げんいん');
expect(romajiConv('genninn')).toBe('げんいん');
expect(romajiConv('genin').toHiragana()).toBe('げにん');
expect(romajiConv('gennin').toHiragana()).toBe('げんいん');
expect(romajiConv('genninn').toHiragana()).toBe('げんいん');
// 信用
expect(romajiConv('shinyou')).toBe('しにょう');
expect(romajiConv('shinnyou')).toBe('しんよう');
expect(romajiConv('shinnnyou')).toBe('しんにょう');
expect(romajiConv('shinyou').toHiragana()).toBe('しにょう');
expect(romajiConv('shinnyou').toHiragana()).toBe('しんよう');
expect(romajiConv('shinnnyou').toHiragana()).toBe('しんにょう');
});
test('『ん』対応:B, M, P の前にある M は『ん』になる規則', () => {
expect(romajiConv('namba')).toBe('なんば');
expect(romajiConv('homma')).toBe('ほんま');
expect(romajiConv('sanpei')).toBe('さんぺい');
test('toHiragana: 『ん』対応:B, M, P の前にある M は『ん』になる規則', () => {
expect(romajiConv('namba').toHiragana()).toBe('なんば');
expect(romajiConv('homma').toHiragana()).toBe('ほんま');
expect(romajiConv('sanpei').toHiragana()).toBe('さんぺい');
});
{
"name": "@koozaki/romaji-conv",
"version": "1.0.6",
"description": "Convert romaji into hiragana",
"version": "2.0.0",
"description": "Convert romaji into kana",
"keywords": [
"romaji",
"kana",
"hiragana",
"katakana",
"nihongo",

@@ -12,7 +14,9 @@ "japanese",

"ローマ字",
"ひらがな"
"かな",
"ひらがな",
"カタカナ"
],
"homepage": "https://koozaki.com/romaji-conv/",
"bugs": {
"url": "https://github.com/koozaki/romaji-conv/issues",
"url": "https://github.com/koozaki/romaji-conv/issues/new?assignees=koozaki&labels=bug&template=bug_report.md",
"email": "koujirou0111@gmail.com"

@@ -32,4 +36,4 @@ },

"lint": "eslint ./bin/ ./lib/",
"tdd": "jest --watchAll",
"test": "jest",
"tdd": "jest --watchAll --coverage --verbose",
"test": "jest --coverage --verbose",
"webpack": "webpack"

@@ -36,0 +40,0 @@ },

# romaji-conv
[![](https://github.com/koozaki/romaji-conv/workflows/Node.js%20Package/badge.svg)](https://github.com/koozaki/romaji-conv/actions?query=workflow%3A%22Node.js+Package%22)
[![](https://img.shields.io/github/v/release/koozaki/romaji-conv?style=flat-square)](https://github.com/koozaki/romaji-conv/releases)
[![](https://img.shields.io/npm/v/@koozaki/romaji-conv?style=flat-square)](https://www.npmjs.com/package/@koozaki/romaji-conv)

@@ -7,31 +8,116 @@ [![](https://data.jsdelivr.com/v1/package/npm/@koozaki/romaji-conv/badge)](https://www.jsdelivr.com/package/npm/@koozaki/romaji-conv)

Convert romaji into hiragana
Convert romaji into kana
## About
- ローマ字をひらがなに変換します。
### About
- ローマ字・ひらがな・カタカナをひらがな・カタカナに変換します。
- 訓令式、ヘボン式など幅広い記法に対応しています。
- [シンプルなディクショナリ型設計](https://github.com/koozaki/romaji-conv/blob/master/lib/map.js)のため誰でも簡単に改善ができます。
- Node.js, Browser, Shell 上で実行可能な軽量 JavaScript ライブラリです。
- シンプルな[完全ディクショナリ型設計](https://github.com/koozaki/romaji-conv/blob/master/lib/map/)のため誰でも簡単に[改善](https://github.com/koozaki/romaji-conv/pulls)ができます。
- Browser, Node.js, CLI で動作する軽量 JavaScript ライブラリです。
- 不具合報告は[こちら](https://github.com/koozaki/romaji-conv/issues/new?assignees=koozaki&labels=bug&template=bug_report.md)からお願いします。
### Sample
#### Node.js
```node
const romajiConv = require('romaji-conv');
console.log(romajiConv('anoinutyauchautocyauntyau'));
// あのいぬちゃうちゃうとちゃうんちゃう
```
### Usage
#### Browser
##### Load the romaji-conv.js (jsDelivr)
```html
<script src="https://cdn.jsdelivr.net/npm/@koozaki/romaji-conv/dist/romaji-conv.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@koozaki/romaji-conv@latest/dist/romaji-conv.js"></script>
```
##### 1. Method pattern
```html
<script>
console.log(window.romajiConv('anoinutyauchautocyauntyau'));
console.log(romajiConv('hogehoge').toHiragana()); // ほげほげ
// ローマ字 → ひらがな・カタカナ
var romaji = romajiConv('anoinutyauchautocyauntyau');
console.log(romaji.toHiragana()); // あのいぬちゃうちゃうとちゃうんちゃう
console.log(romaji.toKatakana()); // アノイヌチャウチャウトチャウンチャウ
// ひらがな → カタカナ
var hiragana = romajiConv('あのいぬちゃうちゃうとちゃうんちゃう');
console.log(hiragana.toKatakana()); // アノイヌチャウチャウトチャウンチャウ
// カタカナ → ひらがな
var katakana = romajiConv('アノイヌチャウチャウトチャウンチャウ');
console.log(katakana.toHiragana()); // あのいぬちゃうちゃうとちゃうんちゃう
</script>
// あのいぬちゃうちゃうとちゃうんちゃう
```
#### CLI (Shell)
##### 2. Function pattern
```html
<script>
var toHiragana = romajiConv.toHiragana;
var toKatakana = romajiConv.toKatakana;
// ローマ字 → ひらがな・カタカナ
console.log(toHiragana('hogehoge')); // ほげほげ
console.log(toKatakana('hogehoge')); // ホゲホゲ
// ひらがな → カタカナ
console.log(toKatakana('ほげほげ')); // ホゲホゲ
// カタカナ → ひらがな
console.log(toHiragana('ホゲホゲ')); // ほげほげ
</script>
```
#### Node.js
##### Install package
```sh
$ ./bin/romaji-conv.js anoinutyauchautocyauntyau
あのいぬちゃうちゃうとちゃうんちゃう
npm install @koozaki/romaji-conv
```
or
```sh
yarn add @koozaki/romaji-conv
```
##### 1. Method pattern
```javascript
const romajiConv = require('@koozaki/romaji-conv');
console.log(romajiConv('hogehoge').toHiragana()); // ほげほげ
// ローマ字 → ひらがな・カタカナ
const romaji = romajiConv('anoinutyauchautocyauntyau');
console.log(romaji.toHiragana()); // あのいぬちゃうちゃうとちゃうんちゃう
console.log(romaji.toKatakana()); // アノイヌチャウチャウトチャウンチャウ
// ひらがな → カタカナ
const hiragana = romajiConv('あのいぬちゃうちゃうとちゃうんちゃう');
console.log(hiragana.toKatakana()); // アノイヌチャウチャウトチャウンチャウ
// カタカナ → ひらがな
const katakana = romajiConv('アノイヌチャウチャウトチャウンチャウ');
console.log(katakana.toHiragana()); // あのいぬちゃうちゃうとちゃうんちゃう
```
##### 2. Function pattern
```javascript
const { toHiragana, toKatakana } = require('@koozaki/romaji-conv');
// ローマ字 → ひらがな・カタカナ
console.log(toHiragana('hogehoge')); // ほげほげ
console.log(toKatakana('hogehoge')); // ホゲホゲ
// ひらがな → カタカナ
console.log(toKatakana('ほげほげ')); // ホゲホゲ
// カタカナ → ひらがな
console.log(toHiragana('ホゲホゲ')); // ほげほげ
```
#### CLI
```sh
# ローマ字 → ひらがな・カタカナ
$(npm bin)/romaji-conv anoinutyauchautocyauntyau # あのいぬちゃうちゃうとちゃうんちゃう
$(npm bin)/romaji-conv anoinutyauchautocyauntyau --katakana # アノイヌチャウチャウトチャウンチャウ
# ひらがな → カタカナ
$(npm bin)/romaji-conv あのいぬちゃうちゃうとちゃうんちゃう --katakana # アノイヌチャウチャウトチャウンチャウ
# カタカナ → ひらがな
$(npm bin)/romaji-conv アノイヌチャウチャウトチャウンチャウ # あのいぬちゃうちゃうとちゃうんちゃう
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc