"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });

//#region src/fs/encoding.ts
/**
* Normalize encoding string to canonical form. Handles common encodings inline
* for performance, delegates to slowCases for others.
*
* Based on Node.js internal/util.js normalizeEncoding implementation.
*
* @example
*   ;```ts
*   normalizeEncoding('UTF-8') // Returns 'utf8'
*   normalizeEncoding('binary') // Returns 'latin1'
*   normalizeEncoding('ucs-2') // Returns 'utf16le'
*   normalizeEncoding(null) // Returns 'utf8'
*   ```
*
* @param enc - Encoding to normalize (can be null/undefined)
*
* @returns Normalized encoding string, defaults to 'utf8'
*
* @see https://github.com/nodejs/node/blob/ae62b36d442b7bf987e85ae6e0df0f02cc1bb17f/lib/internal/util.js#L247-L310
*/
/*@__NO_SIDE_EFFECTS__*/
function normalizeEncoding(enc) {
	return enc == null || enc === "utf8" || enc === "utf-8" ? "utf8" : /* @__PURE__ */ normalizeEncodingSlow(enc);
}
/**
* Move the "slow cases" to a separate function to make sure this function gets
* inlined properly. That prioritizes the common case.
*
* Based on Node.js internal/util.js normalizeEncoding implementation.
*
* @example
*   ;```typescript
*   normalizeEncodingSlow('ucs2') // 'utf16le'
*   normalizeEncodingSlow('LATIN1') // 'latin1'
*   normalizeEncodingSlow('binary') // 'latin1'
*   ```
*
* @param enc - Encoding to normalize.
*
* @returns Normalized encoding string, defaults to 'utf8' for unknown encodings
*
* @see https://github.com/nodejs/node/blob/ae62b36d442b7bf987e85ae6e0df0f02cc1bb17f/lib/internal/util.js#L247-L310
*/
/*@__NO_SIDE_EFFECTS__*/
function normalizeEncodingSlow(enc) {
	const { length } = enc;
	if (length === 4) {
		if (enc === "ucs2" || enc === "UCS2") return "utf16le";
		if (enc.toLowerCase() === "ucs2") return "utf16le";
	} else if (length === 3 && enc === "hex" || enc === "HEX" || enc.toLowerCase() === "hex") return "hex";
	else if (length === 5) {
		if (enc === "ascii") return "ascii";
		if (enc === "ucs-2") return "utf16le";
		if (enc === "ASCII") return "ascii";
		if (enc === "UCS-2") return "utf16le";
		enc = enc.toLowerCase();
		if (enc === "ascii") return "ascii";
		if (enc === "ucs-2") return "utf16le";
	} else if (length === 6) {
		if (enc === "base64") return "base64";
		if (enc === "latin1" || enc === "binary") return "latin1";
		if (enc === "BASE64") return "base64";
		if (enc === "LATIN1" || enc === "BINARY") return "latin1";
		enc = enc.toLowerCase();
		if (enc === "base64") return "base64";
		if (enc === "latin1" || enc === "binary") return "latin1";
	} else if (length === 7) {
		if (enc === "utf16le" || enc === "UTF16LE" || enc.toLowerCase() === "utf16le") return "utf16le";
	} else if (length === 8) {
		if (enc === "utf-16le" || enc === "UTF-16LE" || enc.toLowerCase() === "utf-16le") return "utf16le";
	} else if (length === 9) {
		if (enc === "base64url" || enc === "BASE64URL" || enc.toLowerCase() === "base64url") return "base64url";
	}
	/* c8 ignore stop */
	return "utf8";
}

//#endregion
exports.normalizeEncoding = normalizeEncoding;
exports.normalizeEncodingSlow = normalizeEncodingSlow;