UNPKG

@web3r/flowerkit

Version:

Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).

1 lines 1.19 kB
{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["export type TIsStrUrlArgs = Parameters<typeof isStrUrl>;\r\n\r\nexport type TIsStrUrlReturn = ReturnType<typeof isStrUrl>;\r\n\r\n/**\r\n * Heuristically checks if a string looks like a URL or URL pathname. This is a permissive regex-based check and not a full URL validator.\r\n *\r\n * @param {string} str Source string\r\n * @returns {boolean} True if string looks like a URL/pathname\r\n * @throws {TypeError} isStrUrl: str must be a string\r\n * @example\r\n * isStrUrl(\"www.example.com\"); // true\r\n * isStrUrl(\"file.php\"); // true\r\n */\r\nexport const isStrUrl = (str: string): boolean => {\r\n if (typeof str !== \"string\") {\r\n throw new TypeError(\"isStrUrl: str must be a string\");\r\n }\r\n // eslint-disable-next-line security/detect-unsafe-regex\r\n const res = str.match(/(http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/g);\r\n return res !== null;\r\n};\r\n"],"names":["isStrUrl","str","TypeError","res","match"],"mappings":";;;;;;;;;;GAcO,MAAMA,SAAYC,MACvB,UAAWA,MAAQ,SACjB,MAAM,IAAIC,UAAU;wDAGtB;MAAMC,IAAMF,IAAIG,MAAM,mGACtB,OAAOD,MAAQ"}