5
5
*/
6
6
7
7
/**
8
- * @callback Dictionary
8
+ * @typedef Dictionary
9
+ * A hunspell dictionary.
10
+ * @property {Uint8Array } aff
11
+ * Data for the affix file (defines the language, keyboard, flags, and more).
12
+ * @property {Uint8Array } dic
13
+ * Data for the dictionary file (contains words and flags applying to those words).
14
+ *
15
+ * @callback DictionaryCallback
9
16
* Dictionary function.
10
17
* @param {DictionaryOnLoad } onload
11
18
* Callback called when the dictionary is loaded.
18
25
* Callback called when the dictionary is loaded.
19
26
* @param {Error | undefined } error
20
27
* Error.
21
- * @param {unknown } [result]
28
+ * @param {Dictionary } [result]
22
29
* Dictionary.
23
30
* @returns {undefined | void }
24
31
* Nothing.
27
34
*
28
35
* @typedef Options
29
36
* Configuration.
30
- * @property {Dictionary } dictionary
31
- * Dictionary function (required);
37
+ * @property {Dictionary | DictionaryCallback } dictionary
38
+ * Dictionary (required);
32
39
* result of importing one of the dictionaries in `wooorm/dictionaries`.
33
40
* @property {ReadonlyArray<string> | null | undefined } [ignore]
34
41
* List of words to ignore (optional).
@@ -80,15 +87,17 @@ const emptyIgnore = []
80
87
/**
81
88
* Check spelling.
82
89
*
83
- * @param {Readonly<Options> | Dictionary } options
90
+ * @param {Readonly<Options> | DictionaryCallback | Dictionary } options
84
91
* Configuration or dictionary (required).
85
92
* @returns
86
93
* Transform.
87
94
*/
88
95
export default function retextSpell ( options ) {
89
96
const settings =
90
- typeof options === 'function' ? { dictionary : options } : options || { }
91
- const dictionary = settings . dictionary
97
+ typeof options === 'function' ||
98
+ ( options && 'aff' in options && 'dic' in options )
99
+ ? { dictionary : options }
100
+ : options || { }
92
101
const ignore = settings . ignore || emptyIgnore
93
102
const ignoreLiteral =
94
103
typeof settings . ignoreLiteral === 'boolean' ? settings . ignoreLiteral : true
@@ -102,7 +111,7 @@ export default function retextSpell(options) {
102
111
: true
103
112
const personal = settings . personal
104
113
105
- if ( typeof dictionary !== 'function' ) {
114
+ if ( ! settings . dictionary ) {
106
115
throw new TypeError ( 'Missing `dictionary` in options' )
107
116
}
108
117
@@ -125,7 +134,11 @@ export default function retextSpell(options) {
125
134
126
135
// Callback called when a `dictionary` is loaded or when `load`ing failed.
127
136
// Flushes the queue when available, and sets the results on the parent scope.
128
- dictionary ( onload )
137
+ if ( typeof settings . dictionary === 'function' ) {
138
+ settings . dictionary ( onload )
139
+ } else {
140
+ onload ( undefined , settings . dictionary )
141
+ }
129
142
130
143
/**
131
144
* Transform.
0 commit comments