<commit_before>'use strict';

var startsWith = require('es5-ext/string/#/starts-with')
  , endsWith   = require('es5-ext/string/#/ends-with')
  , randomUniq = require('es5-ext/string/random-uniq')
  , nonAsciiRe = /[\0-\/:-@\[-`{-\uffff]/g
  , dashRe     = /-{2,}/g;

var generateFromName = (function () {
	var done = Object.create(null);
	return function (name) {
		var count;
		name = String(name).toLowerCase().trim().replace(nonAsciiRe, '-').replace(dashRe, '-');
		if (startsWith.call(name, '-')) name = name.slice(1);
		if (endsWith.call(name, '-')) name = name.slice(0, -1);
		if (!name) name = 'x';
		if (done[name]) {
			count = 2;
			while (done[name + '-' + count]) ++count;
			name = name + '-' + count;
		}
		done[name] = true;
		return name;
	};
}());

module.exports = function (name) {
	if (name != null) return generateFromName(name);
	return 'i' + randomUniq();
};<commit_msg>Fixed a (really) corner case with dupicated ids comming from generate-id.<commit_after>'use strict';

var startsWith = require('es5-ext/string/#/starts-with')
  , endsWith   = require('es5-ext/string/#/ends-with')
  , randomUniq = require('es5-ext/string/random-uniq')
  , nonAsciiRe = /[\0-\/:-@\[-`{-\uffff]/g
  , dashRe     = /-{2,}/g;

var generateFromName = (function () {
	var done = Object.create(null);
	return function (name) {
		var count;
		name = String(name).toLowerCase().trim().replace(nonAsciiRe, '-').replace(dashRe, '-');
		if (startsWith.call(name, '-')) name = name.slice(1);
		if (endsWith.call(name, '-')) name = name.slice(0, -1);
		if (!name) name = 'x';
		if (done[name]) {
			count = 2;
			while (done[name + '-' + count]) ++count;
			name = name + '-' + count;
		}
		done[name] = true;
		return name;
	};
}());

module.exports = function (name) {
	return generateFromName(name || ('i' + randomUniq()));
};
{'fraction_non_alphanumeric': 0.22289156626506024, 'fraction_numerical': 0.009857612267250822, 'mean_word_length': 3.522277227722772, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4864682', 'n_tokens_mistral': 717, 'n_tokens_neox': 683, 'n_words': 138}