wooorm / franc

Compare 8320d96 ... +0 ... 49970cc

Coverage Reach

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 2 of 7 files from the diff.

@@ -78,8 +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 +
  var only = [].concat(settings.whitelist || [], settings.only || [])
82 +
  var ignore = [].concat(settings.blacklist || [], settings.ignore || [])
83 83
  var script
84 84
85 85
  if (settings.minLength !== null && settings.minLength !== undefined) {
@@ -100,7 +100,7 @@
Loading
100 100
  if (!(script[0] in data)) {
101 101
    /* If no matches occured, such as a digit only string,
102 102
     * or because the language is ignored, exit with `und`. */
103 -
    if (script[1] === 0 || !allow(script[0], whitelist, blacklist)) {
103 +
    if (script[1] === 0 || !allow(script[0], only, ignore)) {
104 104
      return und()
105 105
    }
106 106
@@ -111,12 +111,7 @@
Loading
111 111
   * normalize the distance values. */
112 112
  return normalize(
113 113
    value,
114 -
    getDistances(
115 -
      utilities.asTuples(value),
116 -
      data[script[0]],
117 -
      whitelist,
118 -
      blacklist
119 -
    )
114 +
    getDistances(utilities.asTuples(value), data[script[0]], only, ignore)
120 115
  )
121 116
}
122 117
@@ -191,19 +186,18 @@
Loading
191 186
 *   array containing trigram--count tuples.
192 187
 * @param {Object.<Object>} languages - multiple
193 188
 *   trigrams to test against.
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 +
 * @param {Array.<string>} only - Allowed languages; if
190 +
 *   non-empty, only included languages are kept.
191 +
 * @param {Array.<string>} ignore - Disallowed languages;
192 +
 *   included languages are ignored.
199 193
 * @return {Array.<Array.<string, number>>} An array
200 194
 *   containing language--distance tuples.
201 195
 */
202 -
function getDistances(trigrams, languages, whitelist, blacklist) {
196 +
function getDistances(trigrams, languages, only, ignore) {
203 197
  var distances = []
204 198
  var language
205 199
206 -
  languages = filterLanguages(languages, whitelist, blacklist)
200 +
  languages = filterLanguages(languages, only, ignore)
207 201
208 202
  for (language in languages) {
209 203
    distances.push([language, getDistance(trigrams, languages[language])])
@@ -250,30 +244,29 @@
Loading
250 244
251 245
/**
252 246
 * Filter `languages` by removing languages in
253 -
 * `blacklist`, or including languages in `whitelist`.
247 +
 * `ignore`, or including languages in `only`.
254 248
 *
255 249
 * @param {Object.<Object>} languages - Languages
256 250
 *   to filter
257 -
 * @param {Array.<string>} whitelist - Whitelisted
258 -
 *   languages; if non-empty, only included languages
259 -
 *   are kept.
260 -
 * @param {Array.<string>} blacklist - Blacklisted
261 -
 *   languages; included languages are ignored.
251 +
 * @param {Array.<string>} only - Allowed languages; if
252 +
 *   non-empty, only included languages are kept.
253 +
 * @param {Array.<string>} ignore - Disallowed languages;
254 +
 *   included languages are ignored.
262 255
 * @return {Object.<Object>} - Filtered array of
263 256
 *   languages.
264 257
 */
265 -
function filterLanguages(languages, whitelist, blacklist) {
258 +
function filterLanguages(languages, only, ignore) {
266 259
  var filteredLanguages
267 260
  var language
268 261
269 -
  if (whitelist.length === 0 && blacklist.length === 0) {
262 +
  if (only.length === 0 && ignore.length === 0) {
270 263
    return languages
271 264
  }
272 265
273 266
  filteredLanguages = {}
274 267
275 268
  for (language in languages) {
276 -
    if (allow(language, whitelist, blacklist)) {
269 +
    if (allow(language, only, ignore)) {
277 270
      filteredLanguages[language] = languages[language]
278 271
    }
279 272
  }
@@ -286,21 +279,20 @@
Loading
286 279
 *
287 280
 * @param {string} language - Languages
288 281
 *   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.
282 +
 * @param {Array.<string>} only - Allowed languages; if
283 +
 *   non-empty, only included languages are kept.
284 +
 * @param {Array.<string>} ignore - Disallowed languages;
285 +
 *   included languages are ignored.
294 286
 * @return {boolean} - Whether `language` can match
295 287
 */
296 -
function allow(language, whitelist, blacklist) {
297 -
  if (whitelist.length === 0 && blacklist.length === 0) {
288 +
function allow(language, only, ignore) {
289 +
  if (only.length === 0 && ignore.length === 0) {
298 290
    return true
299 291
  }
300 292
301 293
  return (
302 -
    (whitelist.length === 0 || whitelist.indexOf(language) !== -1) &&
303 -
    blacklist.indexOf(language) === -1
294 +
    (only.length === 0 || only.indexOf(language) !== -1) &&
295 +
    ignore.indexOf(language) === -1
304 296
  )
305 297
}
306 298

@@ -17,10 +17,18 @@
Loading
17 17
      type: 'string',
18 18
      alias: 'w'
19 19
    },
20 +
    only: {
21 +
      type: 'string',
22 +
      alias: 'o'
23 +
    },
20 24
    blacklist: {
21 25
      type: 'string',
22 26
      alias: 'b'
23 27
    },
28 +
    ignore: {
29 +
      type: 'string',
30 +
      alias: 'i'
31 +
    },
24 32
    minLength: {
25 33
      type: 'string',
26 34
      alias: 'm'
@@ -41,13 +49,10 @@
Loading
41 49
42 50
flags.minLength = Number(flags.minLength) || null
43 51
44 -
if (flags.whitelist) {
45 -
  flags.whitelist = String(flags.whitelist).split(',')
46 -
}
47 -
48 -
if (flags.blacklist) {
49 -
  flags.blacklist = String(flags.blacklist).split(',')
50 -
}
52 +
flags.whitelist = list(flags.whitelist)
53 +
flags.blacklist = list(flags.blacklist)
54 +
flags.only = flags.whitelist.concat(list(flags.only))
55 +
flags.ignore = flags.blacklist.concat(list(flags.ignore))
51 56
52 57
if (value) {
53 58
  detect(value)
@@ -62,8 +67,8 @@
Loading
62 67
function detect(value) {
63 68
  var options = {
64 69
    minLength: flags.minLength,
65 -
    whitelist: flags.whitelist,
66 -
    blacklist: flags.blacklist
70 +
    only: flags.only,
71 +
    ignore: flags.ignore
67 72
  }
68 73
69 74
  if (flags.all) {
@@ -84,8 +89,8 @@
Loading
84 89
    '  -h, --help                    output usage information',
85 90
    '  -v, --version                 output version number',
86 91
    '  -m, --min-length <number>     minimum length to accept',
87 -
    '  -w, --whitelist <string>      allow languages',
88 -
    '  -b, --blacklist <string>      disallow languages',
92 +
    '  -o, --only <string>           allow languages',
93 +
    '  -i, --ignore <string>         disallow languages',
89 94
    '  -a, --all                     display all guesses',
90 95
    '',
91 96
    'Usage:',
@@ -98,20 +103,16 @@
Loading
98 103
    '$ echo "এটি একটি ভাষা একক IBM স্ক্রিপ্ট" | ' + command,
99 104
    '# ' + franc('এটি একটি ভাষা একক IBM স্ক্রিপ্ট'),
100 105
    '',
101 -
    '# blacklist certain languages',
102 -
    '$ ' + command + ' --blacklist por,glg "O Brasil caiu 26 posições"',
103 -
    '# ' +
104 -
      franc('O Brasil caiu 26 posições', {
105 -
        blacklist: ['por', 'glg']
106 -
      }),
106 +
    '# ignore certain languages',
107 +
    '$ ' + command + ' --ignore por,glg "O Brasil caiu 26 posições"',
108 +
    '# ' + franc('O Brasil caiu 26 posições', {ignore: ['por', 'glg']}),
107 109
    '',
108 -
    '# output language from stdin with whitelist',
109 -
    '$ echo "Alle mennesker er født frie og" | ' +
110 -
      command +
111 -
      ' --whitelist nob,dan',
112 -
    '# ' +
113 -
      franc('Alle mennesker er født frie og', {
114 -
        whitelist: ['nob', 'dan']
115 -
      })
110 +
    '# output language from stdin with only',
111 +
    '$ echo "Alle mennesker er født frie og" | ' + command + ' --only nob,dan',
112 +
    '# ' + franc('Alle mennesker er født frie og', {only: ['nob', 'dan']})
116 113
  ].join('\n')
117 114
}
115 +
116 +
function list(value) {
117 +
  return value ? String(value).split(',') : []
118 +
}

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
packages 100.00%
Project Totals (3 files) 100.00%
Loading