Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .babelrc

This file was deleted.

9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
lib
node_modules/
*.log
*.log.*
npm-debug.log
npm-debug.log
coverage
.nyc_output
.*cache
.idea
.DS_Store
.coveralls.yml
22 changes: 22 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"require": [
"ts-node/register",
"source-map-support/register"
],
"include": [
"src/**/*.ts"
],
"extension": [
".ts"
],
"exclude": [
"**/*.d.ts",
"src/index.ts"
],
"reporter": [
"text-summary",
"html",
"lcov"
],
"all": true
}
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "node"
- "lts/*"
- "4"
after_success:
- npm run coveralls
52 changes: 39 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,71 @@ yarn add auto-hyphen

## 사용방법 how to use

```js
### In Browser
현재 모던 브라우저에서는 CommonJS 스펙과 ES Module 스펙을 준수한 브라우저가 거의 없다.
따라서 브라우저에서 다이렉트로 쓰려면 아래와 같이 사용해야한다. (CDN은 지원 예정)

```html
<script src="node_modules/auto-hyphen/dist/index.js"></script>
<script>
let input_value = '19880507';
console.log(autoHyphen.autoHyphenBirth(input_value)); // '1988-05-07'

let result_value = autoHyphenBirth(input_value);
input_value = '01033339999';
console.log(autoHyphen.autoHyphenPhone(input_value)); // '010-3333-9999';

console.log(result_value);
// '1988-05-07';
input_value = '93-05-30';
console.log(autoHyphen.removedNotDigits(input_value)); // '930330';
</script>
```

### In Node.js(CommonJS)
```js
const autoHyphen = require('auto-hyphen');

let input_value = '19880507';
console.log(autoHyphen.autoHyphenBirth(input_value)); // '1988-05-07'

input_value = '01033339999';
console.log(autoHyphen.autoHyphenPhone(input_value)); // '010-3333-9999';

result_value = autoHyphenPhone(input_value);
input_value = '93-05-30';
console.log(autoHyphen.removedNotDigits(input_value)); // '930330';
```

### In ES Module
```js
import * as autoHyphen from 'auto-hyphen';

console.log(result_value);
// '010-5555-4444';
let input_value = '19880507';
console.log(autoHyphen.autoHyphenBirth(input_value)); // '1988-05-07'

const remove_hyphen = removeHyphen(result_value);
input_value = '01033339999';
console.log(autoHyphen.autoHyphenPhone(input_value)); // '010-3333-9999';

console.log(result_value);
// '01055554444';
input_value = '93-05-30';
console.log(autoHyphen.removedNotDigits(input_value)); // '930330';
```

## 이벤트와 함께사용하기 event value applicate
```js
// input => Pass event values

const transValue = autoHyphenBirth(event.target.value);
const transValue = autoHyphen.autoHyphenBirth(event.target.value);
// 1998 => 1998
// 19991 => 1999-1
// 19994 => 1999-04
// 199911 => 1999-11
// 199955 => 1999-05-05
// 1999125 => 1999-12-05
const transValue = autoHyphenPhone(event.target.value);
const transValue = autoHyphen.autoHyphenPhone(event.target.value);
// 010333 => 010-333
// 0103334 => 010-3334
// 0104447777 => 010-444-7777
// 01066660000 => 010-6666-0000
```

- 생일 입력시 12월을 넘어간 값은 12로 31일을 넘어간 값은 31로 변경됩니다.
- When the birthday is entered, insert event value exceeding December is 12, and the value exceeding 31 days is changed to 31.
- When the birthday is entered, insert event value exceeding December is 12, and the value exceeding 31 days is changed to 31.

nyc.js --reporter=lcovonly --extension=.ts --extension=.js --exclude=src/test/autoHyphenPhone.spec.ts --report-dir=/private/var/folders/_r/b_s4h7ps3k9bswkwjpv1km6c0000gn/T/mocha-intellij-coverage-2 /Users/yang-gwonseong/IdeaProjects/autoInputValue/node_modules/mocha/bin/_mocha --require ts-node/register --ui bdd --reporter "/Users/yang-gwonseong/Library/Application Support/IntelliJIdea2017.3/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js" /Users/yang-gwonseong/IdeaProjects/autoInputValue/src/test/autoHyphenPhone.spec.ts --grep "autoHyphenPhone "
1 change: 1 addition & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
declare module 'auto-hyphen' {
export function autoHyphenPhone(value: string): string;
export function autoHyphenBirth(value: string): string;
export const removeHyphen: (value: string) => string;
}
/**
* 숫자로만 이루어진 휴대폰 번호에 자동으로 하이픈(-)을 붙여주는 함수
* @param phoneNumber 핸드폰 번호
* @return 하이픈을 포함한 핸드폰 번호
*/
export function autoHyphenPhone(phoneNumber: string): string;

/**
* 숫자로만 이루어진 생년월일에 자동으로 하이픈(-)을 붙여주는 함수
* @param birth 생년월일
* @return 하이픈을 포함한 생년월일
*/
export function autoHyphenBirth(birth: string): string;

/**
* 숫자를 제외한 문자를 제거
* @param numberContainsNotDigits 숫자를 제외한 문자열들을 포함한 문자열
* @return 숫자를 제외한 문자를 제거한 문자열
*/
export function removedNotDigits(numberContainsNotDigits: string): string;
}
2 changes: 2 additions & 0 deletions mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--recursive
src/test/**/*.spec.ts
Loading