Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ufo

Package Overview
Dependencies
Maintainers
1
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 1.1.1 to 1.1.2

29

dist/index.d.ts

@@ -93,6 +93,35 @@ type QueryValue = string | number | undefined | null | Record<string, any>;

}
/**
* It takes a URL string and returns an object with the URL's protocol, auth, host, pathname, search,
* and hash
* @param [input] - The URL to parse.
* @param [defaultProto] - The default protocol to use if the input doesn't have one.
* @returns A parsed URL object.
*/
declare function parseURL(input?: string, defaultProto?: string): ParsedURL;
/**
* It splits the input string into three parts, and returns an object with those three parts
* @param [input] - The URL to parse.
* @returns An object with three properties: `pathname`, `search`, and `hash`.
*/
declare function parsePath(input?: string): ParsedURL;
/**
* It takes a string of the form `username:password` and returns an object with the username and
* password decoded
* @param [input] - The URL to parse.
* @returns An object with two properties: username and password.
*/
declare function parseAuth(input?: string): ParsedAuth;
/**
* It takes a string, and returns an object with two properties: `hostname` and `port`
* @param [input] - The URL to parse.
* @returns A function that takes a string and returns an object with two properties: `hostname` and
* `port`.
*/
declare function parseHost(input?: string): ParsedHost;
/**
* It takes a `ParsedURL` object and returns the stringified URL
* @param [parsed] - The parsed URL
* @returns A stringified URL.
*/
declare function stringifyParsedURL(parsed: ParsedURL): string;

@@ -99,0 +128,0 @@

23

package.json
{
"name": "ufo",
"version": "1.1.1",
"version": "1.1.2",
"description": "URL utils for humans",

@@ -10,2 +10,3 @@ "repository": "unjs/ufo",

".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",

@@ -32,13 +33,13 @@ "import": "./dist/index.mjs"

"devDependencies": {
"@types/node": "^18.14.2",
"@vitest/coverage-c8": "^0.29.1",
"changelogen": "^0.4.1",
"eslint": "^8.35.0",
"@types/node": "^18.16.3",
"@vitest/coverage-c8": "^0.31.0",
"changelogen": "^0.5.3",
"eslint": "^8.39.0",
"eslint-config-unjs": "^0.1.0",
"prettier": "^2.8.4",
"typescript": "^4.9.5",
"unbuild": "^1.1.2",
"vitest": "^0.29.1"
"prettier": "^2.8.8",
"typescript": "^5.0.4",
"unbuild": "^1.2.1",
"vitest": "^0.31.0"
},
"packageManager": "pnpm@7.28.0"
}
"packageManager": "pnpm@8.4.0"
}

@@ -0,17 +1,18 @@

# 👽 ufo
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions][github-actions-src]][github-actions-href]
[![bundle][bundle-src]][bundle-href]
[![Codecov][codecov-src]][codecov-href]
[![bundle][bundle-src]][bundle-href]
[![License][license-src]][license-href]
[![JSDocs][jsdocs-src]][jsdocs-href]
![👽 ufo](.github/banner.svg)
URL utils for humans.
## Install
Install using npm or yarn:
Install using npm or your favourite package manager:
```bash
npm i ufo
# or
yarn add ufo
```

@@ -43,8 +44,7 @@

```ts
// Result: test?query=123%20123#hash,%20test
normalizeURL('test?query=123 123#hash, test')
// test?query=123%20123#hash,%20test
// Result: http://localhost:3000/
normalizeURL('http://localhost:3000')
// http://localhost:3000/
```

@@ -55,4 +55,4 @@

```ts
// Result: a/b/c
joinURL('a', '/b', '/c')
// a/b/c
```

@@ -63,4 +63,4 @@

```ts
// Result: http://foo.com/foo/bar/baz?test=123#token
resolveURL('http://foo.com/foo?test=123#token', 'bar', 'baz')
// http://foo.com/foo/bar/baz?test=123#token
```

@@ -71,17 +71,27 @@

```ts
// Result: { protocol: 'http:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }
parseURL('http://foo.com/foo?test=123#token')
// { protocol: 'http:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }
// Result: { pathname: 'foo.com/foo', search: '?test=123', hash: '#token' }
parseURL('foo.com/foo?test=123#token')
// { pathname: 'foo.com/foo', search: '?test=123', hash: '#token' }
// Result: { protocol: 'https:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }
parseURL('foo.com/foo?test=123#token', 'https://')
// { protocol: 'https:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }
```
### `stringifyParsedURL`
```ts
const obj = parseURL('http://foo.com/foo?test=123#token')
obj.host = 'bar.com'
stringifyParsedURL(obj)
// http://bar.com/foo?test=123#token
```
### `withQuery`
```ts
// Result: /foo?page=a&token=secret
withQuery('/foo?page=a', { token: 'secret' })
// /foo?page=a&token=secret
```

@@ -92,4 +102,4 @@

