Skip to content

Commit 1e7f416

Browse files
committed
initial commit
0 parents  commit 1e7f416

7 files changed

+2542
-0
lines changed

.travis.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
language: node_js
2+
node_js:
3+
- 'node'
4+
cache:
5+
yarn: true
6+
directories:
7+
- node_modules
8+
before_install:
9+
- curl -o- -L https://yarnpkg.com/install.sh | bash
10+
- export PATH=$HOME/.yarn/bin:$PATH
11+
install:
12+
- yarn
13+
script:
14+
- yarn compile
15+
notifications:
16+
email: false
17+
slack:
18+
deploy:
19+
provider: npm
20+
email: deptno@gmail.com
21+
skip_cleanup: true
22+
api_key:
23+
on:
24+
tags: true

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./dist');

lib/index.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import currency from '.';
2+
3+
describe('constructor', () => {
4+
const amount = 1000000000000000; // 1000조
5+
it('1,000,000,000,000,000원', () => {
6+
expect(currency['조원'](amount)).toBe('1,000');
7+
expect(currency['억원'](amount)).toBe('10,000,000');
8+
expect(currency['백만원'](amount)).toBe('1,000,000,000');
9+
expect(currency['만원'](amount)).toBe('100,000,000,000');
10+
});
11+
it('1,000,000,000,000,000원', () => {
12+
expect(currency['조원'](amount, 1)).toBe('1,000.0');
13+
});
14+
});

lib/index.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as currency from 'currency-formatter';
2+
3+
const UNIT = ['', '백', '천', '만', '십만', '백만', '천만', '억', '십억', '백억', '천억', '조', '십조', '백조', '천조'];
4+
5+
const KRW = {
6+
: 10,
7+
: 100,
8+
: 1000,
9+
: 10000,
10+
십만: 100000,
11+
백만: 1000000,
12+
천만: 10000000,
13+
: 100000000,
14+
십억: 1000000000,
15+
백억: 10000000000,
16+
천억: 100000000000,
17+
: 1000000000000,
18+
};
19+
20+
const comma = (unit = 1) => (raw: number, precision = 0) => currency.format(raw / unit, {precision});
21+
22+
export default UNIT.reduce((ret, cur) => {
23+
ret[`${cur}원`] = comma(KRW[cur]);
24+
return ret;
25+
}, {});

package.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "currency-kr",
3+
"version": "0.0.1",
4+
"description": "한국 통화, 한글단위 원",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "jest --watch"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/deptno/currency-kr.git"
12+
},
13+
"keywords": [
14+
"한국",
15+
"통화"
16+
],
17+
"author": "deptno@gmail.com",
18+
"license": "MIT",
19+
"bugs": {
20+
"url": "https://github.com/deptno/currency-kr/issues"
21+
},
22+
"homepage": "https://github.com/deptno/currency-kr#readme",
23+
"devDependencies": {
24+
"jest": "^19.0.2",
25+
"ts-jest": "^19.0.2",
26+
"typescript": "^2.2.1"
27+
},
28+
"dependencies": {
29+
"currency-formatter": "^1.1.1"
30+
},
31+
"jest": {
32+
"transform": {
33+
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
34+
},
35+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
36+
"moduleFileExtensions": [
37+
"ts",
38+
"tsx",
39+
"js"
40+
]
41+
}
42+
}

tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "dist",
4+
"module": "commonjs",
5+
"target": "es5"
6+
},
7+
"exclude": [
8+
"node_modules",
9+
"**/*.test.ts"
10+
]
11+
}

0 commit comments

Comments
 (0)