Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}