Socket
Socket
Sign inDemoInstall

ufo

Package Overview
Dependencies
Maintainers
3
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ufo - npm Package Compare versions

Comparing version 0.8.1 to 0.8.2

6

dist/index.d.ts

@@ -140,2 +140,6 @@ /**

declare function joinURL(base: string, ...input: string[]): string;
declare function withHttp(input: string): string;
declare function withHttps(input: string): string;
declare function withoutProtocol(input: string): string;
declare function withProtocol(input: string, protocol: string): string;
declare function createURL(input: string): $URL;

@@ -146,2 +150,2 @@ declare function normalizeURL(input: string): string;

export { $URL, ParsedAuth, ParsedHost, ParsedURL, QueryObject, QueryValue, cleanDoubleSlashes, createURL, decode, decodePath, decodeQueryValue, encode, encodeHash, encodeHost, encodeParam, encodePath, encodeQueryItem, encodeQueryKey, encodeQueryValue, getQuery, hasLeadingSlash, hasProtocol, hasTrailingSlash, isEmptyURL, isNonEmptyURL, isRelative, isSamePath, joinURL, normalizeURL, parseAuth, parseHost, parsePath, parseQuery, parseURL, resolveURL, stringifyParsedURL, stringifyQuery, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash };
export { $URL, ParsedAuth, ParsedHost, ParsedURL, QueryObject, QueryValue, cleanDoubleSlashes, createURL, decode, decodePath, decodeQueryValue, encode, encodeHash, encodeHost, encodeParam, encodePath, encodeQueryItem, encodeQueryKey, encodeQueryValue, getQuery, hasLeadingSlash, hasProtocol, hasTrailingSlash, isEmptyURL, isNonEmptyURL, isRelative, isSamePath, joinURL, normalizeURL, parseAuth, parseHost, parsePath, parseQuery, parseURL, resolveURL, stringifyParsedURL, stringifyQuery, withBase, withHttp, withHttps, withLeadingSlash, withProtocol, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutProtocol, withoutTrailingSlash };

4

package.json
{
"name": "ufo",
"version": "0.8.1",
"version": "0.8.2",
"description": "URL utils for humans",

@@ -41,3 +41,3 @@ "repository": "unjs/ufo",

},
"readme": "[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![Github Actions][github-actions-src]][github-actions-href]\n[![Codecov][codecov-src]][codecov-href]\n[![bundle][bundle-src]][bundle-href]\n\n![👽 ufo](.github/banner.svg)\n\n## Install\n\nInstall using npm or yarn:\n\n```bash\nnpm i ufo\n# or\nyarn add ufo\n```\n\nImport:\n\n```js\n// CommonJS\nconst { normalizeURL, joinURL } = require('ufo')\n\n// ESM\nimport { normalizeURL, joinURL } from 'ufo'\n\n// Deno\nimport { parseURL } from 'https://unpkg.com/ufo/dist/index.mjs'\n```\n\n**Notice:** You may need to transpile package and add URL polyfill for legacy environments\n\n## Usage\n\n### `normalizeURL`\n\n- Ensures URL is properly encoded\n- Ensures pathname starts with slash\n- Preserves protocol/host if provided\n\n```ts\n\n// Result: test?query=123%20123#hash,%20test\nnormalizeURL('test?query=123 123#hash, test')\n\n// Result: http://localhost:3000/\nnormalizeURL('http://localhost:3000')\n```\n\n### `joinURL`\n\n```ts\n// Result: a/b/c\njoinURL('a', '/b', '/c')\n```\n\n### `resolveURL`\n\n```ts\n// Result: http://foo.com/foo/bar/baz?test=123#token\nresolveURL('http://foo.com/foo?test=123#token', 'bar', 'baz')\n```\n\n### `parseURL`\n\n```ts\n// Result: { protocol: 'http:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }\nparseURL('http://foo.com/foo?test=123#token')\n\n// Result: { pathname: 'foo.com/foo', search: '?test=123', hash: '#token' }\nparseURL('foo.com/foo?test=123#token')\n\n// Result: { protocol: 'https:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }\nparseURL('foo.com/foo?test=123#token', 'https://')\n```\n\n### `withQuery`\n\n```ts\n// Result: /foo?page=a&token=secret\nwithQuery('/foo?page=a', { token: 'secret' })\n```\n\n### `getQuery`\n\n```ts\n// Result: { test: '123', unicode: '好' }\ngetQuery('http://foo.com/foo?test=123&unicode=%E5%A5%BD')\n```\n\n### `$URL`\n\nImplementing URL interface with some improvements:\n\n- Supporting schemeless and hostless URLs\n- Supporting relative URLs\n- Preserving trailing-slash status\n- Decoded and mutable classs properties (`protocol`, `host`, `auth`, `pathname`, `query`, `hash`)\n- Consistent URL parser independent of environment\n- Consistent encoding independent of environment\n- Punycode support for host encoding\n\n### `withTrailingSlash`\n\nEnsures url ends with a trailing slash\n\n```ts\n// Result: /foo/\nwithTrailingSlash('/foo')\n```\n\n```ts\n// Result: /path/?query=true\nwithTrailingSlash('/path?query=true', true)\n```\n\n### `withoutTrailingSlash`\n\nEnsures url does not ends with a trailing slash\n\n```ts\n// Result: /foo\nwithoutTrailingSlash('/foo/')\n```\n\n```ts\n// Result: /path?query=true\nwithoutTrailingSlash('/path/?query=true', true)\n```\n\n### `cleanDoubleSlashes`\n\nEnsures url does not have double slash (except for protocol)\n\n```ts\n// Result: /foo/bar/\ncleanDoubleSlashes('//foo//bar//')\n// Result: http://example.com/analyze/http://localhost:3000/\ncleanDoubleSlashes('http://example.com/analyze//http://localhost:3000//')\n```\n\n### `isSamePath`\n\nCheck two paths are equal or not. Trailing slash and encoding are normalized before comparation.\n\n```ts\n// Result: true\nisSamePath('/foo', '/foo/')\n```\n\n### `isRelative`\n\nCheck if a path starts with `./` or `../`.\n\n```ts\n// Result: true\nisRelative('./foo')\n```\n\n## License\n\n[MIT](./LICENSE)\n\nSpecial thanks to Eduardo San Martin Morote ([posva](https://github.com/posva)) for [encoding utlities](https://github.com/vuejs/vue-router-next/blob/v4.0.1/src/encoding.ts)\n\n<!-- Badges -->\n[npm-version-src]: https://img.shields.io/npm/v/ufo?style=flat-square\n[npm-version-href]: https://npmjs.com/package/ufo\n\n[npm-downloads-src]: https://img.shields.io/npm/dm/ufo?style=flat-square\n[npm-downloads-href]: https://npmjs.com/package/ufo\n\n[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/ufo/ci/main?style=flat-square\n[github-actions-href]: https://github.com/unjs/ufo/actions?query=workflow%3Aci\n\n[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ufo/main?style=flat-square\n[codecov-href]: https://codecov.io/gh/unjs/ufo\n\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/ufo?style=flat-square\n[bundle-href]: https://bundlephobia.com/result?p=ufo\n"
"readme": "[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![Github Actions][github-actions-src]][github-actions-href]\n[![Codecov][codecov-src]][codecov-href]\n[![bundle][bundle-src]][bundle-href]\n\n![👽 ufo](.github/banner.svg)\n\n## Install\n\nInstall using npm or yarn:\n\n```bash\nnpm i ufo\n# or\nyarn add ufo\n```\n\nImport:\n\n```js\n// CommonJS\nconst { normalizeURL, joinURL } = require('ufo')\n\n// ESM\nimport { normalizeURL, joinURL } from 'ufo'\n\n// Deno\nimport { parseURL } from 'https://unpkg.com/ufo/dist/index.mjs'\n```\n\n**Notice:** You may need to transpile package and add URL polyfill for legacy environments\n\n## Usage\n\n### `normalizeURL`\n\n- Ensures URL is properly encoded\n- Ensures pathname starts with slash\n- Preserves protocol/host if provided\n\n```ts\n\n// Result: test?query=123%20123#hash,%20test\nnormalizeURL('test?query=123 123#hash, test')\n\n// Result: http://localhost:3000/\nnormalizeURL('http://localhost:3000')\n```\n\n### `joinURL`\n\n```ts\n// Result: a/b/c\njoinURL('a', '/b', '/c')\n```\n\n### `resolveURL`\n\n```ts\n// Result: http://foo.com/foo/bar/baz?test=123#token\nresolveURL('http://foo.com/foo?test=123#token', 'bar', 'baz')\n```\n\n### `parseURL`\n\n```ts\n// Result: { protocol: 'http:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }\nparseURL('http://foo.com/foo?test=123#token')\n\n// Result: { pathname: 'foo.com/foo', search: '?test=123', hash: '#token' }\nparseURL('foo.com/foo?test=123#token')\n\n// Result: { protocol: 'https:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }\nparseURL('foo.com/foo?test=123#token', 'https://')\n```\n\n### `withQuery`\n\n```ts\n// Result: /foo?page=a&token=secret\nwithQuery('/foo?page=a', { token: 'secret' })\n```\n\n### `getQuery`\n\n```ts\n// Result: { test: '123', unicode: '好' }\ngetQuery('http://foo.com/foo?test=123&unicode=%E5%A5%BD')\n```\n\n### `$URL`\n\nImplementing URL interface with some improvements:\n\n- Supporting schemeless and hostless URLs\n- Supporting relative URLs\n- Preserving trailing-slash status\n- Decoded and mutable classs properties (`protocol`, `host`, `auth`, `pathname`, `query`, `hash`)\n- Consistent URL parser independent of environment\n- Consistent encoding independent of environment\n- Punycode support for host encoding\n\n### `withTrailingSlash`\n\nEnsures url ends with a trailing slash\n\n```ts\n// Result: /foo/\nwithTrailingSlash('/foo')\n```\n\n```ts\n// Result: /path/?query=true\nwithTrailingSlash('/path?query=true', true)\n```\n\n### `withoutTrailingSlash`\n\nEnsures url does not ends with a trailing slash\n\n```ts\n// Result: /foo\nwithoutTrailingSlash('/foo/')\n```\n\n```ts\n// Result: /path?query=true\nwithoutTrailingSlash('/path/?query=true', true)\n```\n\n### `cleanDoubleSlashes`\n\nEnsures url does not have double slash (except for protocol)\n\n```ts\n// Result: /foo/bar/\ncleanDoubleSlashes('//foo//bar//')\n// Result: http://example.com/analyze/http://localhost:3000/\ncleanDoubleSlashes('http://example.com/analyze//http://localhost:3000//')\n```\n\n### `isSamePath`\n\nCheck two paths are equal or not. Trailing slash and encoding are normalized before comparation.\n\n```ts\n// Result: true\nisSamePath('/foo', '/foo/')\n```\n\n### `isRelative`\n\nCheck if a path starts with `./` or `../`.\n\n```ts\n// Result: true\nisRelative('./foo')\n```\n\n### `withHttp`\n\nEnsures url protocol is `http`\n\n```ts\n// Result: http://example.com\nwithHttp('https://example.com')\n```\n\n### `withHttps`\n\nEnsures url protocol is `https`\n\n```ts\n// Result: https://example.com\nwithHttps('http://example.com')\n```\n\n### `withProtocol`\n\nChanges url protocol passed as second argument\n\n```ts\n// Result: ftp://example.com\nwithProtocol('http://example.com', 'ftp://')\n```\n\n### `withoutProtocol`\n\nRemoves url protocol\n\n```ts\n// Result: example.com\nwithoutProtocol('http://example.com')\n```\n\n## License\n\n[MIT](./LICENSE)\n\nSpecial thanks to Eduardo San Martin Morote ([posva](https://github.com/posva)) for [encoding utlities](https://github.com/vuejs/vue-router-next/blob/v4.0.1/src/encoding.ts)\n\n<!-- Badges -->\n[npm-version-src]: https://img.shields.io/npm/v/ufo?style=flat-square\n[npm-version-href]: https://npmjs.com/package/ufo\n\n[npm-downloads-src]: https://img.shields.io/npm/dm/ufo?style=flat-square\n[npm-downloads-href]: https://npmjs.com/package/ufo\n\n[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/ufo/ci/main?style=flat-square\n[github-actions-href]: https://github.com/unjs/ufo/actions?query=workflow%3Aci\n\n[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ufo/main?style=flat-square\n[codecov-href]: https://codecov.io/gh/unjs/ufo\n\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/ufo?style=flat-square\n[bundle-href]: https://bundlephobia.com/result?p=ufo\n"
}

@@ -161,2 +161,38 @@ [![npm version][npm-version-src]][npm-version-href]

### `withHttp`
Ensures url protocol is `http`
```ts
// Result: http://example.com
withHttp('https://example.com')
```
### `withHttps`
Ensures url protocol is `https`
```ts
// Result: https://example.com
withHttps('http://example.com')
```
### `withProtocol`
Changes url protocol passed as second argument
```ts
// Result: ftp://example.com
withProtocol('http://example.com', 'ftp://')
```
### `withoutProtocol`
Removes url protocol
```ts
// Result: example.com
withoutProtocol('http://example.com')
```
## License

@@ -163,0 +199,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc