Skip to content

Commit

Permalink
Add toPhoneNumber and update region-name-kr to 2.0.1, release v0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Shin-JaeHeon committed Apr 12, 2019
1 parent df624ab commit edfbfae
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 체인지 로그

## 0.7.0
* 전화번호 처리 추가
* `region-name-kr@2.0.1` 적용
## 0.6.0
* `inko@1.0.6` 라이브러리의 함수 추가(`ko2en`, `en2ko`)
* `inko@1.0.6`의 지원을 위한 인터페이스 추가 `InkoOption`
Expand Down
118 changes: 112 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,104 @@ declare interface InkoOption {
숫자를 처리하는 부분입니다.
### NumberMode
`import NumberMode from 'korean-js/number/mode`
* `NumberMode.Unit4` : 숫자는 한국어로 바꾸지않고, 4자리마다 단위를 추가합니다.
* 예 : `toKorean(1234567890, NumberMode.Unit4) // 12억3456만7890`
* `NumberMode.Unit` : 숫자는 한국어로 바꾸지않고, 각각에 단위를 추가합니다.
* 예 : `toKorean(1234567890, NumberMode.Unit4) // 1십2억3천4백5십6만7천8백9십`
* 숫자
* `NumberMode.Unit4` : 숫자는 한국어로 바꾸지않고, 4자리마다 단위를 추가합니다.
* 예 : `toKorean(1234567890, NumberMode.Unit4) // 12억3456만7890`
* `NumberMode.Unit` : 숫자는 한국어로 바꾸지않고, 각각에 단위를 추가합니다.
* 예 : `toKorean(1234567890, NumberMode.Unit4) // 1십2억3천4백5십6만7천8백9십`
* 전화번호(숫자)
* `phone`
* `phoneSKT`
* `NetworkIOT`
* `NetworkPC`
* `phoneKTF`
* `phoneLGT`
* `Seoul`
* `Gyeonggi`
* `Incheon`
* `Gangwon`
* `Chungnam`
* `Chungbuk`
* `Daejeon`
* `Sejong`
* `Busan`
* `Ulsan`
* `Daegu`
* `Gyeongbuk`
* `Gyeongnam`
* `jeonbuk`
* `Gwangju`
* `Jeonnam`
* `Jeju`
* `핸드폰`
* `핸드폰SKT`
* `IOT통신`
* `PC통신`
* `핸드폰KTF`
* `핸드폰LGT`
* `서울`
* `경기`
* `인천`
* `강원`
* `충남`
* `충북`
* `대전`
* `세종`
* `부산`
* `울산`
* `대구`
* `경북`
* `경남`
* `전북`
* `광주`
* `전남`
* `제주`
* 지역(전화번호를 지역이름으로)
* `010`
* `011`
* `012`
* `013`
* `016`
* `014`
* `02`
* `031`
* `032`
* `033`
* `041`
* `042`
* `043`
* `044`
* `051`
* `052`
* `053`
* `054`
* `055`
* `061`
* `062`
* `063`
* `064`
### toPhoneNumberString(number, gukbeon, split, split2)
* number : number, 예) 12345678
* gukbeon : 국번, 예) NumberMode.Seoul, NumberMode.서울
* split : 전화번호 구분자(기본값 : '')
* split2 : 국번 구분자(기본값 : '') : '-'이면 공이-XXXX-XXXX, ')'이면 공이)XXXX-XXXX

숫자를 한글로 표기된 전화번호로 바꿉니다.

```javascript
number.toPhoneNumberString(12345678, NumberMode.Seoul); //공이일이삼사오육칠팔
```
### toPhoneNumber(number, gukbeon, split, split2)
* number : number, 예) 12345678
* gukbeon : 국번, 예) NumberMode.Seoul, NumberMode.서울
* split : 전화번호 구분자(기본값 : '-')
* split2 : 국번 구분자(기본값 : '-') : '-'이면 02-XXXX-XXXX, ')'이면 02)XXXX-XXXX

한글을 숫자로 표기된 전화번호로 바꿉니다.

```javascript
number.toPhoneNumber('일이삼사오륙칠팔', NumberMode.Seoul); //02-1234-5678
```

