{"name":"ufo","version":"1.6.0","license":"MIT","_id":"ufo@1.6.0","maintainers":[{"name":"pi0","email":"pyapar@gmail.com"}],"homepage":"https://github.com/unjs/ufo#readme","bugs":{"url":"https://github.com/unjs/ufo/issues"},"dist":{"shasum":"97c0729950279476b94b4ccdfd264a7206f7c872","tarball":"http://registry-npm.ywwl.com/ufo/download/ufo-1.6.0.tgz","fileCount":8,"integrity":"sha512-AkgU2cV/+Xb4Uz6cic0kMZbtM42nbltnGvTVOt/8gMCbO2/z64nE47TOygh7HjgFPkUkVRBEyNFqpqi3zo+BJA==","signatures":[{"sig":"MEUCIEadfPSDmb6SskM73DYhqy2g1QUvZE5z+0ZSNN3DEsChAiEA5yD/IyHPmO43hspHvMVpxmHweD42WnpCHoUWqOwvroQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":105013,"size":20434,"noattachment":false,"key":"/ufo/-/ufo-1.6.0.tgz"},"main":"./dist/index.cjs","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"},"./*":"./*"},"gitHead":"5b87427f05d0f34f484b1c9559175d65573b8e1c","scripts":{"dev":"vitest","lint":"eslint . && prettier -c src test","test":"pnpm lint && vitest run --typecheck","build":"automd && unbuild","automd":"automd","prepack":"pnpm build","release":"pnpm test && changelogen --release && npm publish && git push --follow-tags","lint:fix":"eslint --fix . && prettier -w src test"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"repository":{"url":"git+https://github.com/unjs/ufo.git","type":"git"},"_npmVersion":"10.9.2","description":"URL utils for humans","directories":{},"sideEffects":false,"_nodeVersion":"22.14.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.7.1","devDependencies":{"jiti":"^2.4.2","automd":"^0.4.0","eslint":"^9.24.0","vitest":"^3.1.1","unbuild":"^3.5.0","untyped":"^2.0.0","prettier":"^3.5.3","typescript":"^5.8.3","@types/node":"^22.14.0","changelogen":"^0.6.1","eslint-config-unjs":"^0.4.2","@vitest/coverage-v8":"^3.1.1"},"_npmOperationalInternal":{"tmp":"tmp/ufo_1.6.0_1744036315026_0.816824429828733","host":"s3://npm-registry-packages-npm-production"},"readme":"# ufo\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![Codecov][codecov-src]][codecov-href]\n\nURL utils for humans.\n\n## Install\n\nInstall using npm or your favourite package manager:\n\nInstall package:\n\n```sh\n# npm\nnpm install ufo\n\n# yarn\nyarn add ufo\n\n# pnpm\npnpm install ufo\n\n# bun\nbun install ufo\n```\n\nImport utils:\n\n```js\n// ESM\nimport { normalizeURL, joinURL } from \"ufo\";\n\n// CommonJS\nconst { normalizeURL, joinURL } = require(\"ufo\");\n\n// Deno\nimport { parseURL } from \"https://unpkg.com/ufo/dist/index.mjs\";\n```\n\n<!-- automd:jsdocs src=./src defaultGroup=utils -->\n\n## Encoding Utils\n\n### `decode(text)`\n\nDecodes text using `decodeURIComponent`. Returns the original text if it fails.\n\n### `decodePath(text)`\n\nDecodes path section of URL (consistent with encodePath for slash encoding).\n\n### `decodeQueryKey(text)`\n\nDecodes query key (consistent with `encodeQueryKey` for plus encoding).\n\n### `decodeQueryValue(text)`\n\nDecodes query value (consistent with `encodeQueryValue` for plus encoding).\n\n### `encode(text)`\n\nEncodes characters that need to be encoded in the path, search and hash sections of the URL.\n\n### `encodeHash(text)`\n\nEncodes characters that need to be encoded in the hash section of the URL.\n\n### `encodeHost(name)`\n\nEncodes hostname with punycode encoding.\n\n### `encodeParam(text)`\n\nEncodes characters that need to be encoded in the path section of the URL as a param. This function encodes everything `encodePath` does plus the slash (`/`) character.\n\n### `encodePath(text)`\n\nEncodes characters that need to be encoded in the path section of the URL.\n\n### `encodeQueryKey(text)`\n\nEncodes characters that need to be encoded for query values in the query section of the URL and also encodes the `=` character.\n\n### `encodeQueryValue(input)`\n\nEncodes characters that need to be encoded for query values in the query section of the URL.\n\n## Parsing Utils\n\n### `parseAuth(input)`\n\nTakes a string of the form `username:password` and returns an object with the username and password decoded.\n\n### `parseFilename(input, opts?: { strict? })`\n\nParses a URL and returns last segment in path as filename.\n\nIf `{ strict: true }` is passed as the second argument, it will only return the last segment only if ending with an extension.\n\n**Example:**\n\n```js\n// Result: filename.ext\nparseFilename(\"http://example.com/path/to/filename.ext\");\n\n// Result: undefined\nparseFilename(\"/path/to/.hidden-file\", { strict: true });\n```\n\n### `parseHost(input)`\n\nTakes a string, and returns an object with two properties: `hostname` and `port`.\n\n**Example:**\n\n```js\nparseHost(\"foo.com:8080\");\n// { hostname: 'foo.com', port: '8080' }\n```\n\n### `parsePath(input)`\n\nSplits the input string into three parts, and returns an object with those three parts.\n\n**Example:**\n\n```js\nparsePath(\"http://foo.com/foo?test=123#token\");\n// { pathname: 'http://foo.com/foo', search: '?test=123', hash: '#token' }\n```\n\n### `parseURL(input, defaultProto?)`\n\nTakes a URL string and returns an object with the URL's `protocol`, `auth`, `host`, `pathname`, `search`, and `hash`.\n\n**Example:**\n\n```js\nparseURL(\"http://foo.com/foo?test=123#token\");\n// { protocol: 'http:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }\n\nparseURL(\"foo.com/foo?test=123#token\");\n// { pathname: 'foo.com/foo', search: '?test=123', hash: '#token' }\n\nparseURL(\"foo.com/foo?test=123#token\", \"https://\");\n// { protocol: 'https:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }\n```\n\n### `stringifyParsedURL(parsed)`\n\nTakes a `ParsedURL` object and returns the stringified URL.\n\n**Example:**\n\n```js\nconst obj = parseURL(\"http://foo.com/foo?test=123#token\");\nobj.host = \"bar.com\";\n\nstringifyParsedURL(obj); // \"http://bar.com/foo?test=123#token\"\n```\n\n## Query Utils\n\n### `encodeQueryItem(key, value)`\n\nEncodes a pair of key and value into a url query string value.\n\nIf the value is an array, it will be encoded as multiple key-value pairs with the same key.\n\n**Example:**\n\n```js\nencodeQueryItem('message', 'Hello World')\n// 'message=Hello+World'\n\nencodeQueryItem('tags', ['javascript', 'web', 'dev'])\n// 'tags=javascript&tags=web&tags=dev'\n```\n\n### `parseQuery(parametersString)`\n\nParses and decodes a query string into an object.\n\nThe input can be a query string with or without the leading `?`.\n\n**Example:**\n\n```js\nparseQuery(\"?foo=bar&baz=qux\");\n// { foo: \"bar\", baz: \"qux\" }\n\nparseQuery(\"tags=javascript&tags=web&tags=dev\");\n// { tags: [\"javascript\", \"web\", \"dev\"] }\n```\n\n### `stringifyQuery(query)`\n\nStringfies and encodes a query object into a query string.\n\n**Example:**\n\n```js\nstringifyQuery({ foo: 'bar', baz: 'qux' })\n// 'foo=bar&baz=qux'\n\nstringifyQuery({ foo: 'bar', baz: undefined })\n// 'foo=bar'\n```\n\n## Utils\n\n### `$URL()`\n\n### `cleanDoubleSlashes(input)`\n\nRemoves double slashes from the URL.\n\n**Example:**\n\n```js\ncleanDoubleSlashes(\"//foo//bar//\"); // \"/foo/bar/\"\n\ncleanDoubleSlashes(\"http://example.com/analyze//http://localhost:3000//\");\n// Returns \"http://example.com/analyze/http://localhost:3000/\"\n```\n\n### `filterQuery(input, predicate)`\n\nRemoves the query section of the URL.\n\n**Example:**\n\n```js\nfilterQuery(\"/foo?bar=1&baz=2\", (key) => key !== \"bar\"); // \"/foo?baz=2\"\n```\n\n### `getQuery(input)`\n\nParses and decodes the query object of an input URL into an object.\n\n**Example:**\n\n```js\ngetQuery(\"http://foo.com/foo?test=123&unicode=%E5%A5%BD\");\n// { test: \"123\", unicode: \"好\" }\n```\n\n### `hasLeadingSlash(input)`\n\nChecks if the input has a leading slash (e.g. `/foo`).\n\n### `hasProtocol(inputString, opts)`\n\nChecks if the input has a protocol.\n\nYou can use `{ acceptRelative: true }` to accept relative URLs as valid protocol.\n\n**Example:**\n\n```js\nhasProtocol('https://example.com'); // true\n\nhasProtocol(\"//example.com\"); // false\n\nhasProtocol('//example.com', { acceptRelative: true });  // true\n\nhasProtocol(\"ftp://example.com\"); // true\n\nhasProtocol('data:text/plain'); // true\n\nhasProtocol('data:text/plain', { strict: true }); // false\n```\n\n### `hasTrailingSlash(input, respectQueryAndFragment?)`\n\nChecks if the input has a trailing slash.\n\n**Example:**\n\n```js\nhasTrailingSlash(\"/foo/\"); // true\n\nhasTrailingSlash(\"/foo\"); // false\n\nhasTrailingSlash(\"/foo?query=true\", true); // false\n\nhasTrailingSlash(\"/foo/?query=true\", true); // true\n```\n\n### `isEmptyURL(url)`\n\nChecks if the input URL is empty or `/`.\n\n### `isEqual(a, b, options)`\n\nChecks if two paths are equal regardless of encoding, trailing slash, and leading slash differences.\n\nYou can make slash check strict by setting `{ trailingSlash: true, leadingSlash: true }` as options.\n\nYou can make encoding check strict by setting `{ encoding: true }` as options.\n\n**Example:**\n\n```js\nisEqual(\"/foo\", \"foo\"); // true\nisEqual(\"foo/\", \"foo\"); // true\nisEqual(\"/foo bar\", \"/foo%20bar\"); // true\n\n// Strict compare\nisEqual(\"/foo\", \"foo\", { leadingSlash: true }); // false\nisEqual(\"foo/\", \"foo\", { trailingSlash: true }); // false\nisEqual(\"/foo bar\", \"/foo%20bar\", { encoding: true }); // false\n```\n\n### `isNonEmptyURL(url)`\n\nChecks if the input URL is neither empty nor `/`.\n\n### `isRelative(inputString)`\n\nCheck if a path starts with `./` or `../`.\n\n**Example:**\n\n```js\nisRelative(\"./foo\"); // true\n```\n\n### `isSamePath(p1, p2)`\n\nCheck if two paths are equal or not. Trailing slash and encoding are normalized before comparison.\n\n**Example:**\n\n```js\nisSamePath(\"/foo\", \"/foo/\"); // true\n```\n\n### `isScriptProtocol(protocol?)`\n\nChecks if the input protocol is any of the dangerous `blob:`, `data:`, `javascript`: or `vbscript:` protocols.\n\n**Example:**\n\n```js\nisScriptProtocol(\"javascript:alert(1)\"); // true\n\nisScriptProtocol(\"data:text/html,hello\"); // true\n\nisScriptProtocol(\"blob:hello\"); // true\n\nisScriptProtocol(\"vbscript:alert(1)\"); // true\n\nisScriptProtocol(\"https://example.com\"); // false\n```\n\n### `joinRelativeURL()`\n\nJoins multiple URL segments into a single URL and also handles relative paths with `./` and `../`.\n\n**Example:**\n\n```js\njoinRelativeURL(\"/a\", \"../b\", \"./c\"); // \"/b/c\"\n```\n\n### `joinURL(base)`\n\nJoins multiple URL segments into a single URL.\n\n**Example:**\n\n```js\njoinURL(\"a\", \"/b\", \"/c\"); // \"a/b/c\"\n```\n\n### `normalizeURL(input)`\n\nNormalizes the input URL:\n\n- Ensures the URL is properly encoded - Ensures pathname starts with a slash - Preserves protocol/host if provided\n\n**Example:**\n\n```js\nnormalizeURL(\"test?query=123 123#hash, test\");\n// Returns \"test?query=123%20123#hash,%20test\"\n\nnormalizeURL(\"http://localhost:3000\");\n// Returns \"http://localhost:3000\"\n```\n\n### `resolveURL(base)`\n\nResolves multiple URL segments into a single URL.\n\n**Example:**\n\n```js\nresolveURL(\"http://foo.com/foo?test=123#token\", \"bar\", \"baz\");\n// Returns \"http://foo.com/foo/bar/baz?test=123#token\"\n```\n\n### `withBase(input, base)`\n\nEnsures the URL or pathname starts with base.\n\nIf input already starts with base, it will not be added again.\n\n**Example:**\n\n```js\nwithBase(\"/foo/bar\", \"/foo\"); // \"/foo/bar\"\n\nwithBase(\"/foo/bar\", \"/baz\"); // \"/baz/foo/bar\"\n```\n\n### `withFragment(input, hash)`\n\nAdds or replaces the fragment section of the URL.\n\n**Example:**\n\n```js\nwithFragment(\"/foo\", \"bar\"); // \"/foo#bar\"\nwithFragment(\"/foo#bar\", \"baz\"); // \"/foo#baz\"\nwithFragment(\"/foo#bar\", \"\"); // \"/foo\"\n```\n\n### `withHttp(input)`\n\nAdds or replaces the URL protocol to `http://`.\n\n**Example:**\n\n```js\nwithHttp(\"https://example.com\"); // http://example.com\n```\n\n### `withHttps(input)`\n\nAdds or replaces the URL protocol to `https://`.\n\n**Example:**\n\n```js\nwithHttps(\"http://example.com\"); // https://example.com\n```\n\n### `withLeadingSlash(input)`\n\nEnsures the URL or pathname has a leading slash.\n\n**Example:**\n\n```js\nwithLeadingSlash(\"foo\"); // \"/foo\"\n```\n\n### `withoutBase(input, base)`\n\nRemoves the base from the URL or pathname.\n\nIf input does not start with base, it will not be removed.\n\n**Example:**\n\n```js\nwithoutBase(\"/foo/bar\", \"/foo\"); // \"/bar\"\n```\n\n### `withoutFragment(input)`\n\nRemoves the fragment section from the URL.\n\n**Example:**\n\n```js\nwithoutFragment(\"http://example.com/foo?q=123#bar\")\n// Returns \"http://example.com/foo?q=123\"\n```\n\n### `withoutHost(input)`\n\nRemoves the host from the URL while preserving everything else.\n\n**Example:**\n\n```js\nwithoutHost(\"http://example.com/foo?q=123#bar\")\n// Returns \"/foo?q=123#bar\"\n```\n\n### `withoutLeadingSlash(input)`\n\nRemoves leading slash from the URL or pathname.\n\n**Example:**\n\n```js\nwithoutLeadingSlash(\"/foo\"); // \"foo\"\n```\n\n### `withoutProtocol(input)`\n\nRemoves the protocol from the input.\n\n**Example:**\n\n```js\nwithoutProtocol(\"http://example.com\"); // \"example.com\"\n```\n\n### `withoutTrailingSlash(input, respectQueryAndFragment?)`\n\nRemoves the trailing slash from the URL or pathname.\n\nIf second argument is `true`, it will only remove the trailing slash if it's not part of the query or fragment with cost of more expensive operations.\n\n**Example:**\n\n```js\nwithoutTrailingSlash(\"/foo/\"); // \"/foo\"\n\nwithoutTrailingSlash(\"/path/?query=true\", true); // \"/path?query=true\"\n```\n\n### `withProtocol(input, protocol)`\n\nAdds or replaces protocol of the input URL.\n\n**Example:**\n\n```js\nwithProtocol(\"http://example.com\", \"ftp://\"); // \"ftp://example.com\"\n```\n\n### `withQuery(input, query)`\n\nAdd/Replace the query section of the URL.\n\n**Example:**\n\n```js\nwithQuery(\"/foo?page=a\", { token: \"secret\" }); // \"/foo?page=a&token=secret\"\n```\n\n### `withTrailingSlash(input, respectQueryAndFragment?)`\n\nEnsures the URL ends with a trailing slash.\n\nIf second argument is `true`, it will only add the trailing slash if it's not part of the query or fragment with cost of more expensive operation.\n\n**Example:**\n\n```js\nwithTrailingSlash(\"/foo\"); // \"/foo/\"\n\nwithTrailingSlash(\"/path?query=true\", true); // \"/path/?query=true\"\n```\n\n<!-- /automd -->\n\n## License\n\n[MIT](./LICENSE)\n\nSpecial thanks to Eduardo San Martin Morote ([posva](https://github.com/posva)) for [encoding utilities](https://github.com/vuejs/vue-router-next/blob/v4.0.1/src/encoding.ts)\n\n<!-- Badges -->\n\n[npm-version-src]: https://img.shields.io/npm/v/ufo?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-version-href]: https://npmjs.com/package/ufo\n[npm-downloads-src]: https://img.shields.io/npm/dm/ufo?style=flat&colorA=18181B&colorB=F0DB4F\n[npm-downloads-href]: https://npmjs.com/package/ufo\n[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ufo/main?style=flat&colorA=18181B&colorB=F0DB4F\n[codecov-href]: https://codecov.io/gh/unjs/ufo\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/ufo?style=flat&colorA=18181B&colorB=F0DB4F\n[bundle-href]: https://bundlephobia.com/result?p=ufo\n","publish_time":1744036315190,"_cnpm_publish_time":1744036315190,"dist-tags":{"0.5x":"0.5.5","0.6x":"0.6.12","latest":"1.6.4"}}