-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
897 additions
and
1,009 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage/ | ||
nspell.js | ||
nspell.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
module.exports = add; | ||
module.exports = add | ||
|
||
var own = {}.hasOwnProperty; | ||
var own = {}.hasOwnProperty | ||
|
||
/* Add `value` to the checker. */ | ||
function add(value, model) { | ||
var self = this; | ||
var dict = self.data; | ||
var self = this | ||
var dict = self.data | ||
|
||
dict[value] = []; | ||
dict[value] = [] | ||
|
||
if (model && own.call(dict, model) && dict[model]) { | ||
dict[value] = dict[model].concat(); | ||
dict[value] = dict[model].concat() | ||
} | ||
|
||
return self; | ||
return self | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
var trim = require('trim'); | ||
var form = require('./util/form.js'); | ||
var trim = require('trim') | ||
var form = require('./util/form.js') | ||
|
||
module.exports = correct; | ||
module.exports = correct | ||
|
||
/* Check spelling of `value`. */ | ||
function correct(value) { | ||
return Boolean(form(this, trim(value))); | ||
return Boolean(form(this, trim(value))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
var parse = require('./util/dictionary.js'); | ||
var parse = require('./util/dictionary.js') | ||
|
||
module.exports = add; | ||
module.exports = add | ||
|
||
/* Add a dictionary file. */ | ||
function add(buf) { | ||
var self = this; | ||
var compound = self.compoundRules; | ||
var compoundCodes = self.compoundRuleCodes; | ||
var index = -1; | ||
var length = compound.length; | ||
var rule; | ||
var source; | ||
var character; | ||
var offset; | ||
var count; | ||
|
||
parse(buf, self, self.data); | ||
var self = this | ||
var compound = self.compoundRules | ||
var compoundCodes = self.compoundRuleCodes | ||
var index = -1 | ||
var length = compound.length | ||
var rule | ||
var source | ||
var character | ||
var offset | ||
var count | ||
|
||
parse(buf, self, self.data) | ||
|
||
/* Regenerate compound expressions. */ | ||
while (++index < length) { | ||
rule = compound[index]; | ||
source = ''; | ||
rule = compound[index] | ||
source = '' | ||
|
||
offset = -1; | ||
count = rule.length; | ||
offset = -1 | ||
count = rule.length | ||
|
||
while (++offset < count) { | ||
character = rule.charAt(offset); | ||
character = rule.charAt(offset) | ||
|
||
if (compoundCodes[character].length === 0) { | ||
source += character; | ||
source += character | ||
} else { | ||
source += '(?:' + compoundCodes[character].join('|') + ')'; | ||
source += '(?:' + compoundCodes[character].join('|') + ')' | ||
} | ||
} | ||
|
||
compound[index] = new RegExp(source, 'i'); | ||
compound[index] = new RegExp(source, 'i') | ||
} | ||
|
||
return self; | ||
return self | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,70 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
var buffer = require('is-buffer'); | ||
var affix = require('./util/affix.js'); | ||
var buffer = require('is-buffer') | ||
var affix = require('./util/affix.js') | ||
|
||
module.exports = NSpell; | ||
module.exports = NSpell | ||
|
||
var proto = NSpell.prototype; | ||
var proto = NSpell.prototype | ||
|
||
proto.correct = require('./correct.js'); | ||
proto.suggest = require('./suggest.js'); | ||
proto.spell = require('./spell.js'); | ||
proto.add = require('./add.js'); | ||
proto.remove = require('./remove.js'); | ||
proto.wordCharacters = require('./word-characters.js'); | ||
proto.dictionary = require('./dictionary.js'); | ||
proto.personal = require('./personal.js'); | ||
proto.correct = require('./correct.js') | ||
proto.suggest = require('./suggest.js') | ||
proto.spell = require('./spell.js') | ||
proto.add = require('./add.js') | ||
proto.remove = require('./remove.js') | ||
proto.wordCharacters = require('./word-characters.js') | ||
proto.dictionary = require('./dictionary.js') | ||
proto.personal = require('./personal.js') | ||
|
||
/* Construct a new spelling context. */ | ||
function NSpell(aff, dic) { | ||
var length; | ||
var index; | ||
var dictionaries; | ||
var length | ||
var index | ||
var dictionaries | ||
|
||
if (!(this instanceof NSpell)) { | ||
return new NSpell(aff, dic); | ||
return new NSpell(aff, dic) | ||
} | ||
|
||
if (typeof aff === 'string' || buffer(aff)) { | ||
if (typeof dic === 'string' || buffer(dic)) { | ||
dictionaries = [{dic: dic}]; | ||
dictionaries = [{dic: dic}] | ||
} | ||
} else if (aff) { | ||
if ('length' in aff) { | ||
dictionaries = aff; | ||
aff = aff[0] && aff[0].aff; | ||
dictionaries = aff | ||
aff = aff[0] && aff[0].aff | ||
} else { | ||
if (aff.dic) { | ||
dictionaries = [aff]; | ||
dictionaries = [aff] | ||
} | ||
|
||
aff = aff.aff; | ||
aff = aff.aff | ||
} | ||
} | ||
|
||
if (!aff) { | ||
throw new Error('Missing `aff` in dictionary'); | ||
throw new Error('Missing `aff` in dictionary') | ||
} | ||
|
||
aff = affix(aff); | ||
aff = affix(aff) | ||
|
||
this.data = {}; | ||
this.compoundRuleCodes = aff.compoundRuleCodes; | ||
this.replacementTable = aff.replacementTable; | ||
this.conversion = aff.conversion; | ||
this.compoundRules = aff.compoundRules; | ||
this.rules = aff.rules; | ||
this.flags = aff.flags; | ||
this.data = {} | ||
this.compoundRuleCodes = aff.compoundRuleCodes | ||
this.replacementTable = aff.replacementTable | ||
this.conversion = aff.conversion | ||
this.compoundRules = aff.compoundRules | ||
this.rules = aff.rules | ||
this.flags = aff.flags | ||
|
||
length = dictionaries ? dictionaries.length : 0; | ||
index = -1; | ||
length = dictionaries ? dictionaries.length : 0 | ||
index = -1 | ||
|
||
while (++index < length) { | ||
dic = dictionaries[index]; | ||
dic = dictionaries[index] | ||
|
||
if (dic && dic.dic) { | ||
this.dictionary(dic.dic); | ||
this.dictionary(dic.dic) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
var trim = require('trim'); | ||
var trim = require('trim') | ||
|
||
module.exports = add; | ||
module.exports = add | ||
|
||
/* Add a dictionary. */ | ||
function add(buf) { | ||
var self = this; | ||
var flags = self.flags; | ||
var lines = buf.toString('utf8').split('\n'); | ||
var length = lines.length; | ||
var index = -1; | ||
var line; | ||
var forbidden; | ||
var word; | ||
var model; | ||
var flag; | ||
var self = this | ||
var flags = self.flags | ||
var lines = buf.toString('utf8').split('\n') | ||
var length = lines.length | ||
var index = -1 | ||
var line | ||
var forbidden | ||
var word | ||
var model | ||
var flag | ||
|
||
/* Ensure there’s a key for `FORBIDDENWORD`: `false` | ||
* cannot be set through an affix file so its safe to use | ||
* as a magic constant. */ | ||
flag = flags.FORBIDDENWORD || false; | ||
flags.FORBIDDENWORD = flag; | ||
flag = flags.FORBIDDENWORD || false | ||
flags.FORBIDDENWORD = flag | ||
|
||
while (++index < length) { | ||
line = trim(lines[index]); | ||
line = trim(lines[index]) | ||
|
||
if (!line) { | ||
continue; | ||
continue | ||
} | ||
|
||
line = line.split('/'); | ||
word = line[0]; | ||
model = line[1]; | ||
forbidden = word.charAt(0) === '*'; | ||
line = line.split('/') | ||
word = line[0] | ||
model = line[1] | ||
forbidden = word.charAt(0) === '*' | ||
|
||
if (forbidden) { | ||
word = word.slice(1); | ||
word = word.slice(1) | ||
} | ||
|
||
self.add(word, model); | ||
self.add(word, model) | ||
|
||
if (forbidden) { | ||
self.data[word].push(flag); | ||
self.data[word].push(flag) | ||
} | ||
} | ||
|
||
return self; | ||
return self | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
module.exports = remove; | ||
module.exports = remove | ||
|
||
/* Remove `value` from the checker. */ | ||
function remove(value) { | ||
var self = this; | ||
var self = this | ||
|
||
self.data[value] = null; | ||
self.data[value] = null | ||
|
||
return self; | ||
return self | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
var form = require('./util/form.js'); | ||
var flag = require('./util/flag.js'); | ||
var form = require('./util/form.js') | ||
var flag = require('./util/flag.js') | ||
|
||
module.exports = spell; | ||
module.exports = spell | ||
|
||
/* Check spelling of `word`. */ | ||
function spell(word) { | ||
var self = this; | ||
var dict = self.data; | ||
var flags = self.flags; | ||
var value = form(self, word, true); | ||
var self = this | ||
var dict = self.data | ||
var flags = self.flags | ||
var value = form(self, word, true) | ||
|
||
/* Hunspell also provides `root` (root word of the input word), | ||
* and `compound` (whether `word` was compound). */ | ||
return { | ||
correct: self.correct(word), | ||
forbidden: Boolean(value && flag(flags, 'FORBIDDENWORD', dict[value])), | ||
warn: Boolean(value && flag(flags, 'WARN', dict[value])) | ||
}; | ||
} | ||
} |
Oops, something went wrong.