Skip to content

Commit

Permalink
chore: update automd
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 6, 2024
1 parent 541bc62 commit 3301e51
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 51 deletions.
46 changes: 22 additions & 24 deletions README.md
Expand Up @@ -40,11 +40,9 @@ const { normalizeURL, joinURL } = require("ufo");
import { parseURL } from "https://unpkg.com/ufo/dist/index.mjs";
```

# Utils
<!-- AUTOMD_START generator="jsdocs" defaultGroup="utils" -->

<!-- AUTOMD_START generator="jsdocs" headingLevel="2" -->

## Encoding
## Encoding Utils

### `decode(text)`

Expand Down Expand Up @@ -90,7 +88,7 @@ Encode characters that need to be encoded query values on the query section of t

Encode characters that need to be encoded query values on the query section of the URL.

## Parsing
## Parsing Utils

### `parseAuth(input)`

Expand Down Expand Up @@ -120,7 +118,7 @@ Takes a string, and returns an object with two properties: `hostname` and `port`

Splits the input string into three parts, and returns an object with those three parts.

### `parseURL(input, defaultProto)`
### `parseURL(input, defaultProto?)`

Takes a URL string and returns an object with the URL's `protocol`, `auth`, `host`, `pathname`, `search`, and `hash`.

Expand Down Expand Up @@ -150,7 +148,7 @@ obj.host = "bar.com";
stringifyParsedURL(obj); // "http://bar.com/foo?test=123#token"
```

## Qeury
## Qeury Utils

### `encodeQueryItem(key, value)`

Expand Down Expand Up @@ -198,7 +196,10 @@ getQuery("http://foo.com/foo?test=123&unicode=%E5%A5%BD");

Checks if the input has a leading slash. (e.g. `/foo`)

### `hasTrailingSlash(input, respectQueryAndFragment)`
### `hasProtocol(inputString, opts)`


### `hasTrailingSlash(input, respectQueryAndFragment?)`

Checks if the input has a trailing slash.

Expand Down Expand Up @@ -250,7 +251,7 @@ Check two paths are equal or not. Trailing slash and encoding are normalized bef
isSamePath("/foo", "/foo/"); // true
```

### `isScriptProtocol(protocol)`
### `isScriptProtocol(protocol?)`

Checks if the input protocol is any of the dangerous `blob:`, `data:`, `javascript`: or `vbscript:` protocols.

Expand Down Expand Up @@ -354,7 +355,17 @@ withoutFragment("http://example.com/foo?q=123#bar")

Removes leading slash from the URL or pathname.

### `withoutTrailingSlash(input, respectQueryAndFragment)`
### `withoutProtocol(input)`

Removes the protocol from the input.

**Example:**

```js
withoutProtocol("http://example.com"); // "example.com"
```

### `withoutTrailingSlash(input, respectQueryAndFragment?)`

Removes trailing slash from the URL or pathname.

Expand Down Expand Up @@ -388,7 +399,7 @@ Add/Replace the query section of the URL.
withQuery("/foo?page=a", { token: "secret" }); // "/foo?page=a&token=secret"
```

### `withTrailingSlash(input, respectQueryAndFragment)`
### `withTrailingSlash(input, respectQueryAndFragment?)`

Ensures url ends with a trailing slash.

