From 7b0149bcdce839c72fd80af95cf1ef01c51032a8 Mon Sep 17 00:00:00 2001 From: Evyatar Date: Fri, 11 Aug 2023 00:03:00 +0300 Subject: [PATCH] add(vest): Expose isURL rule through Vest as well --- .../n4s/src/exports/{isUrl.ts => isURL.ts} | 0 packages/vest/.npmignore | 1 + packages/vest/package.json | 30 +++++++++++++++++++ packages/vest/src/exports/enforce@isURL.ts | 1 + packages/vest/tsconfig.json | 1 + .../enforce/builtin-enforce-plugins/isUrl.md | 28 +++++++++-------- 6 files changed, 49 insertions(+), 12 deletions(-) rename packages/n4s/src/exports/{isUrl.ts => isURL.ts} (100%) create mode 100644 packages/vest/src/exports/enforce@isURL.ts 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, }); ```