mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-29 16:16:02 +00:00
feat (string): url encode
This commit is contained in:
18
src/pages/tools/string/url-encode/service.ts
Normal file
18
src/pages/tools/string/url-encode/service.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user