@rxap/forms 12.5.1-alpha.0 → 12.5.1-next.3

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.
@@ -10,6 +10,7 @@ import { IsComplex } from './is-complex';
10
10
  import { IsPhoneNumber } from './is-phone-number';
11
11
  import { IsEmail } from './is-email';
12
12
  import { IsUrl } from './is-url';
13
+ import { IsIP } from './is-ip';
13
14
  export const RxapValidators = {
14
15
  IsNumber,
15
16
  IsBoolean,
@@ -22,6 +23,7 @@ export const RxapValidators = {
22
23
  IsComplex,
23
24
  IsPhoneNumber,
24
25
  IsEmail,
25
- IsUrl
26
+ IsUrl,
27
+ IsIP
26
28
  };
27
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/forms/src/lib/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,QAAQ;IACR,SAAS;IACT,OAAO;IACP,MAAM;IACN,MAAM;IACN,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,aAAa;IACb,OAAO;IACP,KAAK;CACN,CAAC","sourcesContent":["import { _IsNumber as IsNumber } from './is-number';\nimport { IsBoolean } from './is-boolean';\nimport { IsObject } from './is-object';\nimport { IsString } from './is-string';\nimport { IsInt } from './is-int';\nimport { IsEnum } from './is-enum';\nimport { IsDate } from './is-date';\nimport { IsArray } from './is-array';\nimport { IsComplex } from './is-complex';\nimport { IsPhoneNumber } from './is-phone-number';\nimport { IsEmail } from './is-email';\nimport { IsUrl } from './is-url';\n\nexport const RxapValidators = {\n IsNumber,\n IsBoolean,\n IsArray,\n IsDate,\n IsEnum,\n IsInt,\n IsObject,\n IsString,\n IsComplex,\n IsPhoneNumber,\n IsEmail,\n IsUrl\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/forms/src/lib/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,QAAQ;IACR,SAAS;IACT,OAAO;IACP,MAAM;IACN,MAAM;IACN,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,aAAa;IACb,OAAO;IACP,KAAK;IACL,IAAI;CACL,CAAC","sourcesContent":["import { _IsNumber as IsNumber } from './is-number';\nimport { IsBoolean } from './is-boolean';\nimport { IsObject } from './is-object';\nimport { IsString } from './is-string';\nimport { IsInt } from './is-int';\nimport { IsEnum } from './is-enum';\nimport { IsDate } from './is-date';\nimport { IsArray } from './is-array';\nimport { IsComplex } from './is-complex';\nimport { IsPhoneNumber } from './is-phone-number';\nimport { IsEmail } from './is-email';\nimport { IsUrl } from './is-url';\nimport { IsIP } from './is-ip';\n\nexport const RxapValidators = {\n IsNumber,\n IsBoolean,\n IsArray,\n IsDate,\n IsEnum,\n IsInt,\n IsObject,\n IsString,\n IsComplex,\n IsPhoneNumber,\n IsEmail,\n IsUrl,\n IsIP\n};\n"]}
@@ -0,0 +1,19 @@
1
+ import { isIP } from '@rxap/validator';
2
+ export function IsIP({ message, version } = {}) {
3
+ return (control) => {
4
+ if (control.value === null) {
5
+ return null;
6
+ }
7
+ if (!(typeof control.value === 'string' && isIP(control.value, version))) {
8
+ return {
9
+ isIp: {
10
+ expected: `A valid IPv${version !== null && version !== void 0 ? version : '4'} value`,
11
+ actual: control.value,
12
+ message
13
+ }
14
+ };
15
+ }
16
+ return null;
17
+ };
18
+ }
19
+ //# sourceMappingURL=is-ip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-ip.js","sourceRoot":"","sources":["../../../../../../libs/forms/src/lib/validators/is-ip.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,MAAM,UAAU,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,KAAsD,EAAE;IAC7F,OAAO,CAAC,OAAwB,EAA2B,EAAE;QAC3D,IAAI,OAAO,CAAC,KAAK,KAAK,IAAI,EAAE;YAC1B,OAAO,IAAI,CAAC;SACb;QACD,IAAI,CAAC,CAAC,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE;YACxE,OAAO;gBACL,IAAI,EAAE;oBACJ,QAAQ,EAAE,cAAc,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,GAAG,QAAQ;oBAC9C,MAAM,EAAI,OAAO,CAAC,KAAK;oBACvB,OAAO;iBACR;aACF,CAAC;SACH;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n AbstractControl,\n ValidationErrors\n} from '@angular/forms';\nimport { isIP } from '@rxap/validator';\n\nexport function IsIP({ message, version }: { message?: string, version?: string | number } = {}) {\n return (control: AbstractControl): ValidationErrors | null => {\n if (control.value === null) {\n return null;\n }\n if (!(typeof control.value === 'string' && isIP(control.value, version))) {\n return {\n isIp: {\n expected: `A valid IPv${version ?? '4'} value`,\n actual: control.value,\n message\n }\n };\n }\n return null;\n };\n}\n"]}
@@ -42,7 +42,7 @@ export function _IsNumber({ message, options } = {}) {
42
42
  if (control.value === null) {
43
43
  return null;
44
44
  }
45
- if (!isNumber(control.value, options)) {
45
+ if (!isNumber(!(options === null || options === void 0 ? void 0 : options.strict) && typeof control.value === 'string' ? Number(control.value) : control.value, options)) {
46
46
  return {
47
47
  isNumber: {
48
48
  expected: 'A number value',
@@ -1 +1 @@
1
- {"version":3,"file":"is-number.js","sourceRoot":"","sources":["../../../../../../libs/forms/src/lib/validators/is-number.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc,EAAE,UAA2B,EAAE;;IACpE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IAED,IAAI,KAAK,KAAK,QAAQ,IAAI,KAA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ACL,QAAQ,EAAE;oBACR,QAAQ,EAAE,gBAAgB;oBAC1B,MAAM,EAAI,OAAO,CAAC,KAAK;oBACvB,OAAO;iBACR;aACF,CAAC;SACH;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n AbstractControl,\n ValidationErrors\n} from '@angular/forms';\n\n/**\n * Options to be passed to IsNumber decorator.\n */\nexport interface IsNumberOptions {\n allowNaN?: boolean;\n allowInfinity?: boolean;\n maxDecimalPlaces?: number;\n}\n\n/**\n * Checks if a given value is a number.\n */\nexport function isNumber(value: unknown, options: IsNumberOptions = {}): value is number {\n if (typeof value !== 'number') {\n return false;\n }\n\n if (value === Infinity || value === -Infinity) {\n return options.allowInfinity ?? false;\n }\n\n if (Number.isNaN(value)) {\n return options.allowNaN ?? false;\n }\n\n if (options.maxDecimalPlaces !== undefined) {\n let decimalPlaces = 0;\n if (value % 1 !== 0) {\n decimalPlaces = value.toString().split('.')[ 1 ].length;\n }\n if (decimalPlaces > options.maxDecimalPlaces) {\n return false;\n }\n }\n\n return Number.isFinite(value);\n}\n\n/**\n * @deprecated use RxapValidators.isNumber() instead\n * @param control\n * @constructor\n */\nexport function IsNumber(control: AbstractControl): ValidationErrors | null {\n if (control.value === null) {\n return null;\n }\n if (isNaN(Number(control.value))) {\n return { isNumber: { expected: 'A number or a string representing a number', actual: control.value } };\n }\n return null;\n}\n\nexport function _IsNumber({ message, options }: { message?: string, options?: IsNumberOptions } = {}) {\n return (control: AbstractControl): ValidationErrors | null => {\n if (control.value === null) {\n return null;\n }\n if (!isNumber(control.value, options)) {\n return {\n isNumber: {\n expected: 'A number value',\n actual: control.value,\n message\n }\n };\n }\n return null;\n };\n}\n"]}
1
+ {"version":3,"file":"is-number.js","sourceRoot":"","sources":["../../../../../../libs/forms/src/lib/validators/is-number.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc,EAAE,UAA2B,EAAE;;IACpE,I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O,IAAI,CAAC;SACb;QACD,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAA,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE;YACrH,OAAO;gBACL,QAAQ,EAAE;oBACR,QAAQ,EAAE,gBAAgB;oBAC1B,MAAM,EAAI,OAAO,CAAC,KAAK;oBACvB,OAAO;iBACR;aACF,CAAC;SACH;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n AbstractControl,\n ValidationErrors\n} from '@angular/forms';\n\n/**\n * Options to be passed to IsNumber decorator.\n */\nexport interface IsNumberOptions {\n allowNaN?: boolean;\n allowInfinity?: boolean;\n maxDecimalPlaces?: number;\n strict?: boolean;\n}\n\n/**\n * Checks if a given value is a number.\n */\nexport function isNumber(value: unknown, options: IsNumberOptions = {}): value is number {\n if (typeof value !== 'number') {\n return false;\n }\n\n if (value === Infinity || value === -Infinity) {\n return options.allowInfinity ?? false;\n }\n\n if (Number.isNaN(value)) {\n return options.allowNaN ?? false;\n }\n\n if (options.maxDecimalPlaces !== undefined) {\n let decimalPlaces = 0;\n if (value % 1 !== 0) {\n decimalPlaces = value.toString().split('.')[ 1 ].length;\n }\n if (decimalPlaces > options.maxDecimalPlaces) {\n return false;\n }\n }\n\n return Number.isFinite(value);\n}\n\n/**\n * @deprecated use RxapValidators.isNumber() instead\n * @param control\n * @constructor\n */\nexport function IsNumber(control: AbstractControl): ValidationErrors | null {\n if (control.value === null) {\n return null;\n }\n if (isNaN(Number(control.value))) {\n return { isNumber: { expected: 'A number or a string representing a number', actual: control.value } };\n }\n return null;\n}\n\nexport function _IsNumber({ message, options }: { message?: string, options?: IsNumberOptions } = {}) {\n return (control: AbstractControl): ValidationErrors | null => {\n if (control.value === null) {\n return null;\n }\n if (!isNumber(!options?.strict && typeof control.value === 'string' ? Number(control.value) : control.value, options)) {\n return {\n isNumber: {\n expected: 'A number value',\n actual: control.value,\n message\n }\n };\n }\n return null;\n };\n}\n"]}
@@ -14,7 +14,7 @@ import { ToggleSubject } from '@rxap/utilities/rxjs';
14
14
  import * as i2$1 from '@angular/router';
15
15
  import { Router } from '@angular/router';
16
16
  import { ConfirmClick } from '@rxap/directives';
17
- import { isMobilePhone, isEmail, isURL } from '@rxap/validator';
17
+ import { isMobilePhone, isEmail, isURL, isIP } from '@rxap/validator';
18
18
 
19
19
  function getControlValue(control) {
20
20
  if (control.getRawValue) {
@@ -2258,7 +2258,7 @@ function _IsNumber({ message, options } = {}) {
2258
2258
  if (control.value === null) {
2259
2259
  return null;
2260
2260
  }
2261
- if (!isNumber(control.value, options)) {
2261
+ if (!isNumber(!(options === null || options === void 0 ? void 0 : options.strict) && typeof control.value === 'string' ? Number(control.value) : control.value, options)) {
2262
2262
  return {
2263
2263
  isNumber: {
2264
2264
  expected: 'A number value',
@@ -2536,6 +2536,24 @@ function IsUrl({ message, options } = {}) {
2536
2536
  };
2537
2537
  }
2538
2538
 
2539
+ function IsIP({ message, version } = {}) {
2540
+ return (control) => {
2541
+ if (control.value === null) {
2542
+ return null;
2543
+ }
2544
+ if (!(typeof control.value === 'string' && isIP(control.value, version))) {
2545
+ return {
2546
+ isIp: {
2547
+ expected: `A valid IPv${version !== null && version !== void 0 ? version : '4'} value`,
2548
+ actual: control.value,
2549
+ message
2550
+ }
2551
+ };
2552
+ }
2553
+ return null;
2554
+ };
2555
+ }
2556
+
2539
2557
  const RxapValidators = {
2540
2558
  IsNumber: _IsNumber,
2541
2559
  IsBoolean,
@@ -2548,7 +2566,8 @@ const RxapValidators = {
2548
2566
  IsComplex,
2549
2567
  IsPhoneNumber,
2550
2568
  IsEmail,
2551
- IsUrl
2569
+ IsUrl,
2570
+ IsIP
2552
2571
  };
2553
2572
 
2554
2573
  // endregion