@koozaki/romaji-conv
Advanced tools
Comparing version 2.0.21 to 2.0.22
{ | ||
"semi": true, | ||
"singleQuote": true, | ||
"quoteProps": "preserve", | ||
"jsxSingleQuote": true, | ||
@@ -5,0 +6,0 @@ "trailingComma": "none", |
@@ -9,13 +9,7 @@ #!/usr/bin/env node | ||
program.option('--katakana').action((someString, options) => { | ||
const instance = romajiConv(someString); | ||
console.log(options.katakana ? instance.toKatakana() : instance.toHiragana()); | ||
}); | ||
program | ||
.option('--katakana') | ||
.action((someString, options) => { | ||
const instance = romajiConv(someString); | ||
console.log(options.katakana ? instance.toKatakana() : instance.toHiragana()); | ||
}); | ||
program | ||
.version(package.version) | ||
.arguments('<someString>') | ||
.parse(process.argv); | ||
program.version(package.version).arguments('<someString>').parse(process.argv); |
const romajiConv = require('../lib/index'); | ||
window['romajiConv'] = romajiConv; | ||
window['romajiConv'] = romajiConv; |
/*! | ||
* @name @koozaki/romaji-conv | ||
* @version 2.0.21 | ||
* @version 2.0.22 | ||
* @desc Convert romaji into kana | ||
@@ -5,0 +5,0 @@ * @author Kojiro Ozaki <koujirou0111@gmail.com> (https://koozaki.com/) |
@@ -12,7 +12,8 @@ const reverseMap = require('./reverseMap'); | ||
*/ | ||
constructor (someString) { | ||
if (typeof someString !== 'string') throw new TypeError(`"${someString}" is not a string.`); | ||
constructor(someString) { | ||
if (typeof someString !== 'string') | ||
throw new TypeError(`"${someString}" is not a string.`); | ||
this.someString = someString; | ||
this.hiragana = this.convert(this.someString, mapRomaji2Hiragana); | ||
@@ -29,3 +30,3 @@ this.hiragana = this.convert(this.hiragana, mapKatakana2Hiragana); | ||
*/ | ||
string () { | ||
string() { | ||
return this.someString; | ||
@@ -41,8 +42,11 @@ } | ||
*/ | ||
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); | ||
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 | ||
); | ||
@@ -57,3 +61,3 @@ return outputString; | ||
*/ | ||
toHiragana () { | ||
toHiragana() { | ||
return this.hiragana; | ||
@@ -67,3 +71,3 @@ } | ||
*/ | ||
toKatakana () { | ||
toKatakana() { | ||
return this.katakana; | ||
@@ -70,0 +74,0 @@ } |
@@ -29,13 +29,16 @@ /* global describe, test, beforeEach, expect */ | ||
beforeEach(() => { | ||
romaji = '' + | ||
romaji = | ||
'' + | ||
'aiueokakikukekosashisusesotachitsutetonaninuneno' + | ||
'hahifuhehomamimumemoyayuyorarirurerowawiwuwewonnn'; | ||
hiragana = '' + | ||
hiragana = | ||
'' + | ||
'あいうえおかきくけこさしすせそたちつてとなにぬねの' + | ||
'はひふへほまみむめもやゆよらりるれろわうぃううぇをんん'; | ||
katakana = '' + | ||
katakana = | ||
'' + | ||
'アイウエオカキクケコサシスセソタチツテトナニヌネノ' + | ||
'ハヒフヘホマミムメモヤユヨラリルレロワウィウウェヲンン' | ||
'ハヒフヘホマミムメモヤユヨラリルレロワウィウウェヲンン'; | ||
@@ -97,5 +100,5 @@ romajiInstance = romajiConv(romaji); | ||
test('toHiragana: 訓令式とローマ式の混合', () => { | ||
expect( | ||
romajiConv('anoinutyauchautocyauntyau?').toHiragana() | ||
).toBe('あのいぬちゃうちゃうとちゃうんちゃう?'); | ||
expect(romajiConv('anoinutyauchautocyauntyau?').toHiragana()).toBe( | ||
'あのいぬちゃうちゃうとちゃうんちゃう?' | ||
); | ||
}); | ||
@@ -102,0 +105,0 @@ |
@@ -9,9 +9,11 @@ /* global test, expect */ | ||
test('reverseMap はオブジェクトの key と value を入れ替える', () => { | ||
expect(reverseMap({ | ||
'key1': 'value1', | ||
'key2': 'value2', | ||
'key3': 'value3', | ||
'key4': 'value4', | ||
'key5': 'value5' | ||
})).toEqual({ | ||
expect( | ||
reverseMap({ | ||
'key1': 'value1', | ||
'key2': 'value2', | ||
'key3': 'value3', | ||
'key4': 'value4', | ||
'key5': 'value5' | ||
}) | ||
).toEqual({ | ||
'value1': 'key1', | ||
@@ -18,0 +20,0 @@ 'value2': 'key2', |
{ | ||
"name": "@koozaki/romaji-conv", | ||
"version": "2.0.21", | ||
"version": "2.0.22", | ||
"description": "Convert romaji into kana", | ||
@@ -33,4 +33,5 @@ "keywords": [ | ||
"scripts": { | ||
"build": "run-s lint test webpack", | ||
"build": "run-s lint prettier test webpack", | ||
"lint": "eslint ./bin/ ./lib/", | ||
"prettier": "prettier --write .", | ||
"tdd": "jest --watchAll --coverage --verbose", | ||
@@ -41,14 +42,15 @@ "test": "jest --coverage --verbose", | ||
"dependencies": { | ||
"commander": "^10.0.1" | ||
"commander": "^11.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.21.8", | ||
"@babel/preset-env": "^7.21.5", | ||
"babel-loader": "^9.1.2", | ||
"eslint": "^8.41.0", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"@babel/core": "^7.22.9", | ||
"@babel/preset-env": "^7.22.9", | ||
"babel-loader": "^9.1.3", | ||
"eslint": "^8.45.0", | ||
"jest": "^29.6.1", | ||
"jest-environment-jsdom": "^29.6.1", | ||
"npm-run-all": "^4.1.5", | ||
"webpack": "^5.83.1", | ||
"webpack-cli": "^5.1.1" | ||
"prettier": "^3.0.0", | ||
"webpack": "^5.88.1", | ||
"webpack-cli": "^5.1.4" | ||
}, | ||
@@ -55,0 +57,0 @@ "publishConfig": { |
@@ -26,3 +26,3 @@ # romaji-conv | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@koozaki/romaji-conv@2.0.21/dist/romaji-conv.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@koozaki/romaji-conv@2.0.22/dist/romaji-conv.js"></script> | ||
``` | ||
@@ -125,10 +125,10 @@ | ||
# ローマ字 → ひらがな・カタカナ | ||
$(npm bin)/romaji-conv anoinutyauchautocyauntyau # あのいぬちゃうちゃうとちゃうんちゃう | ||
$(npm bin)/romaji-conv anoinutyauchautocyauntyau --katakana # アノイヌチャウチャウトチャウンチャウ | ||
./bin/romaji-conv.js anoinutyauchautocyauntyau # あのいぬちゃうちゃうとちゃうんちゃう | ||
./bin/romaji-conv.js anoinutyauchautocyauntyau --katakana # アノイヌチャウチャウトチャウンチャウ | ||
# ひらがな → カタカナ | ||
$(npm bin)/romaji-conv あのいぬちゃうちゃうとちゃうんちゃう --katakana # アノイヌチャウチャウトチャウンチャウ | ||
./bin/romaji-conv.js あのいぬちゃうちゃうとちゃうんちゃう --katakana # アノイヌチャウチャウトチャウンチャウ | ||
# カタカナ → ひらがな | ||
$(npm bin)/romaji-conv アノイヌチャウチャウトチャウンチャウ # あのいぬちゃうちゃうとちゃうんちゃう | ||
./bin/romaji-conv.js アノイヌチャウチャウトチャウンチャウ # あのいぬちゃうちゃうとちゃうんちゃう | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
43924
25
720
10
+ Addedcommander@11.1.0(transitive)
- Removedcommander@10.0.1(transitive)
Updatedcommander@^11.0.0