wooorm / franc
Showing 1 of 1 files from the diff.

@@ -78,6 +78,7 @@
Loading
78 78
function detectAll(value, options) {
79 79
  var settings = options || {}
80 80
  var minLength = MIN_LENGTH
81 +
  var whitelist = settings.whitelist || []
81 82
  var blacklist = settings.blacklist || []
82 83
  var script
83 84
@@ -99,7 +100,7 @@
Loading
99 100
  if (!(script[0] in data)) {
100 101
    /* If no matches occured, such as a digit only string,
101 102
     * or because the language is ignored, exit with `und`. */
102 -
    if (script[1] === 0 || blacklist.indexOf(script[0]) !== -1) {
103 +
    if (script[1] === 0 || !allow(script[0], whitelist, blacklist)) {
103 104
      return und()
104 105
    }
105 106
@@ -110,7 +111,12 @@
Loading
110 111
   * normalize the distance values. */
111 112
  return normalize(
112 113
    value,
113 -
    getDistances(utilities.asTuples(value), data[script[0]], settings)
114 +
    getDistances(
115 +
      utilities.asTuples(value),
116 +
      data[script[0]],
117 +
      whitelist,
118 +
      blacklist
119 +
    )
114 120
  )
115 121
}
116 122
@@ -185,14 +191,16 @@
Loading
185 191
 *   array containing trigram--count tuples.
186 192
 * @param {Object.<Object>} languages - multiple
187 193
 *   trigrams to test against.
188 -
 * @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.
189 199
 * @return {Array.<Array.<string, number>>} An array
190 200
 *   containing language--distance tuples.
191 201
 */
192 -
function getDistances(trigrams, languages, options) {
202 +
function getDistances(trigrams, languages, whitelist, blacklist) {
193 203
  var distances = []
194 -
  var whitelist = options.whitelist || []
195 -
  var blacklist = options.blacklist || []
196 204
  var language
197 205
198 206
  languages = filterLanguages(languages, whitelist, blacklist)
@@ -265,10 +273,7 @@
Loading
265 273
  filteredLanguages = {}
266 274
267 275
  for (language in languages) {
268 -
    if (
269 -
      (whitelist.length === 0 || whitelist.indexOf(language) !== -1) &&
270 -
      blacklist.indexOf(language) === -1
271 -
    ) {
276 +
    if (allow(language, whitelist, blacklist)) {
272 277
      filteredLanguages[language] = languages[language]
273 278
    }
274 279
  }
@@ -276,6 +281,29 @@
Loading
276 281
  return filteredLanguages
277 282
}
278 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 +
279 307
/* Create a single `und` tuple. */
280 308
function und() {
281 309
  return singleLanguageTuples('und')
Files Coverage
packages 100.00%
Project Totals (3 files) 100.00%
208.2
TRAVIS_NODE_VERSION=node
TRAVIS_OS_NAME=linux
207.2
TRAVIS_NODE_VERSION=node
TRAVIS_OS_NAME=linux
208.1
TRAVIS_NODE_VERSION=lts/boron
TRAVIS_OS_NAME=linux
207.1
TRAVIS_NODE_VERSION=lts/boron
TRAVIS_OS_NAME=linux

No yaml found.

Create your codecov.yml to customize your Codecov experience

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.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading