{"_id":"@blyou/whatwg-url","_rev":"2-2b4390acd84008005073e1c5de00b75a","name":"@blyou/whatwg-url","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@blyou/whatwg-url","version":"0.0.1","keywords":["url","urlsearchparams","whatwg"],"author":{"name":"blyou","email":"youbolincode@163.com"},"license":"MIT","_id":"@blyou/whatwg-url@0.0.1","maintainers":[{"name":"blyou","email":"youbolincode@163.com"}],"homepage":"https://github.com/blyou/whatwg-url#readme","bugs":{"url":"https://github.com/blyou/whatwg-url/issues"},"dist":{"shasum":"273a70378a87ebd2fd534e75f4235066a2eb266a","tarball":"https://registry.npmjs.org/@blyou/whatwg-url/-/whatwg-url-0.0.1.tgz","fileCount":7,"integrity":"sha512-qMgwuA/bTDpToDdTVjWfp0Sy7jJGF3GxSjwTG8mEy3bk7z9gLUKbFe4uREWAeFljQE4L44cjR6aj+xUDgtItFQ==","signatures":[{"sig":"MEQCIFZBrVdlBJAGbPYFiKUyzx2ujMlSOmy8JAuJoVMhSs7pAiBeesVFg7t7EoXqy6uSQvdp8uxtegqqJfNPuQgz5rMY/w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":30795},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.cts","module":"./dist/index.mjs","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"},"./package.json":"./package.json"},"gitHead":"01017dd8cd58974bd961423809cc18ed564abb1f","scripts":{"dev":"tsdown --watch","lint":"run-s lint:*","taze":"pnpx taze -I","test":"vitest","build":"tsdown","format":"oxfmt src/","release":"bumpp","git:hooks":"pnpm simple-git-hooks","typecheck":"tsc --noEmit","lint:eslint":"eslint . --fix --cache","lint:oxlint":"oxlint . --fix","prepublishOnly":"pnpm run build"},"_npmUser":{"name":"blyou","email":"youbolincode@163.com"},"repository":{"url":"git+https://github.com/blyou/whatwg-url.git","type":"git"},"_npmVersion":"11.13.0","description":"A tiny, zero-dependency WHATWG URL and URLSearchParams implementation for constrained environments.","directories":{},"_nodeVersion":"24.16.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@11.17.0+sha512.cca3cea332ad254bb84145f966d19f4879615210346fc92c79a047f23a0d7b3cca3c3792f0076ba1f1831d277efbcf0a9119b31a9a60eca7fb3d6231f331ef72","devDependencies":{"bumpp":"^12.0.0","oxfmt":"^0.60.0","eslint":"^10.8.0","oxlint":"^1.75.0","tsdown":"^0.22.14","vitest":"^4.1.10","typescript":"^6.0.3","@types/node":"^26.1.1","lint-staged":"^17.2.0","npm-run-all2":"^9.0.2","@commitlint/cli":"^21.2.1","simple-git-hooks":"^2.13.1","@commitlint/types":"^21.2.0","eslint-plugin-vue":"^10.10.0","eslint-plugin-oxlint":"^1.75.0","eslint-config-prettier":"^10.1.8","@typescript/native-preview":"7.0.0-dev.20260707.2","@vue/eslint-config-typescript":"^14.9.0","@commitlint/config-conventional":"^21.2.0"},"_npmOperationalInternal":{"tmp":"tmp/whatwg-url_0.0.1_1785089679172_0.8927062691922198","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"@blyou/whatwg-url","version":"0.0.2","description":"a zero-dependency, WHATWG URL & URLSearchParams implementation for DOM-less ES2023 environments.","keywords":["url","urlsearchparams","whatwg"],"homepage":"https://github.com/blyou/whatwg-url#readme","bugs":{"url":"https://github.com/blyou/whatwg-url/issues"},"license":"MIT","author":{"name":"blyou","email":"youbolincode@163.com"},"repository":{"type":"git","url":"git+https://github.com/blyou/whatwg-url.git"},"type":"module","main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.cts","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"},"./package.json":"./package.json"},"publishConfig":{"access":"public"},"scripts":{"build":"tsdown","dev":"tsdown --watch","test":"vitest","fetch:wpt":"node scripts/fetch-wpt-resources.mjs","test:wpt":"pnpm build && vitest run tests/wpt-tests","typecheck":"tsc --noEmit","release":"bumpp","prepublishOnly":"pnpm run build","lint":"run-s lint:*","lint:oxlint":"oxlint . --fix","lint:eslint":"eslint . --fix --cache","format":"oxfmt src/","git:hooks":"pnpm simple-git-hooks","taze":"pnpx taze -I"},"devDependencies":{"@commitlint/cli":"^21.2.1","@commitlint/config-conventional":"^21.2.0","@commitlint/types":"^21.2.0","@types/node":"^26.1.2","@typescript/native-preview":"7.0.0-dev.20260707.2","@vue/eslint-config-typescript":"^14.9.0","bumpp":"^12.1.1","eslint":"^10.8.0","eslint-config-prettier":"^10.1.8","eslint-plugin-oxlint":"^1.76.0","eslint-plugin-vue":"^10.10.0","lint-staged":"^17.2.0","npm-run-all2":"^9.0.3","oxfmt":"^0.61.0","oxlint":"^1.76.0","simple-git-hooks":"^2.13.1","terser":"^5.49.0","tsdown":"^0.22.14","typescript":"^6.0.3","vitest":"^4.1.10"},"packageManager":"pnpm@11.18.0+sha512.33d83c77da82f49fba836925c6f1b841181ec3132b670639bd012f7075f5c7cf634c5f870147c19aae7478fac01df09d8892e880454896edd23ee9b33757563c","gitHead":"2cbfa4fd85247a7a0ee09a6b048ea9c5d120a17b","_id":"@blyou/whatwg-url@0.0.2","_nodeVersion":"24.16.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-DqHjvg+GDv0+eixVJ/l4PrbWwHZkDWn1c8p8nOVv8Z0B+q2zyeNYm/V/Rp/OA0NF8MebjIL8xgIqiCIpkloAhQ==","shasum":"5bbf974980d8d3d99eb592d732e0da567f451bd8","tarball":"https://registry.npmjs.org/@blyou/whatwg-url/-/whatwg-url-0.0.2.tgz","fileCount":7,"unpackedSize":47394,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC7rTPKArRLWlkDVUZq+0UPBSeSGrvio2DHDt+9baW1MAIgBJZ44JMC9VqywvA8EZB47oCQEtYrs1Jo05Fa0gyEtBw="}]},"_npmUser":{"name":"blyou","email":"youbolincode@163.com"},"directories":{},"maintainers":[{"name":"blyou","email":"youbolincode@163.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/whatwg-url_0.0.2_1785769290454_0.20082309229602258"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-26T18:14:39.060Z","modified":"2026-08-03T15:01:30.796Z","0.0.1":"2026-07-26T18:14:39.297Z","0.0.2":"2026-08-03T15:01:30.630Z"},"bugs":{"url":"https://github.com/blyou/whatwg-url/issues"},"author":{"name":"blyou","email":"youbolincode@163.com"},"license":"MIT","homepage":"https://github.com/blyou/whatwg-url#readme","keywords":["url","urlsearchparams","whatwg"],"repository":{"type":"git","url":"git+https://github.com/blyou/whatwg-url.git"},"description":"a zero-dependency, WHATWG URL & URLSearchParams implementation for DOM-less ES2023 environments.","maintainers":[{"name":"blyou","email":"youbolincode@163.com"}],"readme":"# whatwg-url\n\n零依赖、无 DOM、ES2023 的 [WHATWG URL 标准](https://url.spec.whatwg.org/) 实现 —— 和浏览器里一样的 `URL` 和 `URLSearchParams` API，可在任意 JavaScript 运行时中使用。\n\n它使用纯 JS UTF-8 编解码，不依赖 `TextEncoder`/`TextDecoder`，因此可以运行在缺少这些全局对象的环境中 —— **小程序、嵌入式运行时、沙箱环境、以及普通 Node.js** —— 无需任何 polyfill。\n\n## 特性\n\n- **符合规范的解析器**：完整实现 Basic URL 解析器状态机（scheme、authority、host、port、path、query、fragment，以及所有特殊 scheme 分支）。\n- **`URL` 和 `URLSearchParams`** 类，与 Web IDL 接口一致，包括：\n  - 全部属性访问器：`href`、`protocol`、`username`、`password`、`host`、`hostname`、`port`、`pathname`、`search`、`searchParams`、`hash`、`origin`\n  - `toString()` / `toJSON()`\n  - `URL.parse(url, base?)` 和 `URL.canParse(url, base?)`（失败时返回 `null` / `false`，不抛异常）\n  - 完整的 `URLSearchParams` API：`append`、`delete`、`get`、`getAll`、`has`、`set`、`sort`、`keys`、`values`、`entries`、`forEach`、`size`，以及迭代器\n- **Host 解析**：支持域名（含 IDNA/punycode）、IPv4、IPv6（含 `::` 压缩）、以及 opaque host。\n- **正确的 origin 序列化**（opaque origin 返回 `'null'`）。\n- **表单编码**（`application/x-www-form-urlencoded`），用于查询字符串和 `URLSearchParams`。\n\n## 安装\n\n```sh\npnpm i @blyou/whatwg-url\n```\n\n## 使用\n\n```ts\nimport { URL, URLSearchParams } from '@blyou/whatwg-url'\n\nconst u = new URL('https://user:pass@example.com:8080/a/b?q=1#frag')\nu.href // \"https://user:pass@example.com:8080/a/b?q=1#frag\"\nu.hostname // \"example.com\"\nu.port // \"8080\"\nu.pathname // \"/a/b\"\nu.origin // \"https://example.com:8080\"\n\n// 相对路径解析\nnew URL('../c', 'https://example.com/a/b/').href\n// \"https://example.com/a/c\"\n\n// searchParams 与 URL 双向绑定\nconst sp = new URLSearchParams('a=b c')\nsp.toString() // \"a=b+c\"\n\n// 符合规范的错误处理\nURL.parse('http://') // null\nURL.canParse('http://') // false\nURL.parse('../x', 'http://example.com/') // URL 实例\n```\n\n## API\n\n### `class URL`\n\n| 成员                       | 说明                                                           |\n| -------------------------- | -------------------------------------------------------------- |\n| `new URL(url, base?)`      | 解析 `url`（可选相对于 `base` 解析）。失败时抛出 `TypeError`。 |\n| `href`                     | 序列化后的 URL（getter/setter）。                              |\n| `protocol`                 | scheme + `:`（getter/setter）。                                |\n| `username` / `password`    | 用户信息部分（getter/setter）。                                |\n| `host` / `hostname`        | 带/不带端口的主机名（getter/setter）。                         |\n| `port`                     | 端口字符串，默认端口或空端口时为 `''`（getter/setter）。       |\n| `pathname`                 | 路径（getter/setter；对 opaque path 无操作）。                 |\n| `search`                   | 以 `?` 开头的查询字符串，或 `''`（getter/setter）。            |\n| `searchParams`             | 与 URL 双向绑定的 `URLSearchParams`。                          |\n| `hash`                     | 以 `#` 开头的 fragment，或 `''`（getter/setter）。             |\n| `origin`                   | 序列化后的 origin；opaque origin 返回 `'null'`。               |\n| `toString()` / `toJSON()`  | 序列化为字符串。                                               |\n| `URL.parse(url, base?)`    | 类似 `new URL`，但失败时返回 `null` 而不是抛异常。             |\n| `URL.canParse(url, base?)` | 输入可成功解析时返回 `true`。                                  |\n\n### `class URLSearchParams`\n\n| 成员                                | 说明                                             |\n| ----------------------------------- | ------------------------------------------------ |\n| `new URLSearchParams(init?)`        | 从查询字符串、对象、数组对、或迭代器初始化。     |\n| `append(name, value)`               | 追加一个键值对。                                 |\n| `delete(name, value?)`              | 按 name（或 name+value）删除。                   |\n| `get(name)` / `getAll(name)`        | 获取第一个值 / 所有值。                          |\n| `has(name, value?)`                 | 检查是否存在。                                   |\n| `set(name, value)`                  | 替换 `name` 对应的所有值。                       |\n| `sort()`                            | 按 name 排序（稳定排序）。                       |\n| `keys()` / `values()` / `entries()` | 迭代器。                                         |\n| `forEach(cb, thisArg?)`             | 遍历键值对。                                     |\n| `size`                              | 键值对数量。                                     |\n| `toString()`                        | 序列化：空格转为 `+`，不安全字符进行百分号编码。 |\n\n## 构建\n\n```sh\npnpm build      # tsdown -> dist/index.mjs (ESM) + dist/index.cjs (CJS) + 类型声明\n```\n\n`package.json` 同时暴露 ESM 和 CJS 入口及其类型声明。\n\n## 测试\n\n### 单元测试\n\n```sh\npnpm test\n```\n\n### Web Platform Tests (WPT)\n\n本项目集成了官方 [web-platform-tests](https://github.com/web-platform-tests/wpt) URL 测试套件，用于验证规范符合性。\n\nWPT 测试数据**不**提交到本仓库。通过一个轻量脚本按需从 WPT 仓库下载所需的 4 个 JSON 数据文件：\n\n```sh\n# 下载 WPT URL 测试数据（urltestdata、setters、percent-encoding、toascii）\npnpm fetch:wpt\n\n# 针对构建产物运行 WPT 测试（先构建，再测试）\npnpm test:wpt\n```\n\n下载的文件保存在 `tests/wpt-resources/`（已加入 `.gitignore`）。如需升级测试数据，修改 `scripts/fetch-wpt-resources.mjs` 中的 `WPT_REF` 常量并重新运行 `pnpm fetch:wpt`。\n\n## 许可证\n\n[MIT](./LICENSE)\n","readmeFilename":"README.md"}