```ts
// Result: { test: '123', unicode: '好' }
getQuery('http://foo.com/foo?test=123&unicode=%E5%A5%BD')
// { test: '123', unicode: '好' }
```

@@ -99,3 +109,3 @@

Implementing URL interface with some improvements:
Implementing URL interface with improvements:

@@ -105,3 +115,3 @@ - Supporting schemeless and hostless URLs

- Preserving trailing-slash status
- Decoded and mutable classs properties (`protocol`, `host`, `auth`, `pathname`, `query`, `hash`)
- Decoded and mutable class properties (`protocol`, `host`, `auth`, `pathname`, `query`, `hash`)
- Consistent URL parser independent of environment

@@ -111,14 +121,21 @@ - Consistent encoding independent of environment

```ts
new $URL('http://localhost:3000/hello?world=true')
// { protocol: 'http:', host: 'localhost:3000', auth: '', pathname: '/hello', query: { world: 'true' }, hash: '' }
```
### `withTrailingSlash`
Ensures url ends with a trailing slash
Ensures url ends with a trailing slash.
```ts
// Result: /foo/
withTrailingSlash('/foo')
// /foo/
```
Set the second option to `true` to support query parameters:
```ts
// Result: /path/?query=true
withTrailingSlash('/path?query=true', true)
// /path/?query=true
```

@@ -128,12 +145,14 @@

Ensures url does not ends with a trailing slash
Ensures url does not ends with a trailing slash.
```ts
// Result: /foo
withoutTrailingSlash('/foo/')
// /foo
```
Set the second option to `true` to support query parameters:
```ts
// Result: /path?query=true
withoutTrailingSlash('/path/?query=true', true)
// /path?query=true
```

@@ -143,9 +162,10 @@

Ensures url does not have double slash (except for protocol)
Ensures url does not have double slash (except for protocol).
```ts
// Result: /foo/bar/
cleanDoubleSlashes('//foo//bar//')
// Result: http://example.com/analyze/http://localhost:3000/
// /foo/bar/
cleanDoubleSlashes('http://example.com/analyze//http://localhost:3000//')
// http://example.com/analyze/http://localhost:3000/
```

@@ -158,4 +178,4 @@

```ts
// Result: true
isSamePath('/foo', '/foo/')
// true
```

@@ -168,4 +188,4 @@

```ts
// Result: true
isRelative('./foo')
// true
```

@@ -178,4 +198,4 @@

```ts
// Result: http://example.com
withHttp('https://example.com')
// http://example.com
```

@@ -188,4 +208,4 @@

```ts
// Result: https://example.com
withHttps('http://example.com')
// https://example.com
```

@@ -198,4 +218,4 @@

```ts
// Result: ftp://example.com
withProtocol('http://example.com', 'ftp://')
// ftp://example.com
```

@@ -208,4 +228,4 @@

```ts
// Result: example.com
withoutProtocol('http://example.com')
// example.com
```

@@ -218,12 +238,16 @@

```ts
// Result: true
isEqual('/foo', 'foo')
// true
isEqual('foo/', 'foo')
// true
isEqual('/foo bar', '/foo%20bar')
// true
// Strict compare
// Result: false
isEqual('/foo', 'foo', { leadingSlash: true })
// false
isEqual('foo/', 'foo', { trailingSlash: true })
// false
isEqual('/foo bar', '/foo%20bar', { encoding: true })
// false
```

@@ -238,15 +262,13 @@

<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/ufo?style=flat-square
[npm-version-src]: https://img.shields.io/npm/v/ufo?style=flat&colorA=18181B&colorB=F0DB4F
[npm-version-href]: https://npmjs.com/package/ufo
[npm-downloads-src]: https://img.shields.io/npm/dm/ufo?style=flat-square
[npm-downloads-src]: https://img.shields.io/npm/dm/ufo?style=flat&colorA=18181B&colorB=F0DB4F
[npm-downloads-href]: https://npmjs.com/package/ufo
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/ufo/ci/main?style=flat-square
[github-actions-href]: https://github.com/unjs/ufo/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ufo/main?style=flat-square
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ufo/main?style=flat&colorA=18181B&colorB=F0DB4F
[codecov-href]: https://codecov.io/gh/unjs/ufo
[bundle-src]: https://img.shields.io/bundlephobia/minzip/ufo?style=flat-square
[bundle-src]: https://img.shields.io/bundlephobia/minzip/ufo?style=flat&colorA=18181B&colorB=F0DB4F
[bundle-href]: https://bundlephobia.com/result?p=ufo
[license-src]: https://img.shields.io/github/license/unjs/ufo.svg?style=flat&colorA=18181B&colorB=F0DB4F
[license-href]: https://github.com/unjs/ufo/blob/main/LICENSE
[jsdocs-src]: https://img.shields.io/badge/jsDocs.io-reference-18181B?style=flat&colorA=18181B&colorB=F0DB4F
[jsdocs-href]: https://www.jsdocs.io/package/ufo
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