@skyux/validation 5.9.6 → 5.11.2

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,8 +1,10 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms')) :
3
- typeof define === 'function' && define.amd ? define('@skyux/validation', ['exports', '@angular/core', '@angular/forms'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.skyux = global.skyux || {}, global.skyux.validation = {}), global.ng.core, global.ng.forms));
5
- })(this, (function (exports, i0, forms) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('validator/es/lib/isURL')) :
3
+ typeof define === 'function' && define.amd ? define('@skyux/validation', ['exports', '@angular/core', '@angular/forms', 'validator/es/lib/isURL'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.skyux = global.skyux || {}, global.skyux.validation = {}), global.ng.core, global.ng.forms, global.isURL));
5
+ })(this, (function (exports, i0, forms, isURL) { 'use strict';
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
6
8
 
7
9
  function _interopNamespace(e) {
8
10
  if (e && e.__esModule) return e;
@@ -23,6 +25,7 @@
23
25
  }
24
26
 
25
27
  var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28
+ var isURL__default = /*#__PURE__*/_interopDefaultLegacy(isURL);
26
29
 
27
30
  var SkyValidation = /** @class */ (function () {
28
31
  function SkyValidation() {
@@ -34,9 +37,24 @@
34
37
  var 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,}))$/;
35
38
  return regex.test(emailAddress);
36
39
  };
37
- SkyValidation.isUrl = function (url) {
40
+ SkyValidation.isUrl = function (value, options) {
41
+ if (typeof value !== 'string') {
42
+ return false;
43
+ }
44
+ var url = value;
38
45
  var regex = /^((http|https):\/\/)?([\w-]+\.)+[\w-]+/i;
39
- return regex.test(url);
46
+ if (options) {
47
+ switch (options.rulesetVersion) {
48
+ case 1:
49
+ return regex.test(url);
50
+ case 2:
51
+ // we are using the `validator` package's default options
52
+ return isURL__default["default"](url);
53
+ }
54
+ }
55
+ else {
56
+ return regex.test(url);
57
+ }
40
58
  };
41
59
  return SkyValidation;
42
60
  }());
@@ -115,34 +133,45 @@
115
133
  */
116
134
  var SkyUrlValidationDirective = /** @class */ (function () {
117
135
  function SkyUrlValidationDirective() {
136
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
137
+ this._validatorChange = function () { };
118
138
  }
139
+ Object.defineProperty(SkyUrlValidationDirective.prototype, "skyUrlValidation", {
140
+ /**
141
+ * Specifies configuration options for the URL validation component.
142
+ */
143
+ set: function (value) {
144
+ this._skyUrlValidationOptions = value;
145
+ this._validatorChange();
146
+ },
147
+ enumerable: false,
148
+ configurable: true
149
+ });
119
150
  SkyUrlValidationDirective.prototype.validate = function (control) {
120
151
  var value = control.value;
121
152
  if (!value) {
122
- return;
123
- }
124
- if (!this.urlIsValid(value)) {
125
- return {
126
- skyUrl: {
127
- invalid: control.value,
128
- },
129
- };
153
+ return null;
130
154
  }
155
+ return SkyValidation.isUrl(value, this._skyUrlValidationOptions)
156
+ ? null
157
+ : { skyUrl: { invalid: value } };
131
158
  };
132
- SkyUrlValidationDirective.prototype.urlIsValid = function (url) {
133
- return SkyValidation.isUrl(url);
159
+ SkyUrlValidationDirective.prototype.registerOnValidatorChange = function (fn) {
160
+ this._validatorChange = fn;
134
161
  };
135
162
  return SkyUrlValidationDirective;
136
163
  }());
137
164
  SkyUrlValidationDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyUrlValidationDirective, deps: [], target: i0__namespace.ɵɵFactoryTarget.Directive });
138
- SkyUrlValidationDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyUrlValidationDirective, selector: "[skyUrlValidation]", providers: [SKY_URL_VALIDATION_VALIDATOR], ngImport: i0__namespace });
165
+ SkyUrlValidationDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: SkyUrlValidationDirective, selector: "[skyUrlValidation]", inputs: { skyUrlValidation: "skyUrlValidation" }, providers: [SKY_URL_VALIDATION_VALIDATOR], ngImport: i0__namespace });
139
166
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyUrlValidationDirective, decorators: [{
140
167
  type: i0.Directive,
141
168
  args: [{
142
169
  selector: '[skyUrlValidation]',
143
170
  providers: [SKY_URL_VALIDATION_VALIDATOR],
144
171
  }]
145
- }] });
172
+ }], propDecorators: { skyUrlValidation: [{
173
+ type: i0.Input
174
+ }] } });
146
175
 
147
176
  var SkyUrlValidationModule = /** @class */ (function () {
148
177
  function SkyUrlValidationModule() {
@@ -171,33 +200,43 @@
171
200
  * Validates email addresses in reactive forms. Add this validator directly to the form control
172
201
  * model in the component class. If users enter values that are not valid email addresses, the
173
202
  * validator throws an error. Since this is a sync validator, it returns a set of validation
174
- * errors or `undefined` immediately when users enter values.
175
- * @param control
203
+ * errors or `null` immediately when users enter values.
176
204
  */
177
205
  SkyValidators.email = function (control) {
178
206
  var value = control.value;
179
207
  if (!value) {
180
- return undefined;
208
+ return null;
181
209
  }
182
210
  return SkyValidation.isEmail(value)
183
- ? undefined
211
+ ? null
184
212
  : { skyEmail: { invalid: value } };
185
213
  };
186
- /**
187
- * Validates URLs in reactive forms. Add this validator directly to the form control model in
188
- * the component class. If users enter values that are not valid URLs, the validator throws an
189
- * error. Since this is a sync validator, it returns a set of validation errors or `undefined`
190
- * immediately when users enter values.
191
- * @param control
192
- */
193
- SkyValidators.url = function (control) {
194
- var value = control.value;
195
- if (!value) {
196
- return undefined;
214
+ SkyValidators.url = function (value) {
215
+ var typeTester = value;
216
+ if (typeTester.rulesetVersion === undefined) {
217
+ // there are no SkyUrlValidationOptions passed in, so return ValidationErrors | null
218
+ var abstractControl = value;
219
+ var abstractControlValue = abstractControl.value;
220
+ if (!abstractControlValue) {
221
+ return null;
222
+ }
223
+ return SkyValidation.isUrl(abstractControlValue)
224
+ ? null
225
+ : { skyUrl: { invalid: abstractControlValue } };
226
+ }
227
+ else {
228
+ // there are SkyUrlValidationOptions passed in, so return ValidatorFn
229
+ var skyUrlValidationOptions_1 = value;
230
+ return function (abstractControl) {
231
+ var abstractControlValue = abstractControl.value;
232
+ if (!abstractControlValue) {
233
+ return null;
234
+ }
235
+ return SkyValidation.isUrl(abstractControl.value, skyUrlValidationOptions_1)
236
+ ? null
237
+ : { skyUrl: { invalid: abstractControl.value } };
238
+ };
197
239
  }
198
- return SkyValidation.isUrl(value)
199
- ? undefined
200
- : { skyUrl: { invalid: value } };
201
240
  };
202
241
  return SkyValidators;
203
242
  }());