@skyux/validation 5.9.7 → 5.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/components/validation/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wDAAwD,CAAC;AACvE,cAAc,oDAAoD,CAAC;AACnE,cAAc,qCAAqC,CAAC;AACpD,cAAc,qCAAqC,CAAC;AAEpD,0FAA0F;AAC1F,2EAA2E;AAC3E,OAAO,EAAE,2BAA2B,IAAI,EAAE,EAAE,MAAM,2DAA2D,CAAC;AAC9G,OAAO,EAAE,yBAAyB,IAAI,EAAE,EAAE,MAAM,uDAAuD,CAAC","sourcesContent":["export * from './lib/modules/email-validation/email-validation.module';\nexport * from './lib/modules/url-validation/url-validation.module';\nexport * from './lib/modules/validation/validation';\nexport * from './lib/modules/validators/validators';\n\n// Components and directives must be exported to support Angular's \"partial\" Ivy compiler.\n// Obscure names are used to indicate types are not part of the public API.\nexport { SkyEmailValidationDirective as λ1 } from './lib/modules/email-validation/email-validation.directive';\nexport { SkyUrlValidationDirective as λ2 } from './lib/modules/url-validation/url-validation.directive';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/components/validation/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wDAAwD,CAAC;AACvE,cAAc,qDAAqD,CAAC;AACpE,cAAc,oDAAoD,CAAC;AACnE,cAAc,qCAAqC,CAAC;AACpD,cAAc,qCAAqC,CAAC;AAEpD,0FAA0F;AAC1F,2EAA2E;AAC3E,OAAO,EAAE,2BAA2B,IAAI,EAAE,EAAE,MAAM,2DAA2D,CAAC;AAC9G,OAAO,EAAE,yBAAyB,IAAI,EAAE,EAAE,MAAM,uDAAuD,CAAC","sourcesContent":["export * from './lib/modules/email-validation/email-validation.module';\nexport * from './lib/modules/url-validation/url-validation-options';\nexport * from './lib/modules/url-validation/url-validation.module';\nexport * from './lib/modules/validation/validation';\nexport * from './lib/modules/validators/validators';\n\n// Components and directives must be exported to support Angular's \"partial\" Ivy compiler.\n// Obscure names are used to indicate types are not part of the public API.\nexport { SkyEmailValidationDirective as λ1 } from './lib/modules/email-validation/email-validation.directive';\nexport { SkyUrlValidationDirective as λ2 } from './lib/modules/url-validation/url-validation.directive';\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=url-validation-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-validation-options.js","sourceRoot":"","sources":["../../../../../../../../libs/components/validation/src/lib/modules/url-validation/url-validation-options.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Specifies options for the URL validator component.\n */\nexport interface SkyUrlValidationOptions {\n /**\n * Indicates the ruleset to use for URL validation. Ruleset 1 uses a regular expression and ruleset 2 uses the third-party [validator.js library](https://github.com/validatorjs/validator.js/).\n */\n rulesetVersion: 1 | 2;\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { Directive, forwardRef } from '@angular/core';
2
- import { NG_VALIDATORS } from '@angular/forms';
1
+ import { Directive, Input, forwardRef } from '@angular/core';
2
+ import { NG_VALIDATORS, } from '@angular/forms';
3
3
  import { SkyValidation } from '../validation/validation';
4
4
  import * as i0 from "@angular/core";
5
5
  // tslint:disable:no-forward-ref no-use-before-declare
@@ -15,30 +15,39 @@ const SKY_URL_VALIDATION_VALIDATOR = {
15
15
  * This directive uses `NgModel` to bind data.
16
16
  */
17
17
  export class SkyUrlValidationDirective {
18
+ constructor() {
19
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
20
+ this._validatorChange = () => { };
21
+ }
22
+ /**
23
+ * Specifies configuration options for the URL validation component.
24
+ */
25
+ set skyUrlValidation(value) {
26
+ this._skyUrlValidationOptions = value;
27
+ this._validatorChange();
28
+ }
18
29
  validate(control) {
19
30
  const value = control.value;
20
31
  if (!value) {
21
- return;
22
- }
23
- if (!this.urlIsValid(value)) {
24
- return {
25
- skyUrl: {
26
- invalid: control.value,
27
- },
28
- };
32
+ return null;
29
33
  }
34
+ return SkyValidation.isUrl(value, this._skyUrlValidationOptions)
35
+ ? null
36
+ : { skyUrl: { invalid: value } };
30
37
  }
31
- urlIsValid(url) {
32
- return SkyValidation.isUrl(url);
38
+ registerOnValidatorChange(fn) {
39
+ this._validatorChange = fn;
33
40
  }
34
41
  }
35
42
  SkyUrlValidationDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyUrlValidationDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
36
- SkyUrlValidationDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyUrlValidationDirective, selector: "[skyUrlValidation]", providers: [SKY_URL_VALIDATION_VALIDATOR], ngImport: i0 });
43
+ SkyUrlValidationDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyUrlValidationDirective, selector: "[skyUrlValidation]", inputs: { skyUrlValidation: "skyUrlValidation" }, providers: [SKY_URL_VALIDATION_VALIDATOR], ngImport: i0 });
37
44
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyUrlValidationDirective, decorators: [{
38
45
  type: Directive,
39
46
  args: [{
40
47
  selector: '[skyUrlValidation]',
41
48
  providers: [SKY_URL_VALIDATION_VALIDATOR],
42
49
  }]
43
- }] });
50
+ }], propDecorators: { skyUrlValidation: [{
51
+ type: Input
52
+ }] } });
44
53
  //# sourceMappingURL=url-validation.directive.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"url-validation.directive.js","sourceRoot":"","sources":["../../../../../../../../libs/components/validation/src/lib/modules/url-validation/url-validation.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAmB,aAAa,EAAa,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;;AAEzD,sDAAsD;AACtD,MAAM,4BAA4B,GAAG;IACnC,OAAO,EAAE,aAAa;IACtB,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,yBAAyB,CAAC;IACxD,KAAK,EAAE,IAAI;CACZ,CAAC;AACF,gBAAgB;AAEhB;;;;GAIG;AAKH,MAAM,OAAO,yBAAyB;IAC7B,QAAQ,CAAC,OAAwB;QACtC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5B,IAAI,CAAC,KAAK,EAAE;YACV,OAAO;SACR;QAED,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC3B,OAAO;gBACL,MAAM,EAAE;oBACN,OAAO,EAAE,OAAO,CAAC,KAAK;iBACvB;aACF,CAAC;SACH;IACH,CAAC;IAEM,UAAU,CAAC,GAAW;QAC3B,OAAO,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;;uHAnBU,yBAAyB;2GAAzB,yBAAyB,6CAFzB,CAAC,4BAA4B,CAAC;4FAE9B,yBAAyB;kBAJrC,SAAS;mBAAC;oBACT,QAAQ,EAAE,oBAAoB;oBAC9B,SAAS,EAAE,CAAC,4BAA4B,CAAC;iBAC1C","sourcesContent":["import { Directive, forwardRef } from '@angular/core';\nimport { AbstractControl, NG_VALIDATORS, Validator } from '@angular/forms';\n\nimport { SkyValidation } from '../validation/validation';\n\n// tslint:disable:no-forward-ref no-use-before-declare\nconst SKY_URL_VALIDATION_VALIDATOR = {\n provide: NG_VALIDATORS,\n useExisting: forwardRef(() => SkyUrlValidationDirective),\n multi: true,\n};\n// tslint:enable\n\n/**\n * Creates an input to validate URLs. Place this attribute on an `input` element.\n * If users enters values that are not valid URLs, an error message appears.\n * This directive uses `NgModel` to bind data.\n */\n@Directive({\n selector: '[skyUrlValidation]',\n providers: [SKY_URL_VALIDATION_VALIDATOR],\n})\nexport class SkyUrlValidationDirective implements Validator {\n public validate(control: AbstractControl): { [key: string]: any } {\n const value = control.value;\n\n if (!value) {\n return;\n }\n\n if (!this.urlIsValid(value)) {\n return {\n skyUrl: {\n invalid: control.value,\n },\n };\n }\n }\n\n public urlIsValid(url: string): boolean {\n return SkyValidation.isUrl(url);\n }\n}\n"]}
