mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-29 16:16:02 +00:00
19 lines
414 B
TypeScript
19 lines
414 B
TypeScript
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;
|
|
}
|