How to use the tlds.filter function in tlds

To help you get started, we’ve selected a few tlds examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github markdown-it / linkify-it / support / tlds_2char_gen.js View on Github external
for (i = 1; ; i++) {
      if (str[i] !== String.fromCharCode(str[i - 1].charCodeAt(0) + 1)) {
        if (i < 3) {
          ranges.push(str.slice(0, i));
        } else {
          ranges.push(str[0] + '-' + str[i - 1]);
        }
        str = str.slice(i);
        break;
      }
    }
  }
  return '[' + ranges.join('') + ']';
}

var tlds = require('tlds').filter(name => /^[a-z]{2}$/.test(name)).sort();

//
// group by first letter
//

var result = [];

'abcdefghijklmnopqrstuvwxyz'.split('').forEach(letter => {
  var list = tlds.filter(name => name[0] === letter);

  if (!list.length) { return; }

  if (list.length < 2) {
    result = result.concat(list);
    return;
  }

tlds

A list of TLDs.

MIT
Latest version published 1 month ago

Package Health Score

78 / 100
Full package analysis