{"_id":"@3-/unescape","name":"@3-/unescape","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.2":{"name":"@3-/unescape","version":"0.1.2","keywords":["unescape","html","entity","decoder","fast"],"description":"Fast HTML entity unescape utility / 高效 HTML 实体字符反转义工具","repository":{"type":"git","url":"git+https://github.com/i18n-site/lib.git"},"homepage":"https://github.com/i18n-site/lib/tree/dev/unescape","author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","exports":{".":"./lib.js","./*":"./*"},"devDependencies":{},"scripts":{},"type":"module","dependencies":{"@3-/int":"^0.1.1"},"gitHead":"99d9c1153530c985992637137c5919d3b020dd61","_id":"@3-/unescape@0.1.2","bugs":{"url":"https://github.com/i18n-site/lib/issues"},"_nodeVersion":"26.2.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-eGcomUs0hb0VmhXDv3Vw8fTOTSFz2ZLRp+4CAXKCrPCdGFtI/mIUkQ47yuNSkNMX40lGlwB/bOMdWq6xvnWBNg==","shasum":"aa9da88735cabcc664a72b336453ae030189a65b","tarball":"https://registry.npmjs.org/@3-/unescape/-/unescape-0.1.2.tgz","fileCount":3,"unpackedSize":8523,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBJGVG8PxgDY6Jrqr2E90oKHWBqtunijE/An4B6UM+/VAiAmmL/+3gKCFpb4S0WylTJeNhoRuzvYpzuqGGu/CeSwxA=="}]},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"directories":{},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/unescape_0.1.2_1780437460762_0.24364265186006695"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-02T21:57:40.663Z","0.1.2":"2026-06-02T21:57:40.886Z","modified":"2026-06-02T21:57:41.061Z"},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"description":"Fast HTML entity unescape utility / 高效 HTML 实体字符反转义工具","homepage":"https://github.com/i18n-site/lib/tree/dev/unescape","keywords":["unescape","html","entity","decoder","fast"],"repository":{"type":"git","url":"git+https://github.com/i18n-site/lib.git"},"author":{"name":"i18n.site@gmail.com"},"bugs":{"url":"https://github.com/i18n-site/lib/issues"},"license":"MulanPSL-2.0","readme":"[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n# @3-/unescape : Fast and Lightweight HTML Entity Unescape Utility\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Features](#features)\n- [Usage](#usage)\n- [Calling Flow](#calling-flow)\n- [Tech Stack](#tech-stack)\n- [Directory Structure](#directory-structure)\n- [History](#history)\n\n## Introduction\n\nProvides unescaping functionality for HTML entities. Converts named, decimal, and hexadecimal character entity references back to standard characters.\n\n## Features\n\n- Named entities lookup support (`&amp;`, `&lt;`, `&gt;`, `&quot;`, `&apos;`).\n- Decimal character references support (`&#65;`).\n- Hexadecimal character references support (`&#x41;`).\n- Safe execution avoiding unnecessary processing when no ampersand exists.\n\n## Usage\n\nDemonstrated in [tests/lib.test.js](file:///Users/z/i18n/lib/unescape/tests/lib.test.js):\n\n```javascript\nimport unescape from \"../src/lib.js\";\n\n// Named entities\nunescape(\"&amp; &lt; &gt; &quot; &apos;\"); // Returns: & < > \" '\n\n// Numeric entities (decimal and hexadecimal)\nunescape(\"&#65; &#x41; &#X41;\"); // Returns: A A A\n\n// Strings without entities\nunescape(\"normal text\"); // Returns: normal text\n```\n\n## Calling Flow\n\nModule calling flow for unescaping processes:\n\n```mermaid\ngraph TD\n  Input([Input String]) --> CheckAmp{Contains '&'?}\n  CheckAmp -- No --> ReturnOrig[Return Original String]\n  CheckAmp -- Yes --> MatchRegex[Execute RegExp Replacement]\n  MatchRegex --> MatchType{Match Group Type}\n  MatchType -- Named Entity --> NamedLookup[Look up in MAP]\n  MatchType -- Decimal Code --> DecParse[Parse Integer via @3-/int]\n  MatchType -- Hex Code --> HexParse[Parse Hex via Number.parseInt]\n  NamedLookup --> Replace[String.fromCodePoint / Mapped Value]\n  DecParse --> Replace\n  HexParse --> Replace\n  Replace --> Output([Return Replaced String])\n```\n\n## Tech Stack\n\n- **Runtime**: [Bun](https://bun.sh)\n- **Language**: JavaScript (ES modules)\n- **External Dependency**: [@3-/int](https://www.npmjs.com/package/@3-/int) (For integer parsing optimization)\n\n## Directory Structure\n\nDetailed directory structure layout:\n\n- [src/lib.js](file:///Users/z/i18n/lib/unescape/src/lib.js) - Core unescaping implementation.\n- [tests/lib.test.js](file:///Users/z/i18n/lib/unescape/tests/lib.test.js) - Test suite and usage demonstration.\n- [package.json](file:///Users/z/i18n/lib/unescape/package.json) - Project manifest.\n\n## History\n\nHTML character entities originated from SGML (Standard Generalized Markup Language) in the 1980s (ISO 8879:1986). In SGML, these were defined as \"character entity references\". Tim Berners-Lee adopted SGML syntax when designing HTML in 1991 to bypass character display limitations of early computer terminals and encode reserved symbols like `<` and `>`. Over time, the HTML5 specification expanded the list of named character entities to over 2000. In modern applications, Unicode has minimized the necessity for named entities, yet core XML/HTML entities remain essential for processing web markup and preventing syntax injection.\n\n---\n\n<a id=\"zh\"></a>\n# @3-/unescape : 轻量高效的 HTML 实体字符反转义工具\n\n## 目录导航\n\n- [功能介绍](#功能介绍)\n- [功能特性](#功能特性)\n- [使用演示](#使用演示)\n- [设计思路与调用流程](#设计思路与调用流程)\n- [技术堆栈](#技术堆栈)\n- [目录结构](#目录结构)\n- [历史背景](#历史背景)\n\n## 功能介绍\n\n提供 HTML 实体字符反转义功能，将命名实体、十进制和十六进制字符实体引用恢复为原始字符。\n\n## 功能特性\n\n- 支持命名实体解析（`&amp;`、`&lt;`、`&gt;`、`&quot;`、`&apos;`）。\n- 支持十进制数字实体解析（`&#65;`）。\n- 支持十六进制数字实体解析（`&#x41;`）。\n- 具备快速判断机制，字符串不含 `&` 时直接返回，避免无用正则匹配。\n\n## 使用演示\n\n演示代码参见 [tests/lib.test.js](file:///Users/z/i18n/lib/unescape/tests/lib.test.js)：\n\n```javascript\nimport unescape from \"../src/lib.js\";\n\n// 命名实体解析\nunescape(\"&amp; &lt; &gt; &quot; &apos;\"); // 返回: & < > \" '\n\n// 数字实体解析 (十进制与十六进制)\nunescape(\"&#65; &#x41; &#X41;\"); // 返回: A A A\n\n// 无实体字符\nunescape(\"normal text\"); // 返回: normal text\n```\n\n## 设计思路与调用流程\n\n输入字符串经由以下流程进行反转义处理：\n\n```mermaid\ngraph TD\n  Input([输入字符串]) --> CheckAmp{包含 '&' 字符?}\n  CheckAmp -- 否 --> ReturnOrig[直接返回原字符串]\n  CheckAmp -- 是 --> MatchRegex[执行正则表达式替换]\n  MatchRegex --> MatchType{匹配类型判断}\n  MatchType -- 命名实体 --> NamedLookup[检索 MAP 映射表]\n  MatchType -- 十进制编码 --> DecParse[通过 @3-/int 解析整数]\n  MatchType -- 十六进制编码 --> HexParse[使用 Number.parseInt 解析]\n  NamedLookup --> Replace[String.fromCodePoint 或映射字符]\n  DecParse --> Replace\n  HexParse --> Replace\n  Replace --> Output([返回替换后字符串])\n```\n\n## 技术堆栈\n\n- **运行时**: [Bun](https://bun.sh)\n- **开发语言**: JavaScript (ES modules)\n- **外部依赖**: [@3-/int](https://www.npmjs.com/package/@3-/int) (用于十进制整数解析优化)\n\n## 目录结构\n\n项目目录及文件分布：\n\n- [src/lib.js](file:///Users/z/i18n/lib/unescape/src/lib.js) - 核心反转义逻辑实现。\n- [tests/lib.test.js](file:///Users/z/i18n/lib/unescape/tests/lib.test.js) - 测试用例及调用演示。\n- [package.json](file:///Users/z/i18n/lib/unescape/package.json) - 项目配置文件。\n\n## 历史背景\n\nHTML 实体字符（Entity References）可追溯至 20 世纪 80 年代制定的 SGML（标准通用标记语言，ISO 8879:1986）。当时称为“字符实体引用”。1991 年，Tim Berners-Lee 创立 HTML 时，沿用了 SGML 的实体引用设计，以解决早期终端设备无法显示特定非 ASCII 字符以及避免 `<` 和 `>` 产生标签解析歧义的问题。随着 HTML4 及 HTML5 标准发布，命名实体库扩充至 2000 余种。在 Unicode 普及的今天，虽然命名实体的日常使用频次有所降低，但在网页标记处理与防注入安全防护中，基本的 HTML 实体转义与反转义依然是核心基础。\n\n---\n\n## About\n\nThis project is an open-source component of [i18n.site ⋅ Internationalization Solution](https://i18n.site).\n\n* [i18 : MarkDown Command Line Translation Tool](https://i18n.site/i18)\n\n  The translation perfectly maintains the Markdown format.\n\n  It recognizes file changes and only translates the modified files.\n\n  The translated Markdown content is editable; if you modify the original text and translate it again, manually edited translations will not be overwritten (as long as the original text has not been changed).\n\n* [i18n.site : MarkDown Multi-language Static Site Generator](https://i18n.site/i18n.site)\n\n  Optimized for a better reading experience\n\n## 关于\n\n本项目为 [i18n.site ⋅ 国际化解决方案](https://i18n.site) 的开源组件。\n\n* [i18 :  MarkDown命令行翻译工具](https://i18n.site/i18)\n\n  翻译能够完美保持 Markdown 的格式。能识别文件的修改，仅翻译有变动的文件。\n\n  Markdown 翻译内容可编辑；如果你修改原文并再次机器翻译，手动修改过的翻译不会被覆盖（如果这段原文没有被修改）。\n\n* [i18n.site : MarkDown多语言静态站点生成器](https://i18n.site/i18n.site) 为阅读体验而优化。\n","readmeFilename":"README.md","_rev":"1-687c2c0747a2d55abadcc6888a993b0e"}