--- /dev/null
+orig_file = 'wordlist.txt'
+compressed_file = 'wordlist_compressed.js'
+caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+fs = require 'fs'
+
+fs.readFile orig_file, 'utf8', (err, data) ->
+ if err?
+ console.log "Error reading #{orig_file}: #{err}"
+ process.exit(1)
+ else
+ fs.writeFile compressed_file, (compress data.split '\n'), (err) ->
+ if err?
+ console.log "Error writing to #{compressed_file}: #{err}"
+ process.exit(1)
+
+compress = (words) ->
+ out = 'parse_word_list(['
+ chunk = ''
+ prev = ''
+ for next in words
+ match = prev.length
+ while match and next.substr(0, match) isnt prev.substr(0, match)
+ --match
+ # now match is the number of prefix characters this word has in common with the previous
+ chunk += caps[prev.length - match]
+ if chunk.length > 2000
+ out += "'" + chunk.substr(1) + "',"
+ chunk = '.'
+ chunk += next.substr match
+ prev = next
+ return out + "'" + chunk.substr(1) + "']);"