<commit_before>/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author <NAME> @sokra
*/

"use strict";

const createHash = require("../util/createHash");
const { makePathsRelative } = require("../util/identifier");

/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("../ChunkGraph")} ChunkGraph */
/** @typedef {import("../Compilation")} Compilation */
/** @typedef {import("../Module")} Module */

/**
 * @param {string} str string to hash
 * @param {number} len max length of the hash
 * @returns {string} hash
 */
const getHash = (str, len) => {
	const hash = createHash("md4");
	hash.update(str);
	return hash.digest("hex").substr(0, len);
};

/**
 * @param {string} str string to hash
 * @param {number} len max length of the number in decimal digests
 * @returns {number} hash as number in the range from i. e. for len = 3: 0 - 999
 */
const getHashNumber = (str, len) => {
	const hash = createHash("md4");
	hash.update(str);
	const digest = hash.digest("hex");
	let i = 0;
	let result = "";
	while (i < digest.length && result.length < len) {
		if (digest.charCodeAt(i) < 58) {
			result += digest[i];
		}
		i++;
	}

	return +(result + "10000000000".slice(0, len - result.length));
};

/**
 * @param {string} str the string
 * @returns {string} string prefixed by an underscore if it is a number
 */
const avoidNumber = str => {
	if (str === +str + "") {
		return `_${str}`;
	}
	return str;
};

/**
 * @param {string} request the request
 * @returns {string} id representation
 */
const requestToId = request => {
	return request
		.replace(/^(\.\.?\/)+/, "")
		.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
};
exports.requestToId = requestToId;

/**
 * @param {string} string the string
 * @param {string} delimiter separator for string and hash
 * @returns {string} string with limited max length to 100 chars
 */<commit_msg>Get rid of string<commit_after>/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author <NAME> @sokra
*/

"use strict";

const createHash = require("../util/createHash");
const { makePathsRelative } = require("../util/identifier");

/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("../ChunkGraph")} ChunkGraph */
/** @typedef {import("../Compilation")} Compilation */
/** @typedef {import("../Module")} Module */

/**
 * @param {string} str string to hash
 * @param {number} len max length of the hash
 * @returns {string} hash
 */
const getHash = (str, len) => {
	const hash = createHash("md4");
	hash.update(str);
	return hash.digest("hex").substr(0, len);
};

/**
 * @param {string} str string to hash
 * @param {number} len max length of the number in decimal digests
 * @returns {number} hash as number in the range from i. e. for len = 3: 0 - 999
 */
const getHashNumber = (str, len) => {
	const hash = createHash("md4");
	hash.update(str);
	const digest = hash.digest("hex");
	let result = 0;
	for (let i = 0; i < digest.length; i++) {
		const charCode = digest.charCodeAt(i);
		if (charCode < 58) {
			result = result * 10 + (charCode - 48);
			len--;
			if (len < 1) {
				return result;
			}
		}
	}

	return len > 0 ? (result * 10 + 1) * Math.pow(10, len - 1) : result;
};

/**
 * @param {string} str the string
 * @returns {string} string prefixed by an underscore if it is a number
 */
const avoidNumber = str => {
	if (str === +str + "") {
		return `_${str}`;
	}
	return str;
};

/**
 * @param {string} request the request
 * @returns {string} id representation
 */
const requestToId = request => {
	return request
		.replace(/^(\.\.?\/)+/, "")
		.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
};
exports.requestToId = requestToId;

/**
 * @param {string} string the string
 * @param {string} delimiter separator for string and hash
 * @returns {string} string with limited max length to 100 chars
 */
{'fraction_non_alphanumeric': 0.19275210084033614, 'fraction_numerical': 0.014968487394957984, 'mean_word_length': 3.4601873536299768, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '2317042', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1267, 'n_words': 395}