-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
21 lines (20 loc) · 745 Bytes
/
index.js
File metadata and controls
21 lines (20 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const { parse } = require('url')
const { send } = require('micro')
const writeGood = require('write-good')
const nodehun = require('nodehun')
const spellcheck = require('nodehun-sentences')
const fs = require('fs')
const affbuf = fs.readFileSync('./dictionaries/en_US.aff')
const dictbuf = fs.readFileSync('./dictionaries/en_US.dic')
const dict = new nodehun(affbuf, dictbuf)
module.exports = (req, res) => {
const { query: { text } } = parse(req.url, true)
if (!text) return send(res, 401, { message: 'Please supply a text to be linted.' })
const suggestions = writeGood(text)
spellcheck(dict, text, (err, typos) => {
if (err) {
send(res, 200, {text, suggestions})
}
send(res, 200, {text, suggestions, typos})
})
}