diff --git a/packages/n4s/src/exports/isUrl.ts b/packages/n4s/src/exports/isURL.ts similarity index 100% rename from packages/n4s/src/exports/isUrl.ts rename to packages/n4s/src/exports/isURL.ts diff --git a/packages/vest/.npmignore b/packages/vest/.npmignore index ce8ba984d..21192b146 100644 --- a/packages/vest/.npmignore +++ b/packages/vest/.npmignore @@ -7,6 +7,7 @@ tsconfig.json !promisify/ !parser/ !enforce@schema/ +!enforce@isURL/ !enforce@email/ !enforce@date/ !enforce@compounds/ diff --git a/packages/vest/package.json b/packages/vest/package.json index dc092246c..bf7884fea 100644 --- a/packages/vest/package.json +++ b/packages/vest/package.json @@ -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", diff --git a/packages/vest/src/exports/enforce@isURL.ts b/packages/vest/src/exports/enforce@isURL.ts new file mode 100644 index 000000000..72ef56c1f --- /dev/null +++ b/packages/vest/src/exports/enforce@isURL.ts @@ -0,0 +1 @@ +export * as isURL from 'n4s/isURL'; diff --git a/packages/vest/tsconfig.json b/packages/vest/tsconfig.json index 9ec0de32d..28d0c5560 100644 --- a/packages/vest/tsconfig.json +++ b/packages/vest/tsconfig.json @@ -62,6 +62,7 @@ "promisify": ["./src/exports/promisify.ts"], "parser": ["./src/exports/parser.ts"], "enforce@schema": ["./src/exports/enforce@schema.ts"], + "enforce@isURL": ["./src/exports/enforce@isURL.ts"], "enforce@email": ["./src/exports/enforce@email.ts"], "enforce@date": ["./src/exports/enforce@date.ts"], "enforce@compounds": ["./src/exports/enforce@compounds.ts"], diff --git a/website/docs/enforce/builtin-enforce-plugins/isUrl.md b/website/docs/enforce/builtin-enforce-plugins/isUrl.md index d74bb1472..5a202be03 100644 --- a/website/docs/enforce/builtin-enforce-plugins/isUrl.md +++ b/website/docs/enforce/builtin-enforce-plugins/isUrl.md @@ -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); ``` @@ -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 @@ -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, }); ```