feat (string): url encode

This commit is contained in:
Chesterkxng
2025-07-18 17:23:52 +02:00
parent ad2c70841f
commit c106489a26
4 changed files with 135 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import { InitialValuesType } from './types';
export function encodeString(
input: string,
options: InitialValuesType
): string {
if (!input) return '';
if (!options.nonSpecialChar) {
return encodeURIComponent(input);
}
let result = '';
for (const char of input) {
const hex = char.codePointAt(0)!.toString(16).toUpperCase();
result += '%' + hex.padStart(2, '0');
}
return result;
}