-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspellcheck.coffee
51 lines (39 loc) · 1.46 KB
/
spellcheck.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fs = require 'fs'
list = require './wordlist.json'
config = require './scconfig.json'
space = if config.space? then config.space else ''
isPathGood = (path)->
if config.skipHidden and path.indexOf('./.') is 0 then return false
if path.indexOf("node_modules") > -1 then return false
if path.indexOf("output.csv") > -1 then return false
if path.indexOf("wordlist.json") > -1 then return false
if path.indexOf("spellcheck.js") > -1 then return false
if path.indexOf("scconfig.json") > -1 then return false
return true
buildWordList = ()->
for word in list
if config.skipUpto and word.Wrong.toLowerCase() is "upto" then continue
if config.skipContractions and word.Correct.indexOf("'") isnt -1 then continue
word.Single = word.Correct.indexOf('-') is -1
word.CorrectFull = "#{space}#{word.Correct}#{space}"
word.WrongFull = "#{space}#{word.Wrong}#{space}"
search = (path)->
lpath = path.toLowerCase()
if not isPathGood lpath then return
data = fs.readFileSync path, config.encoding
changed = false
for word in list when word.Single
if data.indexOf(word.WrongFull) isnt -1
data = data.replace word.WrongFull, word.CorrectFull
console.log "#{path} - #{word.Wrong} to #{word.Correct}"
changed = true
if changed
fs.writeFileSync path, data, config.encoding
return
buildWordList()
index = -1
for path in process.argv
index += 1
if index < 2 then continue
if path.length < 2 then continue
search "#{path}"