Parses complex links like this
https://google.com/notify/messages/1295812905/click?signature=10295801298586296300235&url=https%3A%2F%2Fgoogle.com%2Fusers%2Flink%2FZW1hbnVlbC5-9AF80a98fg8vbQ%3D%3DMTY3NDQzMjg2NA%3D%3D6a8f74a552%3Fredirect_to%3Dhttps%253A%252F%252Fgoogle.com%252Fteam%252F832678%252Fincidents%252F331734795%26utm_source%3Descalation_mailer%26utm_medium%3Demail%26utm_campaign%3Dresolved
Into:
{"1: URL Original": "https://google.com/notify/messages/1295812905/click?signature=10295801298586296300235&url=https%3A%2F%2Fgoogle.com%2Fusers%2Flink%2FZW1hbnVlbC5-9AF80a98fg8vbQ%3D%3DMTY3NDQzMjg2NA%3D%3D6a8f74a552%3Fredirect_to%3Dhttps%253A%252F%252Fgoogle.com%252Fteam%252F832678%252Fincidents%252F331734795%26utm_source%3Descalation_mailer%26utm_medium%3Demail%26utm_campaign%3Dresolved","2: URL Decoded": "https://google.com/notify/messages/1295812905/click?signature=10295801298586296300235&url=https://google.com/users/link/ZW1hbnVlbC5-9AF80a98fg8vbQ==MTY3NDQzMjg2NA==6a8f74a552?redirect_to=https%3A%2F%2Fgoogle.com%2Fteam%2F832678%2Fincidents%2F331734795&utm_source=escalation_mailer&utm_medium=email&utm_campaign=resolved","3: URL Params": {"signature": "10295801298586296300235","url": "https%3A%2F%2Fgoogle.com%2Fusers%2Flink%2FZW1hbnVlbC5-9AF80a98fg8vbQ%3D%3DMTY3NDQzMjg2NA%3D%3D6a8f74a552%3Fredirect_to%3Dhttps%253A%252F%252Fgoogle.com%252Fteam%252F832678%252Fincidents%252F331734795%26utm_source%3Descalation_mailer%26utm_medium%3Demail%26utm_campaign%3Dresolved"},"4: Children": {"url": {"1: URL Original": "https%3A%2F%2Fgoogle.com%2Fusers%2Flink%2FZW1hbnVlbC5-9AF80a98fg8vbQ%3D%3DMTY3NDQzMjg2NA%3D%3D6a8f74a552%3Fredirect_to%3Dhttps%253A%252F%252Fgoogle.com%252Fteam%252F832678%252Fincidents%252F331734795%26utm_source%3Descalation_mailer%26utm_medium%3Demail%26utm_campaign%3Dresolved","2: URL Decoded": "https://google.com/users/link/ZW1hbnVlbC5-9AF80a98fg8vbQ==MTY3NDQzMjg2NA==6a8f74a552?redirect_to=https%3A%2F%2Fgoogle.com%2Fteam%2F832678%2Fincidents%2F331734795&utm_source=escalation_mailer&utm_medium=email&utm_campaign=resolved","3: URL Params": {"redirect_to": "https%3A%2F%2Fgoogle.com%2Fteam%2F832678%2Fincidents%2F331734795","utm_source": "escalation_mailer","utm_medium": "email","utm_campaign": "resolved"},"4: Children": {"redirect_to": {"1: URL Original": "https%3A%2F%2Fgoogle.com%2Fteam%2F832678%2Fincidents%2F331734795","2: URL Decoded": "https://google.com/team/832678/incidents/331734795","3: URL Params": {},"4: Children": {}}}}}}
// Name: Deep URL decode// Description: Sometimes you want to know what inside a URL, use this to show as a deep json...import "@johnlindquist/kit";const decode = (str: string) => decodeURIComponent((str + '').replace(/\+/g, '%20'))function getParamsFromUrl(url: string): Record<string, string> | void {if (url.startsWith("https%")) return getParamsFromUrl(decode(url))try {if (typeof url === 'string') {let params = url.split('?');let eachParamsArr = params[1].split('&');let obj: Record<string, string> = {};if (eachParamsArr && eachParamsArr.length) {eachParamsArr.map(param => {let keyValuePair = param.split('=')let key = keyValuePair[0];let value = keyValuePair[1];obj[key] = value;})}return obj;}} catch (err) {// return getParamsFromUrl(decode(url))return {}}}interface DecodeType {['1: URL Original']: string['2: URL Decoded']: string['3: URL Params']: void | Record<string, string>['4: Children']: Record<string, DecodeType>}function decodeDeep(urlString: string): DecodeType {const decodedUrl = decode(urlString)const paramsFromUrl = getParamsFromUrl(urlString)return {['1: URL Original']: urlString,['2: URL Decoded']: decodedUrl,['3: URL Params']: paramsFromUrl,['4: Children']: (() => {if (!paramsFromUrl) return {}const entries = Object.entries(paramsFromUrl)return entries.reduce((current, [paramKey, paramValue]) => {const itemIsUrl = paramValue.startsWith("http")if (!itemIsUrl) return currentconst decoded = decodeDeep(paramValue)if (!decoded) return current// return currentreturn { ...current, [paramKey]: decoded }}, {})})()}}let url = await arg("enter URL")inspect(decodeDeep(url))