Skip to content

Commit

Permalink
add(vest): Expose isURL rule through Vest as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Aug 10, 2023
1 parent 9b2cbb1 commit 7b0149b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions packages/vest/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tsconfig.json
!promisify/
!parser/
!enforce@schema/
!enforce@isURL/
!enforce@email/
!enforce@date/
!enforce@compounds/
Expand Down
30 changes: 30 additions & 0 deletions packages/vest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,36 @@
"module": "./dist/es/enforce/schema.production.js",
"default": "./dist/cjs/enforce/schema.production.js"
},
"./enforce/isURL": {
"production": {
"types": "./types/enforce/isURL.d.ts",
"browser": "./dist/es/enforce/isURL.production.js",
"umd": "./dist/umd/enforce/isURL.production.js",
"import": "./dist/es/enforce/isURL.production.js",
"require": "./dist/cjs/enforce/isURL.production.js",
"node": "./dist/cjs/enforce/isURL.production.js",
"module": "./dist/es/enforce/isURL.production.js",
"default": "./dist/cjs/enforce/isURL.production.js"
},
"development": {
"types": "./types/enforce/isURL.d.ts",
"browser": "./dist/es/enforce/isURL.development.js",
"umd": "./dist/umd/enforce/isURL.development.js",
"import": "./dist/es/enforce/isURL.development.js",
"require": "./dist/cjs/enforce/isURL.development.js",
"node": "./dist/cjs/enforce/isURL.development.js",
"module": "./dist/es/enforce/isURL.development.js",
"default": "./dist/cjs/enforce/isURL.development.js"
},
"types": "./types/enforce/isURL.d.ts",
"browser": "./dist/es/enforce/isURL.production.js",
"umd": "./dist/umd/enforce/isURL.production.js",
"import": "./dist/es/enforce/isURL.production.js",
"require": "./dist/cjs/enforce/isURL.production.js",
"node": "./dist/cjs/enforce/isURL.production.js",
"module": "./dist/es/enforce/isURL.production.js",
"default": "./dist/cjs/enforce/isURL.production.js"
},
"./enforce/email": {
"production": {
"types": "./types/enforce/email.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/vest/src/exports/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as isURL from 'n4s/isURL';
1 change: 1 addition & 0 deletions packages/vest/tsconfig.json

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

28 changes: 16 additions & 12 deletions website/docs/enforce/builtin-enforce-plugins/isUrl.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ These rule exposes the [`validator.js`](https://www.npmjs.com/package/validator)

The `isURL` rule checks whether a given value is a valid URL. It accepts various options to customize the validation behavior.

To be used, the rule first needs to be imported:

```javascript
import 'vest/enforce/isURL';

enforce(value).isURL(options);
```

Expand All @@ -27,17 +31,17 @@ The isURL rule accepts an optional options object to customize the validation be

The `isUrl` rule accepts an optional `options` object to customize the validation behavior. The available options are as follows:

| Option | Default Value | Description |
| ----------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------- |
| `require_protocol` | `false` | Requires the URL to include a protocol (e.g., `http://` or `https://`). |
| `require_host` | `true` | Requires the URL to include a host (e.g., `www.example.com`). |
| `require_valid_protocol` | `true` | Requires the URL's protocol to be in the list of valid protocols (`http`, `https`, `ftp`). |
| `allow_underscores` | `false` | Allows underscores in the host name. |
| `allow_trailing_dot` | `false` | Allows a trailing dot in the host name. |
| `allow_protocol_relative_urls`| `false` | Allows protocol-relative URLs (e.g., `//www.example.com`). |
| `allow_fragments` | `true` | Allows URL fragments (e.g., `#section`). |
| `allow_query_components` | `true` | Allows query components in the URL (e.g., `?query=value`). |
| `validate_length` | `true` | Validates that the URL length does not exceed the maximum allowed length (2083 characters). |
| Option | Default Value | Description |
| ------------------------------ | ------------- | ------------------------------------------------------------------------------------------- |
| `require_protocol` | `false` | Requires the URL to include a protocol (e.g., `http://` or `https://`). |
| `require_host` | `true` | Requires the URL to include a host (e.g., `www.example.com`). |
| `require_valid_protocol` | `true` | Requires the URL's protocol to be in the list of valid protocols (`http`, `https`, `ftp`). |
| `allow_underscores` | `false` | Allows underscores in the host name. |
| `allow_trailing_dot` | `false` | Allows a trailing dot in the host name. |
| `allow_protocol_relative_urls` | `false` | Allows protocol-relative URLs (e.g., `//www.example.com`). |
| `allow_fragments` | `true` | Allows URL fragments (e.g., `#section`). |
| `allow_query_components` | `true` | Allows query components in the URL (e.g., `?query=value`). |
| `validate_length` | `true` | Validates that the URL length does not exceed the maximum allowed length (2083 characters). |

### Usage Example

Expand All @@ -55,6 +59,6 @@ enforce(url).isURL({
allow_protocol_relative_urls: false,
allow_fragments: true,
allow_query_components: true,
validate_length: true
validate_length: true,
});
```

2 comments on commit 7b0149b

@vercel
Copy link

@vercel vercel bot commented on 7b0149b Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest – ./website

vest.vercel.app
vest-git-latest-ealush.vercel.app
vest-ealush.vercel.app
www.vestjs.dev
vestjs.dev

@vercel
Copy link

@vercel vercel bot commented on 7b0149b Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-next-git-latest-ealush.vercel.app
vest-next.vercel.app
vest-next-ealush.vercel.app
vest-website.vercel.app

Please sign in to comment.