Skip to main content

URL Fix

Decode Persian URLs that have been percent-encoded, making them readable.

Basic Usage

import { URLfix } from "@persian-tools/persian-tools";

const encoded = "https://example.com/search?q=%D8%AA%D8%B3%D8%AA";
console.log(URLfix(encoded));
// Output: "https://example.com/search?q=تست"

API Reference

url
string
required
Percent-encoded URL containing Persian characters
result
string
Decoded URL with readable Persian characters

Examples

Display Readable URLs

import { URLfix } from "@persian-tools/persian-tools";

const shareUrl = "%D8%B3%D9%84%D8%A7%D9%85";
console.log(URLfix(shareUrl));
// "سلام"
import { URLfix } from "@persian-tools/persian-tools";

const processLinks = (html: string): string => {
	const urlPattern = /href="([^"]*)"/g;
	return html.replace(urlPattern, (match, url) => {
		return `href="${URLfix(url)}"`;
	});
};

Type Definition

function URLfix(url: string): string;