Closes GH-70. Closes GH-72.
Showing 1 of 2 files from the diff.
packages/franc/index.js
changed.
Other files ignored by Codecov
test/api.js
has changed.
@@ -78,6 +78,8 @@
Loading
78 | 78 | function detectAll(value, options) { |
|
79 | 79 | var settings = options || {} |
|
80 | 80 | var minLength = MIN_LENGTH |
|
81 | + | var whitelist = settings.whitelist || [] |
|
82 | + | var blacklist = settings.blacklist || [] |
|
81 | 83 | var script |
|
82 | 84 | ||
83 | 85 | if (settings.minLength !== null && settings.minLength !== undefined) { |
@@ -94,19 +96,27 @@
Loading
94 | 96 | * in `value`. */ |
|
95 | 97 | script = getTopScript(value, expressions) |
|
96 | 98 | ||
97 | - | /* One languages exists for the most-used script. |
|
98 | - | * |
|
99 | - | * If no matches occured, such as a digit only string, |
|
100 | - | * exit with `und`. */ |
|
99 | + | /* One languages exists for the most-used script. */ |
|
101 | 100 | if (!(script[0] in data)) { |
|
102 | - | return script[1] === 0 ? und() : singleLanguageTuples(script[0]) |
|
101 | + | /* If no matches occured, such as a digit only string, |
|
102 | + | * or because the language is ignored, exit with `und`. */ |
|
103 | + | if (script[1] === 0 || !allow(script[0], whitelist, blacklist)) { |
|
104 | + | return und() |
|
105 | + | } |
|
106 | + | ||
107 | + | return singleLanguageTuples(script[0]) |
|
103 | 108 | } |
|
104 | 109 | ||
105 | 110 | /* Get all distances for a given script, and |
|
106 | 111 | * normalize the distance values. */ |
|
107 | 112 | return normalize( |
|
108 | 113 | value, |
|
109 | - | getDistances(utilities.asTuples(value), data[script[0]], settings) |
|
114 | + | getDistances( |
|
115 | + | utilities.asTuples(value), |
|
116 | + | data[script[0]], |
|
117 | + | whitelist, |
|
118 | + | blacklist |
|
119 | + | ) |
|
110 | 120 | ) |
|
111 | 121 | } |
|
112 | 122 |
@@ -181,14 +191,16 @@
Loading
181 | 191 | * array containing trigram--count tuples. |
|
182 | 192 | * @param {Object.<Object>} languages - multiple |
|
183 | 193 | * trigrams to test against. |
|
184 | - | * @param {Object} options - Configuration. |
|
194 | + | * @param {Array.<string>} whitelist - Whitelisted |
|
195 | + | * languages; if non-empty, only included languages |
|
196 | + | * are kept. |
|
197 | + | * @param {Array.<string>} blacklist - Blacklisted |
|
198 | + | * languages; included languages are ignored. |
|
185 | 199 | * @return {Array.<Array.<string, number>>} An array |
|
186 | 200 | * containing language--distance tuples. |
|
187 | 201 | */ |
|
188 | - | function getDistances(trigrams, languages, options) { |
|
202 | + | function getDistances(trigrams, languages, whitelist, blacklist) { |
|
189 | 203 | var distances = [] |
|
190 | - | var whitelist = options.whitelist || [] |
|
191 | - | var blacklist = options.blacklist || [] |
|
192 | 204 | var language |
|
193 | 205 | ||
194 | 206 | languages = filterLanguages(languages, whitelist, blacklist) |
@@ -261,10 +273,7 @@
Loading
261 | 273 | filteredLanguages = {} |
|
262 | 274 | ||
263 | 275 | for (language in languages) { |
|
264 | - | if ( |
|
265 | - | (whitelist.length === 0 || whitelist.indexOf(language) !== -1) && |
|
266 | - | blacklist.indexOf(language) === -1 |
|
267 | - | ) { |
|
276 | + | if (allow(language, whitelist, blacklist)) { |
|
268 | 277 | filteredLanguages[language] = languages[language] |
|
269 | 278 | } |
|
270 | 279 | } |
@@ -272,6 +281,29 @@
Loading
272 | 281 | return filteredLanguages |
|
273 | 282 | } |
|
274 | 283 | ||
284 | + | /** |
|
285 | + | * Check if `language` can match according to settings. |
|
286 | + | * |
|
287 | + | * @param {string} language - Languages |
|
288 | + | * to filter |
|
289 | + | * @param {Array.<string>} whitelist - Whitelisted |
|
290 | + | * languages; if non-empty, only included languages |
|
291 | + | * are kept. |
|
292 | + | * @param {Array.<string>} blacklist - Blacklisted |
|
293 | + | * languages; included languages are ignored. |
|
294 | + | * @return {boolean} - Whether `language` can match |
|
295 | + | */ |
|
296 | + | function allow(language, whitelist, blacklist) { |
|
297 | + | if (whitelist.length === 0 && blacklist.length === 0) { |
|
298 | + | return true |
|
299 | + | } |
|
300 | + | ||
301 | + | return ( |
|
302 | + | (whitelist.length === 0 || whitelist.indexOf(language) !== -1) && |
|
303 | + | blacklist.indexOf(language) === -1 |
|
304 | + | ) |
|
305 | + | } |
|
306 | + | ||
275 | 307 | /* Create a single `und` tuple. */ |
|
276 | 308 | function und() { |
|
277 | 309 | return singleLanguageTuples('und') |
Files | Coverage |
---|---|
packages | 100.00% |
Project Totals (3 files) | 100.00% |
210.1
TRAVIS_NODE_VERSION=lts/boron TRAVIS_OS_NAME=linux
210.2
TRAVIS_NODE_VERSION=node TRAVIS_OS_NAME=linux
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.