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.54 kB
{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["export type TGetStrUnescapedArgs = Parameters<typeof getStrUnescaped>;\r\n\r\nexport type TGetStrUnescapedReturn = ReturnType<typeof getStrUnescaped>;\r\n\r\n/**\r\n * Unescapes HTML entities back to their characters.\r\n * Unescaped: `&amp; &lt; &gt; &quot; &#39;`\r\n * @param {string} str Source string\r\n * @returns {string} Unescaped string\r\n * @throws {TypeError} If str is not a string\r\n * @example\r\n * getStrUnescaped(\"&lt;b&gt;Hello &amp; world&lt;/b&gt;\");\r\n * // => \"<b>Hello & world</b>\"\r\n */\r\nexport const getStrUnescaped = (str: string): string => {\r\n if (typeof str !== \"string\") {\r\n throw new TypeError(\"getStrUnescaped: str must be a string\");\r\n }\r\n\r\n const symbols: Record<string, string> = {\r\n \"&amp;\": \"&\",\r\n \"&lt;\": \"<\",\r\n \"&gt;\": \">\",\r\n \"&quot;\": \"\\\"\",\r\n \"&#39;\": \"'\",\r\n };\r\n\r\n const regExp = /&(?:amp|lt|gt|quot|#39);/g;\r\n\r\n const getUnescaped = (entity: \"&amp;\" | \"&lt;\" | \"&gt;\" | \"&quot;\" | \"&#39;\"): string => symbols[entity];\r\n\r\n return str.replace(regExp, getUnescaped as (m: string) => string);\r\n};\r\n"],"names":["getStrUnescaped","str","TypeError","symbols","regExp","getUnescaped","entity","replace"],"mappings":";;;;;;;;;;GAcO,MAAMA,gBAAmBC,MAC9B,UAAWA,MAAQ,SACjB,MAAM,IAAIC,UAAU,yCAGtB,MAAMC,QAAkC,CACtC,QAAS,IACT,OAAQ,IACR,OAAQ,IACR,SAAU,IACV,QAAS,KAGX,MAAMC,OAAS,4BAEf,MAAMC,aAAgBC,QAAmEH,QAAQG,QAEjG,OAAOL,IAAIM,QAAQH,OAAQC"}