{"version":3,"file":"ngxtension-not-pattern.mjs","sources":["../../../../libs/ngxtension/not-pattern/src/not-pattern.ts","../../../../libs/ngxtension/not-pattern/src/ngxtension-not-pattern.ts"],"sourcesContent":["import {\n\tAbstractControl,\n\tValidationErrors,\n\tValidatorFn,\n\tValidators,\n} from '@angular/forms';\n\n/**\n * @description\n * Validator that performs pattern matching against a string input that should NOT match the pattern.\n * Opposite of Angular's built-in pattern validator.\n *\n * @usageNotes\n *\n * ```typescript\n * const control = new FormControl('abc', notPattern(/[0-9]/));\n * console.log(control.errors); // null - valid because 'abc' does not contain numbers\n *\n * const control2 = new FormControl('abc123', notPattern(/[0-9]/));\n * console.log(control2.errors); // {notPattern: {requiredPattern: '/[0-9]/', actual: 'abc123'}} - invalid because it contains numbers\n * ```\n *\n * @param pattern A regular expression or string to match against\n * @returns A validator function that returns an error map with the `notPattern` property\n * if the validation check fails, otherwise `null`.\n */\nexport function notPattern(pattern: string | RegExp): ValidatorFn {\n\tif (!pattern) return Validators.nullValidator;\n\tlet regex: RegExp;\n\tlet regexStr: string;\n\tif (typeof pattern === 'string') {\n\t\tregexStr = '';\n\n\t\tif (pattern.charAt(0) !== '^') regexStr += '^';\n\n\t\tregexStr += pattern;\n\n\t\tif (pattern.charAt(pattern.length - 1) !== '$') regexStr += '$';\n\n\t\tregex = new RegExp(regexStr);\n\t} else {\n\t\tregexStr = pattern.toString();\n\t\tregex = pattern;\n\t}\n\treturn (control: AbstractControl): ValidationErrors | null => {\n\t\tif (isEmptyInputValue(control.value)) {\n\t\t\treturn null; // don't validate empty values to allow optional controls\n\t\t}\n\t\tconst value: string = control.value;\n\t\tconsole.log('value', value, 'regex', regex);\n\t\treturn regex.test(value)\n\t\t\t? { notPattern: { disallowedPattern: regexStr, actualValue: value } }\n\t\t\t: null;\n\t};\n}\n\nfunction isEmptyInputValue(value: unknown): boolean {\n\treturn value == null || lengthOrSize(value) === 0;\n}\n\n/**\n * Extract the length property in case it's an array or a string.\n * Extract the size property in case it's a set.\n * Return null else.\n * @param value Either an array, set or undefined.\n */\nfunction lengthOrSize(value: unknown): number | null {\n\t// non-strict comparison is intentional, to check for both `null` and `undefined` values\n\tif (value == null) {\n\t\treturn null;\n\t} else if (Array.isArray(value) || typeof value === 'string') {\n\t\treturn value.length;\n\t} else if (value instanceof Set) {\n\t\treturn value.size;\n\t}\n\n\treturn null;\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAOA;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,UAAU,CAAC,OAAwB,EAAA;AAClD,IAAA,IAAI,CAAC,OAAO;QAAE,OAAO,UAAU,CAAC,aAAa,CAAC;AAC9C,IAAA,IAAI,KAAa,CAAC;AAClB,IAAA,IAAI,QAAgB,CAAC;AACrB,IAAA,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAChC,QAAQ,GAAG,EAAE,CAAC;AAEd,QAAA,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG;YAAE,QAAQ,IAAI,GAAG,CAAC;QAE/C,QAAQ,IAAI,OAAO,CAAC;QAEpB,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;YAAE,QAAQ,IAAI,GAAG,CAAC;AAEhE,QAAA,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;KAC7B;SAAM;AACN,QAAA,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC9B,KAAK,GAAG,OAAO,CAAC;KAChB;IACD,OAAO,CAAC,OAAwB,KAA6B;AAC5D,QAAA,IAAI,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACrC,OAAO,IAAI,CAAC;SACZ;AACD,QAAA,MAAM,KAAK,GAAW,OAAO,CAAC,KAAK,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KA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