1
+ {"version":3,"file":"url-validation.directive.js","sourceRoot":"","sources":["../../../../../../../../libs/components/validation/src/lib/modules/url-validation/url-validation.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAEL,aAAa,GAGd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;;AAIzD,sDAAsD;AACtD,MAAM,4BAA4B,GAAG;IACnC,OAAO,EAAE,aAAa;IACtB,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,yBAAyB,CAAC;IACxD,KAAK,EAAE,IAAI;CACZ,CAAC;AACF,gBAAgB;AAEhB;;;;GAIG;AAKH,MAAM,OAAO,yBAAyB;IAJtC;QAgBE,gEAAgE;QACxD,qBAAgB,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;KAiBrC;IA7BC;;OAEG;IACH,IACW,gBAAgB,CAAC,KAA0C;QACpE,IAAI,CAAC,wBAAwB,GAAG,KAAK,CAAC;QACtC,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAOM,QAAQ,CAAC,OAAwB;QACtC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5B,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,IAAI,CAAC;SACb;QAED,OAAO,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,wBAAwB,CAAC;YAC9D,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;IACrC,CAAC;IAEM,yBAAyB,CAAC,EAAc;QAC7C,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;IAC7B,CAAC;;uHA7BU,yBAAyB;2GAAzB,yBAAyB,+FAFzB,CAAC,4BAA4B,CAAC;4FAE9B,yBAAyB;kBAJrC,SAAS;mBAAC;oBACT,QAAQ,EAAE,oBAAoB;oBAC9B,SAAS,EAAE,CAAC,4BAA4B,CAAC;iBAC1C;8BAMY,gBAAgB;sBAD1B,KAAK","sourcesContent":["import { Directive, Input, forwardRef } from '@angular/core';\nimport {\n AbstractControl,\n NG_VALIDATORS,\n ValidationErrors,\n Validator,\n} from '@angular/forms';\n\nimport { SkyValidation } from '../validation/validation';\n\nimport { SkyUrlValidationOptions } from './url-validation-options';\n\n// tslint:disable:no-forward-ref no-use-before-declare\nconst SKY_URL_VALIDATION_VALIDATOR = {\n provide: NG_VALIDATORS,\n useExisting: forwardRef(() => SkyUrlValidationDirective),\n multi: true,\n};\n// tslint:enable\n\n/**\n * Creates an input to validate URLs. Place this attribute on an `input` element.\n * If users enters values that are not valid URLs, an error message appears.\n * This directive uses `NgModel` to bind data.\n */\n@Directive({\n selector: '[skyUrlValidation]',\n providers: [SKY_URL_VALIDATION_VALIDATOR],\n})\nexport class SkyUrlValidationDirective implements Validator {\n /**\n * Specifies configuration options for the URL validation component.\n */\n @Input()\n public set skyUrlValidation(value: SkyUrlValidationOptions | undefined) {\n this._skyUrlValidationOptions = value;\n this._validatorChange();\n }\n\n private _skyUrlValidationOptions: SkyUrlValidationOptions | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n private _validatorChange = () => {};\n\n public validate(control: AbstractControl): ValidationErrors | null {\n const value = control.value;\n\n if (!value) {\n return null;\n }\n\n return SkyValidation.isUrl(value, this._skyUrlValidationOptions)\n ? null\n : { skyUrl: { invalid: value } };\n }\n\n public registerOnValidatorChange(fn: () => void): void {\n this._validatorChange = fn;\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import isURL from 'validator/es/lib/isURL';
1
2
  export class SkyValidation {
2
3
  static isEmail(emailAddress) {
3
4
  // The regex was obtained from http://emailregex.com/
@@ -6,9 +7,24 @@ export class SkyValidation {
6
7
  const regex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
7
8
  return regex.test(emailAddress);
8
9
  }
9
- static isUrl(url) {
10
+ static isUrl(value, options) {
11
+ if (typeof value !== 'string') {
12
+ return false;
13
+ }
14
+ const url = value;
10
15
  const regex = /^((http|https):\/\/)?([\w-]+\.)+[\w-]+/i;
11
- return regex.test(url);
16
+ if (options) {
17
+ switch (options.rulesetVersion) {
18
+ case 1:
19
+ return regex.test(url);
20
+ case 2:
21
+ // we are using the `validator` package's default options
22
+ return isURL(url);
23
+ }
24
+ }
25
+ else {
26
+ return regex.test(url);
27
+ }
12
28
  }
13
29
  }
14
30
  //# sourceMappingURL=validation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../../../../../../libs/components/validation/src/lib/modules/validation/validation.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,aAAa;IAC1B,MAAM,CAAC,OAAO,CAAC,YAAoB;QACxC,qDAAqD;QACrD,gEAAgE;QAChE,2CAA2C;QAC3C,MAAM,KAAK,GACT,sJAAsJ,CAAC;QACzJ,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,GAAW;QAC7B,MAAM,KAAK,GAAG,yCAAyC,CAAC;QACxD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;CACF","sourcesContent":["export abstract class SkyValidation {\n public static isEmail(emailAddress: string): boolean {\n // The regex was obtained from http://emailregex.com/\n // which claims to correctly handle ~99% of all email addresses.\n // tslint:disable-next-line:max-line-length\n const regex =\n /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n return regex.test(emailAddress);\n }\n\n public static isUrl(url: string): boolean {\n const regex = /^((http|https):\\/\\/)?([\\w-]+\\.)+[\\w-]+/i;\n return regex.test(url);\n }\n}\n"]}
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../../../../../../libs/components/validation/src/lib/modules/validation/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,wBAAwB,CAAC;AAI3C,MAAM,OAAgB,aAAa;IAC1B,MAAM,CAAC,OAAO,CAAC,YAAoB;QACxC,qDAAqD;QACrD,gEAAgE;QAChE,2CAA2C;QAC3C,MAAM,KAAK,GACT,sJAAsJ,CAAC;QACzJ,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,KAAK,CACjB,KAAc,EACd,OAAiC;QAEjC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,KAAK,CAAC;SACd;QAED,MAAM,GAAG,GAAW,KAAK,CAAC;QAE1B,MAAM,KAAK,GAAG,yCAAyC,CAAC;QACxD,IAAI,OAAO,EAAE;YACX,QAAQ,OAAO,CAAC,cAAc,EAAE;gBAC9B,KAAK,CAAC;oBACJ,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACzB,KAAK,CAAC;oBACJ,yDAAyD;oBACzD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;aACrB;SACF;aAAM;YACL,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACxB;IACH,CAAC;CACF","sourcesContent":["import isURL from 'validator/es/lib/isURL';\n\nimport { SkyUrlValidationOptions } from '../url-validation/url-validation-options';\n\nexport abstract class SkyValidation {\n public static isEmail(emailAddress: string): boolean {\n // The regex was obtained from http://emailregex.com/\n // which claims to correctly handle ~99% of all email addresses.\n // tslint:disable-next-line:max-line-length\n const regex =\n /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n return regex.test(emailAddress);\n }\n\n public static isUrl(\n value: unknown,\n options?: SkyUrlValidationOptions\n ): boolean {\n if (typeof value !== 'string') {\n return false;\n }\n\n const url: string = value;\n\n const regex = /^((http|https):\\/\\/)?([\\w-]+\\.)+[\\w-]+/i;\n if (options) {\n switch (options.rulesetVersion) {\n case 1:\n return regex.test(url);\n case 2:\n // we are using the `validator` package's default options\n return isURL(url);\n }\n } else {\n return regex.test(url);\n }\n }\n}\n"]}
@@ -7,33 +7,43 @@ export class SkyValidators {
7
7
  * Validates email addresses in reactive forms. Add this validator directly to the form control
8
8
  * model in the component class. If users enter values that are not valid email addresses, the
9
9
  * validator throws an error. Since this is a sync validator, it returns a set of validation
10
- * errors or `undefined` immediately when users enter values.
11
- * @param control
10
+ * errors or `null` immediately when users enter values.
12
11
  */
13
12
  static email(control) {
14
13
  const value = control.value;
15
14
  if (!value) {
16
- return undefined;
15
+ return null;
17
16
  }
18
17
  return SkyValidation.isEmail(value)
19
- ? undefined
18
+ ? null
20
19
  : { skyEmail: { invalid: value } };
21
20
  }
22
- /**
23
- * Validates URLs in reactive forms. Add this validator directly to the form control model in
24
- * the component class. If users enter values that are not valid URLs, the validator throws an
25
- * error. Since this is a sync validator, it returns a set of validation errors or `undefined`
26
- * immediately when users enter values.
27
- * @param control
28
- */
29
- static url(control) {
30
- const value = control.value;
31
- if (!value) {
32
- return undefined;
21
+ static url(value) {
22
+ const typeTester = value;
23
+ if (typeTester.rulesetVersion === undefined) {
24
+ // there are no SkyUrlValidationOptions passed in, so return ValidationErrors | null
25
+ const abstractControl = value;
26
+ const abstractControlValue = abstractControl.value;
27
+ if (!abstractControlValue) {
28
+ return null;
29
+ }
30
+ return SkyValidation.isUrl(abstractControlValue)
31
+ ? null
32
+ : { skyUrl: { invalid: abstractControlValue } };
33
+ }
34
+ else {
35
+ // there are SkyUrlValidationOptions passed in, so return ValidatorFn
36
+ const skyUrlValidationOptions = value;
37
+ return (abstractControl) => {
38
+ const abstractControlValue = abstractControl.value;
39
+ if (!abstractControlValue) {
40
+ return null;
41
+ }
42
+ return SkyValidation.isUrl(abstractControl.value, skyUrlValidationOptions)
43
+ ? null
44
+ : { skyUrl: { invalid: abstractControl.value } };
45
+ };
33
46
  }
34
- return SkyValidation.isUrl(value)
35
- ? undefined
36
- : { skyUrl: { invalid: value } };
37
47
  }
38
48
  }
39
49
  //# sourceMappingURL=validators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../../../../../../libs/components/validation/src/lib/modules/validators/validators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,qEAAqE;AACrE,2DAA2D;AAC3D,WAAW;AACX,MAAM,OAAO,aAAa;IACxB;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,OAAwB;QAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5B,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC;YACjC,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;IACvC,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,GAAG,CAAC,OAAwB;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5B,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;YAC/B,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;IACrC,CAAC;CACF","sourcesContent":["import { AbstractControl, ValidationErrors } from '@angular/forms';\n\nimport { SkyValidation } from '../validation/validation';\n\n// Need to add the following to classes which contain static methods.\n// See: https://github.com/ng-packagr/ng-packagr/issues/641\n// @dynamic\nexport class SkyValidators {\n /**\n * Validates email addresses in reactive forms. Add this validator directly to the form control\n * model in the component class. If users enter values that are not valid email addresses, the\n * validator throws an error. Since this is a sync validator, it returns a set of validation\n * errors or `undefined` immediately when users enter values.\n * @param control\n */\n public static email(control: AbstractControl): ValidationErrors | null {\n const value = control.value;\n\n if (!value) {\n return undefined;\n }\n\n return SkyValidation.isEmail(value)\n ? undefined\n : { skyEmail: { invalid: value } };\n }\n\n /**\n * Validates URLs in reactive forms. Add this validator directly to the form control model in\n * the component class. If users enter values that are not valid URLs, the validator throws an\n * error. Since this is a sync validator, it returns a set of validation errors or `undefined`\n * immediately when users enter values.\n * @param control\n */\n public static url(control: AbstractControl): ValidationErrors | null {\n const value = control.value;\n\n if (!value) {\n return undefined;\n }\n\n return SkyValidation.isUrl(value)\n ? undefined\n : { skyUrl: { invalid: value } };\n }\n}\n"]}
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../../../../../../libs/components/validation/src/lib/modules/validators/validators.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,qEAAqE;AACrE,2DAA2D;AAC3D,WAAW;AACX,MAAM,OAAO,aAAa;IACxB;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC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kyUrlValidationOptions } from '../url-validation/url-validation-options';\nimport { SkyValidation } from '../validation/validation';\n\n// Need to add the following to classes which contain static methods.\n// See: https://github.com/ng-packagr/ng-packagr/issues/641\n// @dynamic\nexport class SkyValidators {\n /**\n * Validates email addresses in reactive forms. Add this validator directly to the form control\n * model in the component class. If users enter values that are not valid email addresses, the\n * validator throws an error. Since this is a sync validator, it returns a set of validation\n * errors or `null` immediately when users enter values.\n */\n public static email(control: AbstractControl): ValidationErrors | null {\n const value = control.value;\n\n if (!value) {\n return null;\n }\n\n return SkyValidation.isEmail(value)\n ? null\n : { skyEmail: { invalid: value } };\n }\n\n /**\n * Validates URLs in reactive forms. Add this validator directly to the form control model in\n * the component class. If users enter values that are not valid URLs, the validator throws an\n * error. Since this is a sync validator, it returns a set of validation errors or `null`\n * immediately when users enter values.\n */\n public static url(abstractControl: AbstractControl): ValidationErrors | null;\n\n /**\n * Validates URLs in reactive forms. Add this validator with ruleset parameters directly to\n * the form control model in the component class. If users enter values that are not valid\n * URLs, the validator throws an error. Since this is a sync validator, it returns a set of\n * validation errors or `null` immediately when users enter values.\n */\n public static url(\n skyUrlValidationOptions: SkyUrlValidationOptions\n ): ValidatorFn | null;\n\n public static url(\n value: AbstractControl | SkyUrlValidationOptions\n ): ValidatorFn | ValidationErrors | null {\n const typeTester = value as SkyUrlValidationOptions;\n if (typeTester.rulesetVersion === undefined) {\n // there are no SkyUrlValidationOptions passed in, so return ValidationErrors | null\n const abstractControl = value as AbstractControl;\n const abstractControlValue = abstractControl.value;\n if (!abstractControlValue) {\n return null;\n }\n return SkyValidation.isUrl(abstractControlValue)\n ? null\n : { skyUrl: { invalid: abstractControlValue } };\n } else {\n // there are SkyUrlValidationOptions passed in, so return ValidatorFn\n const skyUrlValidationOptions = value as SkyUrlValidationOptions;\n return (abstractControl: AbstractControl): ValidationErrors | null => {\n const abstractControlValue = abstractControl.value;\n if (!abstractControlValue) {\n return null;\n }\n\n return SkyValidation.isUrl(\n abstractControl.value,\n skyUrlValidationOptions\n )\n ? null\n : { skyUrl: { invalid: abstractControl.value } };\n };\n }\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
- import { forwardRef, Directive, NgModule } from '@angular/core';
2
+ import { forwardRef, Directive, NgModule, Input } from '@angular/core';
3
3
  import { NG_VALIDATORS, FormsModule } from '@angular/forms';
4
+ import isURL from 'validator/es/lib/isURL';
4
5
 
5
6
  class SkyValidation {
6
7
  static isEmail(emailAddress) {
@@ -10,9 +11,24 @@ class SkyValidation {
10
11
  const regex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
11
12
  return regex.test(emailAddress);
12
13
  }
13
- static isUrl(url) {
14
+ static isUrl(value, options) {
15
+ if (typeof value !== 'string') {
16
+ return false;
17
+ }
18
+ const url = value;
14
19
  const regex = /^((http|https):\/\/)?([\w-]+\.)+[\w-]+/i;
15
- return regex.test(url);
20
+ if (options) {
21
+ switch (options.rulesetVersion) {
22
+ case 1:
23
+ return regex.test(url);
24
+ case 2:
25
+ // we are using the `validator` package's default options
26
+ return isURL(url);
27
+ }
28
+ }
29
+ else {
30
+ return regex.test(url);
31
+ }
16
32
  }
17
33
  }
18
34
 
@@ -83,32 +99,41 @@ const SKY_URL_VALIDATION_VALIDATOR = {
83
99
  * This directive uses `NgModel` to bind data.
84
100
  */
85
101
  class SkyUrlValidationDirective {
102
+ constructor() {
103
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
104
+ this._validatorChange = () => { };
105
+ }
106
+ /**
107
+ * Specifies configuration options for the URL validation component.
108
+ */
109
+ set skyUrlValidation(value) {
110
+ this._skyUrlValidationOptions = value;
111
+ this._validatorChange();
112
+ }
86
113
  validate(control) {
87
114
  const value = control.value;
88
115
  if (!value) {
89
- return;
90
- }
91
- if (!this.urlIsValid(value)) {
92
- return {
93
- skyUrl: {
94
- invalid: control.value,
95
- },
96
- };
116
+ return null;
97
117
  }
118
+ return SkyValidation.isUrl(value, this._skyUrlValidationOptions)
119
+ ? null
120
+ : { skyUrl: { invalid: value } };
98
121
  }
99
- urlIsValid(url) {
100
- return SkyValidation.isUrl(url);
122
+ registerOnValidatorChange(fn) {
123
+ this._validatorChange = fn;
101
124
  }
102
125
  }
103
126
  SkyUrlValidationDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyUrlValidationDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
104
- SkyUrlValidationDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyUrlValidationDirective, selector: "[skyUrlValidation]", providers: [SKY_URL_VALIDATION_VALIDATOR], ngImport: i0 });
127
+ SkyUrlValidationDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyUrlValidationDirective, selector: "[skyUrlValidation]", inputs: { skyUrlValidation: "skyUrlValidation" }, providers: [SKY_URL_VALIDATION_VALIDATOR], ngImport: i0 });
105
128
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SkyUrlValidationDirective, decorators: [{
106
129
  type: Directive,
107
130
  args: [{
108
131
  selector: '[skyUrlValidation]',
109
132
  providers: [SKY_URL_VALIDATION_VALIDATOR],
110
133
  }]
111
- }] });
134
+ }], propDecorators: { skyUrlValidation: [{
135
+ type: Input
136
+ }] } });
112
137
 
113
138
  class SkyUrlValidationModule {
114
139
  }
@@ -132,33 +157,43 @@ class SkyValidators {
132
157
  * Validates email addresses in reactive forms. Add this validator directly to the form control
133
158
  * model in the component class. If users enter values that are not valid email addresses, the
134
159
  * validator throws an error. Since this is a sync validator, it returns a set of validation
135
- * errors or `undefined` immediately when users enter values.
136
- * @param control
160
+ * errors or `null` immediately when users enter values.
137
161
  */
138
162
  static email(control) {
139
163
  const value = control.value;
140
164
  if (!value) {
141
- return undefined;
165
+ return null;
142
166
  }
143
167
  return SkyValidation.isEmail(value)
144
- ? undefined
168
+ ? null
145
169
  : { skyEmail: { invalid: value } };
146
170
  }
147
- /**
148
- * Validates URLs in reactive forms. Add this validator directly to the form control model in
149
- * the component class. If users enter values that are not valid URLs, the validator throws an
150
- * error. Since this is a sync validator, it returns a set of validation errors or `undefined`
151
- * immediately when users enter values.
152
- * @param control
153
- */
154
- static url(control) {
155
- const value = control.value;
156
- if (!value) {
157
- return undefined;
171
+ static url(value) {
172
+ const typeTester = value;
173
+ if (typeTester.rulesetVersion === undefined) {
174
+ // there are no SkyUrlValidationOptions passed in, so return ValidationErrors | null
175
+ const abstractControl = value;
176
+ const abstractControlValue = abstractControl.value;
177
+ if (!abstractControlValue) {
178
+ return null;
179
+ }
180
+ return SkyValidation.isUrl(abstractControlValue)
181
+ ? null
182
+ : { skyUrl: { invalid: abstractControlValue } };
183
+ }
184
+ else {
185
+ // there are SkyUrlValidationOptions passed in, so return ValidatorFn
186
+ const skyUrlValidationOptions = value;
187
+ return (abstractControl) => {
188
+ const abstractControlValue = abstractControl.value;
189
+ if (!abstractControlValue) {
190
+ return null;
191
+ }
192
+ return SkyValidation.isUrl(abstractControl.value, skyUrlValidationOptions)
193
+ ? null
194
+ : { skyUrl: { invalid: abstractControl.value } };
195
+ };
158
196
  }
159
- return SkyValidation.isUrl(value)
160
- ? undefined
161
- : { skyUrl: { invalid: value } };
162
197
  }
163
198
  }
164
199
 
@@ -1 +1 @@
1
- {"version":3,"file":"skyux-validation.js","sources":["../../../../../libs/components/validation/src/lib/modules/validation/validation.ts","../../../../../libs/components/validation/src/lib/modules/email-validation/email-validation.directive.ts","../../../../../libs/components/validation/src/lib/modules/email-validation/email-validation.module.ts","../../../../../libs/components/validation/src/lib/modules/url-validation/url-validation.directive.ts","../../../../../libs/components/validation/src/lib/modules/url-validation/url-validation.module.ts","../../../../../libs/components/validation/src/lib/modules/validators/validators.ts","../../../../../libs/components/validation/src/skyux-validation.ts"],"sourcesContent":["export abstract class SkyValidation {\n public static isEmail(emailAddress: string): boolean {\n // The regex was obtained from http://emailregex.com/\n // which claims to correctly handle ~99% of all email addresses.\n // tslint:disable-next-line:max-line-length\n const regex =\n /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n return regex.test(emailAddress);\n }\n\n public static isUrl(url: string): boolean {\n const regex = /^((http|https):\\/\\/)?([\\w-]+\\.)+[\\w-]+/i;\n return regex.test(url);\n }\n}\n","import { Directive, forwardRef } from '@angular/core';\nimport { AbstractControl, NG_VALIDATORS, Validator } from '@angular/forms';\n\nimport { SkyValidation } from '../validation/validation';\n\n// tslint:disable:no-forward-ref no-use-before-declare\nconst SKY_EMAIL_VALIDATION_VALIDATOR = {\n provide: NG_VALIDATORS,\n useExisting: forwardRef(() => SkyEmailValidationDirective),\n multi: true,\n};\n// tslint:enable\n\n/**\n * Creates an input to validate email addresses. Place this attribute on an `input` element.\n * If users enter values that are not valid email addresses, an error message appears.\n * The directive uses `NgModel` to bind data.\n */\n@Directive({\n selector: '[skyEmailValidation]',\n providers: [SKY_EMAIL_VALIDATION_VALIDATOR],\n})\nexport class SkyEmailValidationDirective implements Validator {\n public validate(control: AbstractControl): { [key: string]: any } {\n const value = control.value;\n\n if (!value) {\n return;\n }\n\n if (!this.emailIsValid(value)) {\n return {\n skyEmail: {\n invalid: control.value,\n },\n };\n }\n }\n\n public emailIsValid(email: string): boolean {\n return SkyValidation.isEmail(email);\n }\n}\n","import { NgModule } from '@angular/core';\nimport { FormsModule } from '@angular/forms';\n\nimport { SkyEmailValidationDirective } from './email-validation.directive';\n\n@NgModule({\n declarations: [SkyEmailValidationDirective],\n imports: [FormsModule],\n exports: [SkyEmailValidationDirective],\n})\nexport class SkyEmailValidationModule {}\n","import { Directive, forwardRef } from '@angular/core';\nimport { AbstractControl, NG_VALIDATORS, Validator } from '@angular/forms';\n\nimport { SkyValidation } from '../validation/validation';\n\n// tslint:disable:no-forward-ref no-use-before-declare\nconst SKY_URL_VALIDATION_VALIDATOR = {\n provide: NG_VALIDATORS,\n useExisting: forwardRef(() => SkyUrlValidationDirective),\n multi: true,\n};\n// tslint:enable\n\n/**\n * Creates an input to validate URLs. Place this attribute on an `input` element.\n * If users enters values that are not valid URLs, an error message appears.\n * This directive uses `NgModel` to bind data.\n */\n@Directive({\n selector: '[skyUrlValidation]',\n providers: [SKY_URL_VALIDATION_VALIDATOR],\n})\nexport class SkyUrlValidationDirective implements Validator {\n public validate(control: AbstractControl): { [key: string]: any } {\n const value = control.value;\n\n if (!value) {\n return;\n }\n\n if (!this.urlIsValid(value)) {\n return {\n skyUrl: {\n invalid: control.value,\n },\n };\n }\n }\n\n public urlIsValid(url: string): boolean {\n return SkyValidation.isUrl(url);\n }\n}\n","import { NgModule } from '@angular/core';\nimport { FormsModule } from '@angular/forms';\n\nimport { SkyUrlValidationDirective } from './url-validation.directive';\n\n@NgModule({\n declarations: [SkyUrlValidationDirective],\n imports: [FormsModule],\n exports: [SkyUrlValidationDirective],\n})\nexport class SkyUrlValidationModule {}\n","import { AbstractControl, ValidationErrors } from '@angular/forms';\n\nimport { SkyValidation } from '../validation/validation';\n\n// Need to add the following to classes which contain static methods.\n// See: https://github.com/ng-packagr/ng-packagr/issues/641\n// @dynamic\nexport class SkyValidators {\n /**\n * Validates email addresses in reactive forms. Add this validator directly to the form control\n * model in the component class. If users enter values that are not valid email addresses, the\n * validator throws an error. Since this is a sync validator, it returns a set of validation\n * errors or `undefined` immediately when users enter values.\n * @param control\n */\n public static email(control: AbstractControl): ValidationErrors | null {\n const value = control.value;\n\n if (!value) {\n return undefined;\n }\n\n return SkyValidation.isEmail(value)\n ? undefined\n : { skyEmail: { invalid: value } };\n }\n\n /**\n * Validates URLs in reactive forms. Add this validator directly to the form control model in\n * the component class. If users enter values that are not valid URLs, the validator throws an\n * error. Since this is a sync validator, it returns a set of validation errors or `undefined`\n * immediately when users enter values.\n * @param control\n */\n public static url(control: AbstractControl): ValidationErrors | null {\n const value = control.value;\n\n if (!value) {\n return undefined;\n }\n\n return SkyValidation.isUrl(value)\n ? undefined\n : { skyUrl: { invalid: value } };\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;MAAsB,aAAa;IAC1B,OAAO,OAAO,CAAC,YAAoB;;;;QAIxC,MAAM,KAAK,GACT,sJAAsJ,CAAC;QACzJ,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KACjC;IAEM,OAAO,KAAK,CAAC,GAAW;QAC7B,MAAM,KAAK,GAAG,yCAAyC,CAAC;QACxD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACxB;;;ACRH;AACA,MAAM,8BAA8B,GAAG;IACrC,OAAO,EAAE,aAAa;IACtB,WAAW,EAAE,UAAU,CAAC,MAAM,2BAA2B,CAAC;IAC1D,KAAK,EAAE,IAAI;CACZ,CAAC;AACF;AAEA;;;;;MASa,2BAA2B;IAC/B,QAAQ,CAAC,OAAwB;QACtC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5B,IAAI,CAAC,KAAK,EAAE;YACV,OAAO;SACR;QAED,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;YAC7B,OAAO;gBACL,QAAQ,EAAE;oBACR,OAAO,EAAE,OAAO,CAAC,KAAK;iBACvB;aACF,CAAC;SACH;KACF;IAEM,YAAY,CAAC,KAAa;QAC/B,OAAO,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;KACrC;;yHAnBU,2BAA2B;6GAA3B,2BAA2B,+CAF3B,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,yBAAyB;qHAExB,sBAAsB,YAHxB,CAAC,WAAW,CAAC;4FAGX,sBAAsB;kBALlC,QAAQ;mBAAC;oBACR,YAAY,EAAE,CAAC,yBAAyB,CAAC;oBACzC,OAAO,EAAE,CAAC,WAAW,CAAC;oBACtB,OAAO,EAAE,CAAC,yBAAyB,CAAC;iBACrC;;;ACLD;AACA;AACA;MACa,aAAa;;;;;;;;IAQjB,OAAO,KAAK,CAAC,OAAwB;QAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5B,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC;cAC/B,SAAS;cACT,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;KACtC;;;;;;;;IASM,OAAO,GAAG,CAAC,OAAwB;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5B,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;cAC7B,SAAS;cACT,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;KACpC;;;AC5CH;;;;;;"}
1
+ {"version":3,"file":"skyux-validation.js","sources":["../../../../../libs/components/validation/src/lib/modules/validation/validation.ts","../../../../../libs/components/validation/src/lib/modules/email-validation/email-validation.directive.ts","../../../../../libs/components/validation/src/lib/modules/email-validation/email-validation.module.ts","../../../../../libs/components/validation/src/lib/modules/url-validation/url-validation.directive.ts","../../../../../libs/components/validation/src/lib/modules/url-validation/url-validation.module.ts","../../../../../libs/components/validation/src/lib/modules/validators/validators.ts","../../../../../libs/components/validation/src/skyux-validation.ts"],"sourcesContent":["import isURL from 'validator/es/lib/isURL';\n\nimport { SkyUrlValidationOptions } from '../url-validation/url-validation-options';\n\nexport abstract class SkyValidation {\n public static isEmail(emailAddress: string): boolean {\n // The regex was obtained from http://emailregex.com/\n // which claims to correctly handle ~99% of all email addresses.\n // tslint:disable-next-line:max-line-length\n const regex =\n /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n return regex.test(emailAddress);\n }\n\n public static isUrl(\n value: unknown,\n options?: SkyUrlValidationOptions\n ): boolean {\n if (typeof value !== 'string') {\n return false;\n }\n\n const url: string = value;\n\n const regex = /^((http|https):\\/\\/)?([\\w-]+\\.)+[\\w-]+/i;\n if (options) {\n switch (options.rulesetVersion) {\n case 1:\n return regex.test(url);\n case 2:\n // we are using the `validator` package's default options\n return isURL(url);\n }\n } else {\n return regex.test(url);\n }\n }\n}\n","import { Directive, forwardRef } from '@angular/core';\nimport { AbstractControl, NG_VALIDATORS, Validator } from '@angular/forms';\n\nimport { SkyValidation } from '../validation/validation';\n\n// tslint:disable:no-forward-ref no-use-before-declare\nconst SKY_EMAIL_VALIDATION_VALIDATOR = {\n provide: NG_VALIDATORS,\n useExisting: forwardRef(() => SkyEmailValidationDirective),\n multi: true,\n};\n// tslint:enable\n\n/**\n * Creates an input to validate email addresses. Place this attribute on an `input` element.\n * If users enter values that are not valid email addresses, an error message appears.\n * The directive uses `NgModel` to bind data.\n */\n@Directive({\n selector: '[skyEmailValidation]',\n providers: [SKY_EMAIL_VALIDATION_VALIDATOR],\n})\nexport class SkyEmailValidationDirective implements Validator {\n public validate(control: AbstractControl): { [key: string]: any } {\n const value = control.value;\n\n if (!value) {\n return;\n }\n\n if (!this.emailIsValid(value)) {\n return {\n skyEmail: {\n invalid: control.value,\n },\n };\n }\n }\n\n public emailIsValid(email: string): boolean {\n return SkyValidation.isEmail(email);\n }\n}\n","import { NgModule } from '@angular/core';\nimport { FormsModule } from '@angular/forms';\n\nimport { SkyEmailValidationDirective } from './email-validation.directive';\n\n@NgModule({\n declarations: [SkyEmailValidationDirective],\n imports: [FormsModule],\n exports: [SkyEmailValidationDirective],\n})\nexport class SkyEmailValidationModule {}\n","import { Directive, Input, forwardRef } from '@angular/core';\nimport {\n AbstractControl,\n NG_VALIDATORS,\n ValidationErrors,\n Validator,\n} from '@angular/forms';\n\nimport { SkyValidation } from '../validation/validation';\n\nimport { SkyUrlValidationOptions } from './url-validation-options';\n\n// tslint:disable:no-forward-ref no-use-before-declare\nconst SKY_URL_VALIDATION_VALIDATOR = {\n provide: NG_VALIDATORS,\n useExisting: forwardRef(() => SkyUrlValidationDirective),\n multi: true,\n};\n// tslint:enable\n\n/**\n * Creates an input to validate URLs. Place this attribute on an `input` element.\n * If users enters values that are not valid URLs, an error message appears.\n * This directive uses `NgModel` to bind data.\n */\n@Directive({\n selector: '[skyUrlValidation]',\n providers: [SKY_URL_VALIDATION_VALIDATOR],\n})\nexport class SkyUrlValidationDirective implements Validator {\n /**\n * Specifies configuration options for the URL validation component.\n */\n @Input()\n public set skyUrlValidation(value: SkyUrlValidationOptions | undefined) {\n this._skyUrlValidationOptions = value;\n this._validatorChange();\n }\n\n private _skyUrlValidationOptions: SkyUrlValidationOptions | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n private _validatorChange = () => {};\n\n public validate(control: AbstractControl): ValidationErrors | null {\n const value = control.value;\n\n if (!value) {\n return null;\n }\n\n return SkyValidation.isUrl(value, this._skyUrlValidationOptions)\n ? null\n : { skyUrl: { invalid: value } };\n }\n\n public registerOnValidatorChange(fn: () => void): void {\n this._validatorChange = fn;\n }\n}\n","import { NgModule } from '@angular/core';\nimport { FormsModule } from '@angular/forms';\n\nimport { SkyUrlValidationDirective } from './url-validation.directive';\n\n@NgModule({\n declarations: [SkyUrlValidationDirective],\n imports: [FormsModule],\n exports: [SkyUrlValidationDirective],\n})\nexport class SkyUrlValidationModule {}\n","import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';\n\nimport { SkyUrlValidationOptions } from '../url-validation/url-validation-options';\nimport { SkyValidation } from '../validation/validation';\n\n// Need to add the following to classes which contain static methods.\n// See: https://github.com/ng-packagr/ng-packagr/issues/641\n// @dynamic\nexport class SkyValidators {\n /**\n * Validates email addresses in reactive forms. Add this validator directly to the form control\n * model in the component class. If users enter values that are not valid email addresses, the\n * validator throws an error. Since this is a sync validator, it returns a set of validation\n * errors or `null` immediately when users enter values.\n */\n public static email(control: AbstractControl): ValidationErrors | null {\n const value = control.value;\n\n if (!value) {\n return null;\n }\n\n return SkyValidation.isEmail(value)\n ? null\n : { skyEmail: { invalid: value } };\n }\n\n /**\n * Validates URLs in reactive forms. Add this validator directly to the form control model in\n * the component class. If users enter values that are not valid URLs, the validator throws an\n * error. Since this is a sync validator, it returns a set of validation errors or `null`\n * immediately when users enter values.\n */\n public static url(abstractControl: AbstractControl): ValidationErrors | null;\n\n /**\n * Validates URLs in reactive forms. Add this validator with ruleset parameters directly to\n * the form control model in the component class. If users enter values that are not valid\n * URLs, the validator throws an error. Since this is a sync validator, it returns a set of\n * validation errors or `null` immediately when users enter values.\n */\n public static url(\n skyUrlValidationOptions: SkyUrlValidationOptions\n ): ValidatorFn | null;\n\n public static url(\n value: AbstractControl | SkyUrlValidationOptions\n ): ValidatorFn | ValidationErrors | null {\n const typeTester = value as SkyUrlValidationOptions;\n if (typeTester.rulesetVersion === undefined) {\n // there are no SkyUrlValidationOptions passed in, so return ValidationErrors | null\n const abstractControl = value as AbstractControl;\n const abstractControlValue = abstractControl.value;\n if (!abstractControlValue) {\n return null;\n }\n return SkyValidation.isUrl(abstractControlValue)\n ? null\n : { skyUrl: { invalid: abstractControlValue } };\n } else {\n // there are SkyUrlValidationOptions passed in, so return ValidatorFn\n const skyUrlValidationOptions = value as SkyUrlValidationOptions;\n return (abstractControl: AbstractControl): ValidationErrors | null => {\n const abstractControlValue = abstractControl.value;\n if (!abstractControlValue) {\n return null;\n }\n\n return SkyValidation.isUrl(\n abstractControl.value,\n skyUrlValidationOptions\n )\n ? null\n : { skyUrl: { invalid: abstractControl.value } };\n };\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;MAIsB,aAAa;IAC1B,OAAO,OAAO,CAAC,YAAoB;;;;QAIxC,MAAM,KAAK,GACT,sJAAsJ,CAAC;QACzJ,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KACjC;IAEM,OAAO,KAAK,CACjB,KAAc,EACd,OAAiC;QAEjC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,KAAK,CAAC;SACd;QAED,MAAM,GAAG,GAAW,KAAK,CAAC;QAE1B,MAAM,KAAK,GAAG,yCAAyC,CAAC;QACxD,IAAI,OAAO,EAAE;YACX,QAAQ,OAAO,CAAC,cAAc;gBAC5B,KAAK,CAAC;oBACJ,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACzB,KAAK,CAAC;;oBAEJ,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;aACrB;SACF;aAAM;YACL,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACxB;KACF;;;AC/BH;AACA,MAAM,8BAA8B,GAAG;IACrC,OAAO,EAAE,aAAa;IACtB,WAAW,EAAE,UAAU,CAAC,MAAM,2BAA2B,CAAC;IAC1D,KAAK,EAAE,IAAI;CACZ,CAAC;AACF;AAEA;;;;;MASa,2BAA2B;IAC/B,QAAQ,CAAC,OAAwB;QACtC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5B,IAAI,CAAC,KAAK,EAAE;YACV,OAAO;SACR;QAED,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;YAC7B,OAAO;gBACL,QAAQ,EAAE;oBACR,OAAO,EAAE,OAAO,CAAC,KAAK;iBACvB;aACF,CAAC;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EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,CAAC;SACnD;aAAM;;YAEL,MAAM,uBAAuB,GAAG,KAAgC,CAAC;YACjE,OAAO,CAAC,eAAgC;gBACtC,MAAM,oBAAoB,GAAG,eAAe,CAAC,KAAK,CAAC;gBACnD,IAAI,CAAC,oBAAoB,EAAE;oBACzB,OAAO,IAAI,CAAC;iBACb;gBAED,OAAO,aAAa,CAAC,KAAK,CACxB,eAAe,CAAC,KAAK,EACrB,uBAAuB,CACxB;sBACG,IAAI;sBACJ,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,eAAe,CAAC,KAAK,EAAE,EAAE,CAAC;aACpD,CAAC;SACH;KACF;;;AC5EH;;;;;;"}
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './lib/modules/email-validation/email-validation.module';
2
+ export * from './lib/modules/url-validation/url-validation-options';
2
3
  export * from './lib/modules/url-validation/url-validation.module';
3
4
  export * from './lib/modules/validation/validation';
4
5
  export * from './lib/modules/validators/validators';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Specifies options for the URL validator component.
3
+ */
4
+ export interface SkyUrlValidationOptions {
5
+ /**
6
+ * Indicates the ruleset to use for URL validation. Ruleset 1 uses a regular expression and ruleset 2 uses the third-party [validator.js library](https://github.com/validatorjs/validator.js/).
7
+ */
8
+ rulesetVersion: 1 | 2;
9
+ }
@@ -1,4 +1,5 @@
1
- import { AbstractControl, Validator } from '@angular/forms';
1
+ import { AbstractControl, ValidationErrors, Validator } from '@angular/forms';
2
+ import { SkyUrlValidationOptions } from './url-validation-options';
2
3
  import * as i0 from "@angular/core";
3
4
  /**
4
5
  * Creates an input to validate URLs. Place this attribute on an `input` element.
@@ -6,10 +7,14 @@ import * as i0 from "@angular/core";
6
7
  * This directive uses `NgModel` to bind data.
7
8
  */
8
9
  export declare class SkyUrlValidationDirective implements Validator {
9
- validate(control: AbstractControl): {
10
- [key: string]: any;
11
- };
12
- urlIsValid(url: string): boolean;
10
+ /**
11
+ * Specifies configuration options for the URL validation component.
12
+ */
13
+ set skyUrlValidation(value: SkyUrlValidationOptions | undefined);
14
+ private _skyUrlValidationOptions;
15
+ private _validatorChange;
16
+ validate(control: AbstractControl): ValidationErrors | null;
17
+ registerOnValidatorChange(fn: () => void): void;
13
18
  static ɵfac: i0.ɵɵFactoryDeclaration<SkyUrlValidationDirective, never>;
14
- static ɵdir: i0.ɵɵDirectiveDeclaration<SkyUrlValidationDirective, "[skyUrlValidation]", never, {}, {}, never>;
19
+ static ɵdir: i0.ɵɵDirectiveDeclaration<SkyUrlValidationDirective, "[skyUrlValidation]", never, { "skyUrlValidation": "skyUrlValidation"; }, {}, never>;
15
20
  }
@@ -1,4 +1,5 @@
1
+ import { SkyUrlValidationOptions } from '../url-validation/url-validation-options';
1
2
  export declare abstract class SkyValidation {
2
3
  static isEmail(emailAddress: string): boolean;
3
- static isUrl(url: string): boolean;
4
+ static isUrl(value: unknown, options?: SkyUrlValidationOptions): boolean;
4
5
  }
@@ -1,19 +1,25 @@
1
- import { AbstractControl, ValidationErrors } from '@angular/forms';
1
+ import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';
2
+ import { SkyUrlValidationOptions } from '../url-validation/url-validation-options';
2
3
  export declare class SkyValidators {
3
4
  /**
4
5
  * Validates email addresses in reactive forms. Add this validator directly to the form control
5
6
  * model in the component class. If users enter values that are not valid email addresses, the
6
7
  * validator throws an error. Since this is a sync validator, it returns a set of validation
7
- * errors or `undefined` immediately when users enter values.
8
- * @param control
8
+ * errors or `null` immediately when users enter values.
9
9
  */
10
10
  static email(control: AbstractControl): ValidationErrors | null;
11
11
  /**
12
12
  * Validates URLs in reactive forms. Add this validator directly to the form control model in
13
13
  * the component class. If users enter values that are not valid URLs, the validator throws an
14
- * error. Since this is a sync validator, it returns a set of validation errors or `undefined`
14
+ * error. Since this is a sync validator, it returns a set of validation errors or `null`
15
15
  * immediately when users enter values.
16
- * @param control
17
16
  */
18
- static url(control: AbstractControl): ValidationErrors | null;
17
+ static url(abstractControl: AbstractControl): ValidationErrors | null;
18
+ /**
19
+ * Validates URLs in reactive forms. Add this validator with ruleset parameters directly to
20
+ * the form control model in the component class. If users enter values that are not valid
21
+ * URLs, the validator throws an error. Since this is a sync validator, it returns a set of
22
+ * validation errors or `null` immediately when users enter values.
23
+ */
24
+ static url(skyUrlValidationOptions: SkyUrlValidationOptions): ValidatorFn | null;
19
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyux/validation",
3
- "version": "5.9.7",
3
+ "version": "5.11.1",
4
4
  "author": "Blackbaud, Inc.",
5
5
  "keywords": [
6
6
  "blackbaud",
@@ -21,7 +21,8 @@
21
21
  "@angular/forms": "^12.2.16"
22
22
  },
23
23
  "dependencies": {
24
- "tslib": "^2.3.1"
24
+ "tslib": "^2.3.1",
25
+ "validator": "13.7.0"
25
26
  },
26
27
  "main": "bundles/skyux-validation.umd.js",
27
28
  "module": "fesm2015/skyux-validation.js",