Expand All @@ -402,19 +413,6 @@ withTrailingSlash("/foo"); // "/foo/"
withTrailingSlash("/path?query=true", true); // "/path/?query=true"
```

### `hasProtocol(inputString, opts)`


### `withoutProtocol(input)`

Removes the protocol from the input.

**Example:**

```js
withoutProtocol("http://example.com"); // "example.com"
```


<!-- AUTOMD_END -->

Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"@types/node": "^20.11.16",
"@vitest/coverage-v8": "^1.2.2",
"automd": "^0.1.1",
"automd": "^0.1.4",
"changelogen": "^0.5.5",
"eslint": "^8.56.0",
"eslint-config-unjs": "^0.2.1",
Expand All @@ -44,4 +44,4 @@
"vitest": "^1.2.2"
},
"packageManager": "pnpm@8.15.1"
}
}
15 changes: 10 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions src/encoding.ts
Expand Up @@ -23,7 +23,7 @@ const ENC_ENC_SLASH_RE = /%252f/gi;
* Encode characters that need to be encoded on the path, search and hash
* sections of the URL.
*
* @group encoding
* @group encoding_utils
*
* @param text - string to encode
* @returns encoded string
Expand All @@ -35,7 +35,7 @@ export function encode(text: string | number): string {
/**
* Encode characters that need to be encoded on the hash section of the URL.
*
* @group encoding
* @group encoding_utils
*
* @param text - string to encode
* @returns encoded string
Expand All @@ -51,7 +51,7 @@ export function encodeHash(text: string): string {
* Encode characters that need to be encoded query values on the query
* section of the URL.
*
* @group encoding
* @group encoding_utils
*
* @param input - string to encode
* @returns encoded string
Expand All @@ -74,7 +74,7 @@ export function encodeQueryValue(input: QueryValue): string {
* Encode characters that need to be encoded query values on the query
* section of the URL and also encodes the `=` character.
*
* @group encoding
* @group encoding_utils
*
* @param text - string to encode
*/
Expand All @@ -85,7 +85,7 @@ export function encodeQueryKey(text: string | number): string {
/**
* Encode characters that need to be encoded on the path section of the URL.
*
* @group encoding
* @group encoding_utils
*
* @param text - string to encode
* @returns encoded string
Expand All @@ -104,7 +104,7 @@ export function encodePath(text: string | number): string {
* param. This function encodes everything `encodePath` does plus the
* slash (`/`) character.
*
* @group encoding
* @group encoding_utils
*
* @param text - string to encode
* @returns encoded string
Expand All @@ -117,7 +117,7 @@ export function encodeParam(text: string | number): string {
* Decode text using `decodeURIComponent`. Returns the original text if it
* fails.
*
* @group encoding
* @group encoding_utils
*
* @param text - string to decode
* @returns decoded string
Expand All @@ -133,7 +133,7 @@ export function decode(text: string | number = ""): string {
/**
* Decode path section of URL (consistent with encodePath for slash encoding).
*
* @group encoding
* @group encoding_utils
*
* @param text - string to decode
* @returns decoded string
Expand All @@ -145,7 +145,7 @@ export function decodePath(text: string): string {
/**
* Decodes query key (consistent with `encodeQueryKey` for plus encoding).
*
* @group encoding
* @group encoding_utils
*
* @param text - string to decode
* @returns decoded string
Expand All @@ -157,7 +157,7 @@ export function decodeQueryKey(text: string): string {
/**
* Decode query value (consistent with encodeQueryValue for plus encoding).
*
* @group encoding
* @group encoding_utils
*
* @param text - string to decode
* @returns decoded string
Expand All @@ -169,7 +169,7 @@ export function decodeQueryValue(text: string): string {
/**
* Encodes hostname with punycode encoding.
*
* @group encoding
* @group encoding_utils
*/
export function encodeHost(name = "") {
return toASCII(name);
Expand Down
12 changes: 6 additions & 6 deletions src/parse.ts
Expand Up @@ -38,7 +38,7 @@ export interface ParsedHost {
* // { protocol: 'https:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }
* ```
*
* @group parsing
* @group parsing_utils
*
* @param [input] - The URL to parse.
* @param [defaultProto] - The default protocol to use if the input doesn't have one.
Expand Down Expand Up @@ -88,7 +88,7 @@ export function parseURL(input = "", defaultProto?: string): ParsedURL {
/**
* Splits the input string into three parts, and returns an object with those three parts.
*
* @group parsing
* @group parsing_utils
*
* @param [input] - The URL to parse.
* @returns An object with three properties: `pathname`, `search`, and `hash`.
Expand All @@ -109,7 +109,7 @@ export function parsePath(input = ""): ParsedURL {
* Takes a string of the form `username:password` and returns an object with the username and
* password decoded.
*
* @group parsing
* @group parsing_utils
*
* @param [input] - The URL to parse.
* @returns An object with two properties: username and password.
Expand All @@ -125,7 +125,7 @@ export function parseAuth(input = ""): ParsedAuth {
/**
* Takes a string, and returns an object with two properties: `hostname` and `port`.
*
* @group parsing
* @group parsing_utils
*
* @param [input] - The URL to parse.
* @returns A function that takes a string and returns an object with two properties: `hostname` and
Expand All @@ -142,7 +142,7 @@ export function parseHost(input = ""): ParsedHost {
/**
* Takes a `ParsedURL` object and returns the stringified URL.
*
* @group parsing
* @group parsing_utils
*
* @example
*
Expand Down Expand Up @@ -179,7 +179,7 @@ const FILENAME_REGEX = /\/([^/]+)$/;
*
* If `{ strict: true }` is passed as the second argument, it will only return the last segment only if ending with an extension.
*
* @group parsing
* @group parsing_utils
*
* @example
*
Expand Down
6 changes: 3 additions & 3 deletions src/query.ts
Expand Up @@ -26,7 +26,7 @@ export type ParsedQuery = Record<string, string | string[]>;
* @note
* The `__proto__` and `constructor` keys are ignored to prevent prototype pollution.
*
* @group qeury
* @group qeury_utils
*/
export function parseQuery<T extends ParsedQuery = ParsedQuery>(
parametersString = ""
Expand Down Expand Up @@ -61,7 +61,7 @@ export function parseQuery<T extends ParsedQuery = ParsedQuery>(
*
* If the value is an array, it will be encoded as multiple key-value pairs with the same key.
*
* @group qeury
* @group qeury_utils
*/
export function encodeQueryItem(
key: string,
Expand All @@ -86,7 +86,7 @@ export function encodeQueryItem(
/**
* Stringfies and encodes a query object into a query string.
*
* @group qeury
* @group qeury_utils
*/
export function stringifyQuery(query: QueryObject): string {
return Object.keys(query)
Expand Down

0 comments on commit 3301e51

Please sign in to comment.