### toKorean(n, ?mode)
* n : `number`, 한국어로 바꿀 숫자입니다.
Expand Down Expand Up @@ -313,8 +407,20 @@ mode가 2일 경우 한자, 카타카나 병기(`世宗(セジョン)特別自

고성군의 경우 고성군(경남), 고성군(강원)으로 구분해야 변환이 가능합니다.

#### 기본 예시
#### `mode = 2` 예시
* 특별/광역시/도 : `세종특별자치시``世宗(セジョン)特別自治市`
* 특별/광역시 구/군 :`서울특별시 강남구``ソウル特別市 永登浦(ヨンドゥンポ)区`
* 특별/광역시 구/군 :`서울특별시 영등포구``ソウル特別市 永登浦(ヨンドゥンポ)区`
* 도 시/군 : `강원도 평창군``江原(カンウォン)道 平昌(ピョンチャン)郡`
* 도 시 구 : `경기도 수원시 권선구``京畿(キョンギ)道 水原(スウォン)市 勧善(クォンソン)区`

#### `mode = 1` 예시
* 특별/광역시/도 : `세종특별자치시``セジョントゥクピョルジャチシ`
* 특별/광역시 구/군 :`서울특별시 영등포구``ソウルトゥクピョルシ ヨンドゥンポグ`
* 도 시/군 : `강원도 평창군``カンウォンド ピョンチャングン`
* 도 시 구 : `경기도 수원시 권선구``キョンギド スウォンシ クォンソング`

#### `mode = 0` 예시
* 특별/광역시/도 : `세종특별자치시``世宗特別自治市`
* 특별/광역시 구/군 :`서울특별시 영등포구``ソウル特別市 永登浦区`
* 도 시/군 : `강원도 평창군``江原道 平昌郡`
* 도 시 구 : `경기도 수원시 권선구``京畿道 水原市 勧善区`
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "korean-js",
"description": "Korean Processing Library",
"version": "0.6.0",
"version": "0.7.0",
"author": "Shin-JaeHeon",
"main": "src/index.js",
"license": "MIT",
Expand All @@ -14,7 +14,7 @@
},
"dependencies": {
"hangul-js": "^0.2.5",
"region-name-kr": "^2.0.0",
"region-name-kr": "^2.0.1",
"inko": "^1.0.6"
},
"devDependencies": {
Expand Down
25 changes: 24 additions & 1 deletion src/number/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Number {
let sum = 0;
let is4 = false;
let digit = 0;
//@ts-ignore
return temp.reduce((prev, current, index) => {
let tempSum = parseInt(prev.join(''));
switch (this.koreanUnitName.indexOf(current)) {
Expand Down Expand Up @@ -71,7 +72,29 @@ class Number {
return index === temp.length - 1 ? sum + parseInt(prev.join('')) : prev;
}, [0]);
}
/**
* @param number
* @param gukbeon
* @param split 전화번호 구분자(기본값 : '-')
* @param split2 국번 구분자(기본값 : '-') : '-'이면 02-XXXX-XXXX, ')'이면 02)XXXX-XXXX
*/
static toPhoneNumberString(number, gukbeon, split = '', split2 = '') {
const temp = number.toString().split('').map(num => this.koreanName[num]);
temp.splice(4, 0, split);
return `공${gukbeon.toString().split('').map(n => this.koreanName[n]).join('')}${split2}${temp.join('')}`;
}
/**
* @param number
* @param gukbeon
* @param split 전화번호 구분자(기본값 : '-')
* @param split2 국번 구분자(기본값 : '-') : '-'이면 02-XXXX-XXXX, ')'이면 02)XXXX-XXXX
*/
static toPhoneNumber(number, gukbeon, split = '-', split2 = '-') {
const temp = number.toString().replace(//g, '육').split('').map(num => this.koreanName.indexOf(num).toString());
temp.splice(4, 0, split);
return `0${gukbeon}${split2}${temp.join('')}`;
}
}
Number.koreanName = ['', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구'];
Number.koreanName = ['', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구'];
Number.koreanUnitName = ['십', '백', '천', '', '만', '억', '조'];
exports.default = Number;
29 changes: 27 additions & 2 deletions src/number/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import NumberMode from './mode';

export default class Number {
private static koreanName = ['', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구'];
private static koreanName = ['', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구'];
private static koreanUnitName = ['십', '백', '천', '', '만', '억', '조'];

static toKorean(n: number, mode?: NumberMode): string {
Expand All @@ -28,11 +28,12 @@ export default class Number {
return temp.join('').replace(/[영0].?/g, '').replace(/일([십백천])/g, '$1');
}

static toNumber(str: string) {
static toNumber(str: string): number {
const temp = str.replace(/천백/g, '천일백').replace(/([백])(십)/g, '백일십').split('');
let sum = 0;
let is4 = false;
let digit = 0;
//@ts-ignore
return temp.reduce((prev, current, index) => {
let tempSum = parseInt(prev.join(''));
switch (this.koreanUnitName.indexOf(current)) {
Expand Down Expand Up @@ -70,4 +71,28 @@ export default class Number {
return index === temp.length - 1 ? sum + parseInt(prev.join('')) : prev;
}, [0]);
}

/**
* @param number
* @param gukbeon
* @param split 전화번호 구분자(기본값 : '-')
* @param split2 국번 구분자(기본값 : '-') : '-'이면 02-XXXX-XXXX, ')'이면 02)XXXX-XXXX
*/
static toPhoneNumberString(number: number, gukbeon: NumberMode, split: string = '', split2: string = ''): string {
const temp = number.toString().split('').map(num => this.koreanName[num]);
temp.splice(4, 0, split);
return `공${gukbeon.toString().split('').map(n => this.koreanName[n]).join('')}${split2}${temp.join('')}`
}

/**
* @param number
* @param gukbeon
* @param split 전화번호 구분자(기본값 : '-')
* @param split2 국번 구분자(기본값 : '-') : '-'이면 02-XXXX-XXXX, ')'이면 02)XXXX-XXXX
*/
static toPhoneNumber(number: string, gukbeon: NumberMode, split: string = '-', split2: string = '-'): string {
const temp = number.toString().replace(//g, '육').split('').map(num => this.koreanName.indexOf(num).toString());
temp.splice(4, 0, split);
return `0${gukbeon}${split2}${temp.join('')}`
}
}
69 changes: 69 additions & 0 deletions src/number/mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,74 @@ var NumberMode;
(function (NumberMode) {
NumberMode[NumberMode["Unit4"] = 2019] = "Unit4";
NumberMode[NumberMode["Unit"] = 2020] = "Unit";
NumberMode[NumberMode["phone"] = 10] = "phone";
NumberMode[NumberMode["phoneSKT"] = 11] = "phoneSKT";
NumberMode[NumberMode["NetworkIOT"] = 12] = "NetworkIOT";
NumberMode[NumberMode["NetworkPC"] = 13] = "NetworkPC";
NumberMode[NumberMode["phoneKTF"] = 16] = "phoneKTF";
NumberMode[NumberMode["phoneLGT"] = 14] = "phoneLGT";
NumberMode[NumberMode["Seoul"] = 2] = "Seoul";
NumberMode[NumberMode["Gyeonggi"] = 31] = "Gyeonggi";
NumberMode[NumberMode["Incheon"] = 32] = "Incheon";
NumberMode[NumberMode["Gangwon"] = 33] = "Gangwon";
NumberMode[NumberMode["Chungnam"] = 41] = "Chungnam";
NumberMode[NumberMode["Chungbuk"] = 42] = "Chungbuk";
NumberMode[NumberMode["Daejeon"] = 43] = "Daejeon";
NumberMode[NumberMode["Sejong"] = 44] = "Sejong";
NumberMode[NumberMode["Busan"] = 51] = "Busan";
NumberMode[NumberMode["Ulsan"] = 52] = "Ulsan";
NumberMode[NumberMode["Daegu"] = 53] = "Daegu";
NumberMode[NumberMode["Gyeongbuk"] = 54] = "Gyeongbuk";
NumberMode[NumberMode["Gyeongnam"] = 55] = "Gyeongnam";
NumberMode[NumberMode["jeonbuk"] = 61] = "jeonbuk";
NumberMode[NumberMode["Gwangju"] = 62] = "Gwangju";
NumberMode[NumberMode["Jeonnam"] = 63] = "Jeonnam";
NumberMode[NumberMode["Jeju"] = 64] = "Jeju";
NumberMode[NumberMode["\uD578\uB4DC\uD3F0"] = 10] = "\uD578\uB4DC\uD3F0";
NumberMode[NumberMode["\uD578\uB4DC\uD3F0SKT"] = 11] = "\uD578\uB4DC\uD3F0SKT";
NumberMode[NumberMode["IOT\uD1B5\uC2E0"] = 12] = "IOT\uD1B5\uC2E0";
NumberMode[NumberMode["PC\uD1B5\uC2E0"] = 13] = "PC\uD1B5\uC2E0";
NumberMode[NumberMode["\uD578\uB4DC\uD3F0KTF"] = 16] = "\uD578\uB4DC\uD3F0KTF";
NumberMode[NumberMode["\uD578\uB4DC\uD3F0LGT"] = 14] = "\uD578\uB4DC\uD3F0LGT";
NumberMode[NumberMode["\uC11C\uC6B8"] = 2] = "\uC11C\uC6B8";
NumberMode[NumberMode["\uACBD\uAE30"] = 31] = "\uACBD\uAE30";
NumberMode[NumberMode["\uC778\uCC9C"] = 32] = "\uC778\uCC9C";
NumberMode[NumberMode["\uAC15\uC6D0"] = 33] = "\uAC15\uC6D0";
NumberMode[NumberMode["\uCDA9\uB0A8"] = 41] = "\uCDA9\uB0A8";
NumberMode[NumberMode["\uCDA9\uBD81"] = 42] = "\uCDA9\uBD81";
NumberMode[NumberMode["\uB300\uC804"] = 43] = "\uB300\uC804";
NumberMode[NumberMode["\uC138\uC885"] = 44] = "\uC138\uC885";
NumberMode[NumberMode["\uBD80\uC0B0"] = 51] = "\uBD80\uC0B0";
NumberMode[NumberMode["\uC6B8\uC0B0"] = 52] = "\uC6B8\uC0B0";
NumberMode[NumberMode["\uB300\uAD6C"] = 53] = "\uB300\uAD6C";
NumberMode[NumberMode["\uACBD\uBD81"] = 54] = "\uACBD\uBD81";
NumberMode[NumberMode["\uACBD\uB0A8"] = 55] = "\uACBD\uB0A8";
NumberMode[NumberMode["\uC804\uBD81"] = 61] = "\uC804\uBD81";
NumberMode[NumberMode["\uAD11\uC8FC"] = 62] = "\uAD11\uC8FC";
NumberMode[NumberMode["\uC804\uB0A8"] = 63] = "\uC804\uB0A8";
NumberMode[NumberMode["\uC81C\uC8FC"] = 64] = "\uC81C\uC8FC";
NumberMode["010"] = "\uD578\uB4DC\uD3F0";
NumberMode["011"] = "\uD578\uB4DC\uD3F0SKT";
NumberMode["012"] = "IOT\uD1B5\uC2E0";
NumberMode["013"] = "PC\uD1B5\uC2E0";
NumberMode["016"] = "\uD578\uB4DC\uD3F0KTF";
NumberMode["014"] = "\uD578\uB4DC\uD3F0LGT";
NumberMode["02"] = "\uC11C\uC6B8";
NumberMode["031"] = "\uACBD\uAE30";
NumberMode["032"] = "\uC778\uCC9C";
NumberMode["033"] = "\uAC15\uC6D0";
NumberMode["041"] = "\uCDA9\uB0A8";
NumberMode["042"] = "\uCDA9\uBD81";
NumberMode["043"] = "\uB300\uC804";
NumberMode["044"] = "\uC138\uC885";
NumberMode["051"] = "\uBD80\uC0B0";
NumberMode["052"] = "\uC6B8\uC0B0";
NumberMode["053"] = "\uB300\uAD6C";
NumberMode["054"] = "\uACBD\uBD81";
NumberMode["055"] = "\uACBD\uB0A8";
NumberMode["061"] = "\uC804\uBD81";
NumberMode["062"] = "\uAD11\uC8FC";
NumberMode["063"] = "\uC804\uB0A8";
NumberMode["064"] = "\uC81C\uC8FC";
})(NumberMode || (NumberMode = {}));
exports.default = NumberMode;
Loading

0 comments on commit edfbfae

Please sign in to comment.