hanfix 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -0
- package/README.md +25 -2
- package/package.json +2 -1
- package/src/index.js +45 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
ISC License Copyright (c) 2004-2010 by Internet Systems Consortium, Inc.
|
|
2
|
+
("ISC")
|
|
3
|
+
|
|
4
|
+
Copyright (c) 1995-2003 by Internet Software Consortium
|
|
5
|
+
|
|
6
|
+
Permission to
|
|
7
|
+
use, copy, modify, and /or distribute this software for any purpose with or
|
|
8
|
+
without fee is hereby granted, provided that the above copyright notice and this
|
|
9
|
+
permission notice appear in all copies.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND
|
|
12
|
+
ntalbs DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
13
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ntalbs BE
|
|
14
|
+
LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
15
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
|
16
|
+
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
17
|
+
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -5,6 +5,29 @@
|
|
|
5
5
|
검사기입니다. [hanspell](https://github.com/9beach/hanspell)에서
|
|
6
6
|
영감을 받아 작성했습니다. `hanspell`과 다른 점은 다음과 같습니다.
|
|
7
7
|
|
|
8
|
-
- 맞춤법 검사 결과를 JSON으로 리턴해 다른 프로그램(Emacs 등)에서 쉽게
|
|
9
|
-
사용할 수 있습니다.
|
|
10
8
|
- 맞춤법 검사는 다음 맞춤법 검사기만 사용합니다.
|
|
9
|
+
- 입력 텍스트를 `-d`(또는 `--data`) 옵션으로 제공할 수 있습니다. 이
|
|
10
|
+
옵션을 지정하지 않은 경우에는 STDIN으로부터 입력을 기다립니다.
|
|
11
|
+
|
|
12
|
+
## 설치
|
|
13
|
+
|
|
14
|
+
`hanfix`는 다음과 같이 설치할 수 있습니다.
|
|
15
|
+
|
|
16
|
+
```console
|
|
17
|
+
npm install -g hanfix
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## 사용법
|
|
22
|
+
|
|
23
|
+
```console
|
|
24
|
+
$ hanfix --help
|
|
25
|
+
Usage: index [options]
|
|
26
|
+
|
|
27
|
+
Korean Spell Checker
|
|
28
|
+
|
|
29
|
+
Options:
|
|
30
|
+
-d, --data <text> text for spell check
|
|
31
|
+
-c, --include-corrected include corrected text in the result
|
|
32
|
+
-h, --help display help for command
|
|
33
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hanfix",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Korean grammar checker using Daum grammar checker",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"한글",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"commander": "^14.0.2",
|
|
34
35
|
"jsdom": "^27.4.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
package/src/index.js
CHANGED
|
@@ -1,26 +1,58 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import fs from 'fs';
|
|
4
|
+
import { program } from 'commander';
|
|
4
5
|
import { check } from './hanfix.js';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
program
|
|
8
|
+
.description('Korean Spell Checker')
|
|
9
|
+
.option('-d, --data <text>', 'text for spell check')
|
|
10
|
+
.option('-c, --include-corrected', 'include corrected text in the result')
|
|
11
|
+
.action((options) => {
|
|
12
|
+
if (!options.data) {
|
|
13
|
+
readFromStdin(options);
|
|
14
|
+
} else {
|
|
15
|
+
checkText(options.data, options);
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
.parse(process.argv);
|
|
9
19
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
async function readFromStdin (options) {
|
|
21
|
+
try {
|
|
22
|
+
const inputText = fs.readFileSync(0, 'utf8');
|
|
23
|
+
const result = await check(inputText);
|
|
24
|
+
const output = {
|
|
25
|
+
errors: result
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (options.includeCorrected) {
|
|
29
|
+
output.corrected = correctText(inputText, result);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
process.stdout.write(JSON.stringify(output));
|
|
33
|
+
} catch (err) {
|
|
34
|
+
process.stderr.write(err.message);
|
|
35
|
+
process.exit(1);
|
|
13
36
|
}
|
|
37
|
+
}
|
|
14
38
|
|
|
39
|
+
async function checkText(inputText, options) {
|
|
40
|
+
const result = await check(inputText);
|
|
15
41
|
const output = {
|
|
16
|
-
errors: result
|
|
17
|
-
|
|
42
|
+
errors: result
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (options.includeCorrected) {
|
|
46
|
+
output.corrected = correctText(inputText, result);
|
|
18
47
|
}
|
|
19
48
|
|
|
20
|
-
|
|
21
|
-
|
|
49
|
+
process.stdout.write(JSON.stringify(output));
|
|
50
|
+
}
|
|
22
51
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
52
|
+
function correctText(inputText, result) {
|
|
53
|
+
let correctedText = inputText;
|
|
54
|
+
for (const e of result) {
|
|
55
|
+
correctedText = correctedText.replaceAll(e.input, e.output);
|
|
56
|
+
}
|
|
57
|
+
return correctedText;
|
|
26
58
|
}
|