import prettyHrTime from "pretty-hrtime";
import string from "@poppinss/utils/string";
import he from "he";
import StringBuilder from "@poppinss/utils/string_builder";
//#region src/helpers/string.ts
/**
* Collection of string helpers to transform a string value. This object extends
* the base string utilities from @poppinss/utils with additional AdonisJS-specific
* string manipulation methods.
*
* @example
* // Basic string transformations
* stringHelpers.camelCase('hello_world') // 'helloWorld'
* stringHelpers.snakeCase('HelloWorld')   // 'hello_world'
* stringHelpers.pascalCase('hello world') // 'HelloWorld'
*
* @example
* // HTML escaping and encoding
* stringHelpers.escapeHTML('<script>alert("xss")<\/script>')
* stringHelpers.encodeSymbols('© 2023 AdonisJS')
*/
const stringHelpers = {
	...string,
	toSentence: string.sentence,
	ordinalize: string.ordinal,
	generateRandom: string.random,
	create(value) {
		return new StringBuilder(value);
	},
	/**
	* Formats Node.js hrtime output into a human-readable string.
	*
	* @param time - Tuple of [seconds, nanoseconds] from process.hrtime()
	* @param options - Formatting options for output style and precision
	*/
	prettyHrTime(time, options) {
		return prettyHrTime(time, options);
	},
	/**
	* Check if a string is empty or contains only whitespace characters.
	*
	* @param value - The string to check for emptiness
	*/
	isEmpty(value) {
		return value.trim().length === 0;
	},
	/**
	* Escape HTML entities to prevent XSS attacks and display HTML safely.
	*
	* @param value - The string containing HTML to escape
	* @param options - Optional configuration for escaping behavior
	* @param options.encodeSymbols - Whether to also encode Unicode symbols as HTML entities
	*/
	escapeHTML(value, options) {
		value = he.escape(value);
		if (options && options.encodeSymbols) value = this.encodeSymbols(value, { allowUnsafeSymbols: true });
		return value;
	},
	/**
	* Encode Unicode symbols and special characters as HTML entities.
	*
	* @param value - The string containing symbols to encode
	* @param options - Encoding options from the 'he' library
	*/
	encodeSymbols(value, options) {
		return he.encode(value, options);
	}
};
//#endregion
export { stringHelpers as t };
