ngx-mask
Version:
awesome ngx mask
1 lines • 141 kB
Source Map (JSON)
{"version":3,"file":"ngx-mask.umd.js","sources":["../../../projects/ngx-mask-lib/src/lib/config.ts","../../../node_modules/tslib/tslib.es6.js","../../../projects/ngx-mask-lib/src/lib/mask-applier.service.ts","../../../projects/ngx-mask-lib/src/lib/mask.service.ts","../../../projects/ngx-mask-lib/src/lib/mask.directive.ts","../../../projects/ngx-mask-lib/src/lib/mask.pipe.ts","../../../projects/ngx-mask-lib/src/lib/ngx-mask.module.ts","../../../projects/ngx-mask-lib/src/lib/custom-keyboard-event.ts","../../../projects/ngx-mask-lib/src/ngx-mask.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nexport interface IConfig {\n suffix: string;\n prefix: string;\n thousandSeparator: string;\n decimalMarker: '.' | ',';\n clearIfNotMatch: boolean;\n showTemplate: boolean;\n showMaskTyped: boolean;\n placeHolderCharacter: string;\n shownMaskExpression: string;\n dropSpecialCharacters: boolean | string[];\n specialCharacters: string[];\n hiddenInput: boolean | undefined;\n validation: boolean;\n separatorLimit: string;\n allowNegativeNumbers: boolean;\n leadZeroDateTime: boolean;\n patterns: {\n [character: string]: {\n pattern: RegExp;\n optional?: boolean;\n symbol?: string;\n };\n };\n}\n\nexport type optionsConfig = Partial<IConfig>;\nexport const config: InjectionToken<IConfig> = new InjectionToken('config');\nexport const NEW_CONFIG: InjectionToken<IConfig> = new InjectionToken('NEW_CONFIG');\nexport const INITIAL_CONFIG: InjectionToken<IConfig> = new InjectionToken('INITIAL_CONFIG');\n\nexport const initialConfig: IConfig = {\n suffix: '',\n prefix: '',\n thousandSeparator: ' ',\n decimalMarker: '.',\n clearIfNotMatch: false,\n showTemplate: false,\n showMaskTyped: false,\n placeHolderCharacter: '_',\n dropSpecialCharacters: true,\n hiddenInput: undefined,\n shownMaskExpression: '',\n separatorLimit: '',\n allowNegativeNumbers: false,\n validation: true,\n // tslint:disable-next-line: quotemark\n specialCharacters: ['-', '/', '(', ')', '.', ':', ' ', '+', ',', '@', '[', ']', '\"', \"'\"],\n leadZeroDateTime: false,\n patterns: {\n '0': {\n pattern: new RegExp('\\\\d'),\n },\n '9': {\n pattern: new RegExp('\\\\d'),\n optional: true,\n },\n X: {\n pattern: new RegExp('\\\\d'),\n symbol: '*',\n },\n A: {\n pattern: new RegExp('[a-zA-Z0-9]'),\n },\n S: {\n pattern: new RegExp('[a-zA-Z]'),\n },\n d: {\n pattern: new RegExp('\\\\d'),\n },\n m: {\n pattern: new RegExp('\\\\d'),\n },\n M: {\n pattern: new RegExp('\\\\d'),\n },\n H: {\n pattern: new RegExp('\\\\d'),\n },\n h: {\n pattern: new RegExp('\\\\d'),\n },\n s: {\n pattern: new RegExp('\\\\d'),\n },\n },\n};\n\nexport const timeMasks: string[] = ['Hh:m0:s0', 'Hh:m0', 'm0:s0'];\n\nexport const withoutValidation: string[] = [\n 'percent',\n 'Hh',\n 's0',\n 'm0',\n 'separator',\n 'd0/M0/0000',\n 'd0/M0',\n 'd0',\n 'M0',\n];\n","/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from) {\r\n for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)\r\n to[j] = from[i];\r\n return to;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, privateMap) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to get private field on non-instance\");\r\n }\r\n return privateMap.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, privateMap, value) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to set private field on non-instance\");\r\n }\r\n privateMap.set(receiver, value);\r\n return value;\r\n}\r\n","import { Inject, Injectable } from '@angular/core';\nimport { config, IConfig } from './config';\n\n@Injectable()\nexport class MaskApplierService {\n public dropSpecialCharacters: IConfig['dropSpecialCharacters'];\n public hiddenInput: IConfig['hiddenInput'];\n public showTemplate!: IConfig['showTemplate'];\n public clearIfNotMatch!: IConfig['clearIfNotMatch'];\n public maskExpression: string = '';\n public actualValue: string = '';\n public shownMaskExpression: string = '';\n public maskSpecialCharacters!: IConfig['specialCharacters'];\n public maskAvailablePatterns!: IConfig['patterns'];\n public prefix!: IConfig['prefix'];\n public suffix!: IConfig['suffix'];\n public thousandSeparator!: IConfig['thousandSeparator'];\n public decimalMarker!: IConfig['decimalMarker'];\n public customPattern!: IConfig['patterns'];\n public ipError?: boolean;\n public cpfCnpjError?: boolean;\n public showMaskTyped!: IConfig['showMaskTyped'];\n public placeHolderCharacter!: IConfig['placeHolderCharacter'];\n public validation: IConfig['validation'];\n public separatorLimit: IConfig['separatorLimit'];\n public allowNegativeNumbers: IConfig['allowNegativeNumbers'];\n public leadZeroDateTime: IConfig['leadZeroDateTime'];\n\n private _shift!: Set<number>;\n\n public constructor(@Inject(config) protected _config: IConfig) {\n this._shift = new Set();\n this.clearIfNotMatch = this._config.clearIfNotMatch;\n this.dropSpecialCharacters = this._config.dropSpecialCharacters;\n this.maskSpecialCharacters = this._config.specialCharacters;\n this.maskAvailablePatterns = this._config.patterns;\n this.prefix = this._config.prefix;\n this.suffix = this._config.suffix;\n this.thousandSeparator = this._config.thousandSeparator;\n this.decimalMarker = this._config.decimalMarker;\n this.hiddenInput = this._config.hiddenInput;\n this.showMaskTyped = this._config.showMaskTyped;\n this.placeHolderCharacter = this._config.placeHolderCharacter;\n this.validation = this._config.validation;\n this.separatorLimit = this._config.separatorLimit;\n this.allowNegativeNumbers = this._config.allowNegativeNumbers;\n this.leadZeroDateTime = this._config.leadZeroDateTime;\n }\n\n public applyMaskWithPattern(inputValue: string, maskAndPattern: [string, IConfig['patterns']]): string {\n const [mask, customPattern] = maskAndPattern;\n this.customPattern = customPattern;\n return this.applyMask(inputValue, mask);\n }\n\n public applyMask(\n inputValue: string,\n maskExpression: string,\n position: number = 0,\n justPasted: boolean = false,\n backspaced: boolean = false,\n cb: Function = () => {}\n ): string {\n if (inputValue === undefined || inputValue === null || maskExpression === undefined) {\n return '';\n }\n let cursor = 0;\n let result = '';\n let multi = false;\n let backspaceShift = false;\n let shift = 1;\n let stepBack = false;\n if (inputValue.slice(0, this.prefix.length) === this.prefix) {\n inputValue = inputValue.slice(this.prefix.length, inputValue.length);\n }\n if (!!this.suffix && inputValue?.length > 0) {\n inputValue = this.checkAndRemoveSuffix(inputValue);\n }\n const inputArray: string[] = inputValue.toString().split('');\n if (maskExpression === 'IP') {\n this.ipError = !!(inputArray.filter((i: string) => i === '.').length < 3 && inputArray.length < 7);\n maskExpression = '099.099.099.099';\n }\n const arr: string[] = [];\n for (let i = 0; i < inputValue.length; i++) {\n if (inputValue[i].match('\\\\d')) {\n arr.push(inputValue[i]);\n }\n }\n if (maskExpression === 'CPF_CNPJ') {\n this.cpfCnpjError = !!(arr.length !== 11 && arr.length !== 14);\n if (arr.length > 11) {\n maskExpression = '00.000.000/0000-00';\n } else {\n maskExpression = '000.000.000-00';\n }\n }\n if (maskExpression.startsWith('percent')) {\n if (inputValue.match('[a-z]|[A-Z]') || inputValue.match(/[-!$%^&*()_+|~=`{}\\[\\]:\";'<>?,\\/.]/)) {\n inputValue = this._stripToDecimal(inputValue);\n const precision: number = this.getPrecision(maskExpression);\n inputValue = this.checkInputPrecision(inputValue, precision, this.decimalMarker);\n }\n if (inputValue.indexOf('.') > 0 && !this.percentage(inputValue.substring(0, inputValue.indexOf('.')))) {\n const base: string = inputValue.substring(0, inputValue.indexOf('.') - 1);\n inputValue = `${base}${inputValue.substring(inputValue.indexOf('.'), inputValue.length)}`;\n }\n if (this.percentage(inputValue)) {\n result = inputValue;\n } else {\n result = inputValue.substring(0, inputValue.length - 1);\n }\n } else if (maskExpression.startsWith('separator')) {\n if (\n inputValue.match('[wа-яА-Я]') ||\n inputValue.match('[ЁёА-я]') ||\n inputValue.match('[a-z]|[A-Z]') ||\n inputValue.match(/[-@#!$%\\\\^&*()_£¬'+|~=`{}\\[\\]:\";<>.?\\/]/) ||\n inputValue.match('[^A-Za-z0-9,]')\n ) {\n inputValue = this._stripToDecimal(inputValue);\n }\n\n inputValue =\n inputValue.length > 1 && inputValue[0] === '0' && inputValue[1] !== this.decimalMarker\n ? inputValue.slice(1, inputValue.length)\n : inputValue;\n\n // TODO: we had different rexexps here for the different cases... but tests dont seam to bother - check this\n // separator: no COMMA, dot-sep: no SPACE, COMMA OK, comma-sep: no SPACE, COMMA OK\n\n const thousandSeperatorCharEscaped: string = this._charToRegExpExpression(this.thousandSeparator);\n const decimalMarkerEscaped: string = this._charToRegExpExpression(this.decimalMarker);\n const invalidChars: string = '@#!$%^&*()_+|~=`{}\\\\[\\\\]:\\\\s,\\\\.\";<>?\\\\/'\n .replace(thousandSeperatorCharEscaped, '')\n .replace(decimalMarkerEscaped, '');\n\n const invalidCharRegexp: RegExp = new RegExp('[' + invalidChars + ']');\n\n if (inputValue.match(invalidCharRegexp)) {\n inputValue = inputValue.substring(0, inputValue.length - 1);\n }\n\n const precision: number = this.getPrecision(maskExpression);\n inputValue = this.checkInputPrecision(inputValue, precision, this.decimalMarker);\n const strForSep: string = inputValue.replace(new RegExp(thousandSeperatorCharEscaped, 'g'), '');\n result = this._formatWithSeparators(strForSep, this.thousandSeparator, this.decimalMarker, precision);\n\n const commaShift: number = result.indexOf(',') - inputValue.indexOf(',');\n const shiftStep: number = result.length - inputValue.length;\n\n if (shiftStep > 0 && result[position] !== ',') {\n backspaceShift = true;\n let _shift = 0;\n do {\n this._shift.add(position + _shift);\n _shift++;\n } while (_shift < shiftStep);\n } else if (\n (commaShift !== 0 && position > 0 && !(result.indexOf(',') >= position && position > 3)) ||\n (!(result.indexOf('.') >= position && position > 3) && shiftStep <= 0)\n ) {\n this._shift.clear();\n backspaceShift = true;\n shift = shiftStep;\n position += shiftStep;\n this._shift.add(position);\n } else {\n this._shift.clear();\n }\n } else {\n for (\n // tslint:disable-next-line\n let i: number = 0, inputSymbol: string = inputArray[0];\n i < inputArray.length;\n i++, inputSymbol = inputArray[i]\n ) {\n if (cursor === maskExpression.length) {\n break;\n }\n if (this._checkSymbolMask(inputSymbol, maskExpression[cursor]) && maskExpression[cursor + 1] === '?') {\n result += inputSymbol;\n cursor += 2;\n } else if (\n maskExpression[cursor + 1] === '*' &&\n multi &&\n this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2])\n ) {\n result += inputSymbol;\n cursor += 3;\n multi = false;\n } else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor]) && maskExpression[cursor + 1] === '*') {\n result += inputSymbol;\n multi = true;\n } else if (\n maskExpression[cursor + 1] === '?' &&\n this._checkSymbolMask(inputSymbol, maskExpression[cursor + 2])\n ) {\n result += inputSymbol;\n cursor += 3;\n } else if (this._checkSymbolMask(inputSymbol, maskExpression[cursor])) {\n if (maskExpression[cursor] === 'H') {\n if (Number(inputSymbol) > 2) {\n cursor += 1;\n this._shiftStep(maskExpression, cursor, inputArray.length);\n i--;\n if (this.leadZeroDateTime) {\n result += '0';\n }\n continue;\n }\n }\n if (maskExpression[cursor] === 'h') {\n if (result === '2' && Number(inputSymbol) > 3) {\n cursor += 1;\n i--;\n continue;\n }\n }\n if (maskExpression[cursor] === 'm') {\n if (Number(inputSymbol) > 5) {\n cursor += 1;\n this._shiftStep(maskExpression, cursor, inputArray.length);\n i--;\n if (this.leadZeroDateTime) {\n result += '0';\n }\n continue;\n }\n }\n if (maskExpression[cursor] === 's') {\n if (Number(inputSymbol) > 5) {\n cursor += 1;\n this._shiftStep(maskExpression, cursor, inputArray.length);\n i--;\n if (this.leadZeroDateTime) {\n result += '0';\n }\n continue;\n }\n }\n const daysCount = 31;\n if (maskExpression[cursor] === 'd') {\n if (\n (Number(inputSymbol) > 3 && this.leadZeroDateTime) ||\n Number(inputValue.slice(cursor, cursor + 2)) > daysCount ||\n inputValue[cursor + 1] === '/'\n ) {\n cursor += 1;\n this._shiftStep(maskExpression, cursor, inputArray.length);\n i--;\n if (this.leadZeroDateTime) {\n result += '0';\n }\n continue;\n }\n }\n if (maskExpression[cursor] === 'M') {\n const monthsCount = 12;\n // mask without day\n const withoutDays: boolean =\n cursor === 0 &&\n (Number(inputSymbol) > 2 ||\n Number(inputValue.slice(cursor, cursor + 2)) > monthsCount ||\n inputValue[cursor + 1] === '/');\n // day<10 && month<12 for input\n const day1monthInput: boolean =\n inputValue.slice(cursor - 3, cursor - 1).includes('/') &&\n ((inputValue[cursor - 2] === '/' &&\n Number(inputValue.slice(cursor - 1, cursor + 1)) > monthsCount &&\n inputValue[cursor] !== '/') ||\n inputValue[cursor] === '/' ||\n (inputValue[cursor - 3] === '/' &&\n Number(inputValue.slice(cursor - 2, cursor)) > monthsCount &&\n inputValue[cursor - 1] !== '/') ||\n inputValue[cursor - 1] === '/');\n // 10<day<31 && month<12 for input\n const day2monthInput: boolean =\n Number(inputValue.slice(cursor - 3, cursor - 1)) <= daysCount &&\n !inputValue.slice(cursor - 3, cursor - 1).includes('/') &&\n inputValue[cursor - 1] === '/' &&\n (Number(inputValue.slice(cursor, cursor + 2)) > monthsCount || inputValue[cursor + 1] === '/');\n // day<10 && month<12 for paste whole data\n const day1monthPaste: boolean =\n Number(inputValue.slice(cursor - 3, cursor - 1)) > daysCount &&\n !inputValue.slice(cursor - 3, cursor - 1).includes('/') &&\n !inputValue.slice(cursor - 2, cursor).includes('/') &&\n Number(inputValue.slice(cursor - 2, cursor)) > monthsCount;\n // 10<day<31 && month<12 for paste whole data\n const day2monthPaste: boolean =\n Number(inputValue.slice(cursor - 3, cursor - 1)) <= daysCount &&\n !inputValue.slice(cursor - 3, cursor - 1).includes('/') &&\n inputValue[cursor - 1] !== '/' &&\n Number(inputValue.slice(cursor - 1, cursor + 1)) > monthsCount;\n\n if (\n (Number(inputSymbol) > 1 && this.leadZeroDateTime) ||\n withoutDays ||\n day1monthInput ||\n day2monthInput ||\n day1monthPaste ||\n day2monthPaste\n ) {\n cursor += 1;\n this._shiftStep(maskExpression, cursor, inputArray.length);\n i--;\n if (this.leadZeroDateTime) {\n result += '0';\n }\n continue;\n }\n }\n result += inputSymbol;\n cursor++;\n } else if (this.maskSpecialCharacters.indexOf(maskExpression[cursor]) !== -1) {\n result += maskExpression[cursor];\n cursor++;\n this._shiftStep(maskExpression, cursor, inputArray.length);\n i--;\n } else if (\n this.maskSpecialCharacters.indexOf(inputSymbol) > -1 &&\n this.maskAvailablePatterns[maskExpression[cursor]] &&\n this.maskAvailablePatterns[maskExpression[cursor]].optional\n ) {\n if (\n !!inputArray[cursor] &&\n maskExpression !== '099.099.099.099' &&\n maskExpression !== '000.000.000-00' &&\n maskExpression !== '00.000.000/0000-00'\n ) {\n result += inputArray[cursor];\n }\n cursor++;\n i--;\n } else if (\n this.maskExpression[cursor + 1] === '*' &&\n this._findSpecialChar(this.maskExpression[cursor + 2]) &&\n this._findSpecialChar(inputSymbol) === this.maskExpression[cursor + 2] &&\n multi\n ) {\n cursor += 3;\n result += inputSymbol;\n } else if (\n this.maskExpression[cursor + 1] === '?' &&\n this._findSpecialChar(this.maskExpression[cursor + 2]) &&\n this._findSpecialChar(inputSymbol) === this.maskExpression[cursor + 2] &&\n multi\n ) {\n cursor += 3;\n result += inputSymbol;\n } else if (\n this.showMaskTyped &&\n this.maskSpecialCharacters.indexOf(inputSymbol) < 0 &&\n inputSymbol !== this.placeHolderCharacter\n ) {\n stepBack = true;\n }\n }\n }\n if (\n result.length + 1 === maskExpression.length &&\n this.maskSpecialCharacters.indexOf(maskExpression[maskExpression.length - 1]) !== -1\n ) {\n result += maskExpression[maskExpression.length - 1];\n }\n\n let newPosition: number = position + 1;\n\n while (this._shift.has(newPosition)) {\n shift++;\n newPosition++;\n }\n\n let actualShift: number = justPasted ? cursor : this._shift.has(position) ? shift : 0;\n if (stepBack) {\n actualShift--;\n }\n\n cb(actualShift, backspaceShift);\n if (shift < 0) {\n this._shift.clear();\n }\n let onlySpecial = false;\n if (backspaced) {\n onlySpecial = inputArray.every((char) => this.maskSpecialCharacters.includes(char));\n }\n let res = `${this.prefix}${onlySpecial ? '' : result}${this.suffix}`;\n if (result.length === 0) {\n res = `${this.prefix}${result}`;\n }\n return res;\n }\n\n public _findSpecialChar(inputSymbol: string): undefined | string {\n return this.maskSpecialCharacters.find((val: string) => val === inputSymbol);\n }\n\n protected _checkSymbolMask(inputSymbol: string, maskSymbol: string): boolean {\n this.maskAvailablePatterns = this.customPattern ? this.customPattern : this.maskAvailablePatterns;\n return (\n this.maskAvailablePatterns[maskSymbol] &&\n this.maskAvailablePatterns[maskSymbol].pattern &&\n this.maskAvailablePatterns[maskSymbol].pattern.test(inputSymbol)\n );\n }\n\n private _formatWithSeparators = (\n str: string,\n thousandSeparatorChar: string,\n decimalChar: string,\n precision: number\n ) => {\n const x: string[] = str.split(decimalChar);\n const decimals: string = x.length > 1 ? `${decimalChar}${x[1]}` : '';\n let res: string = x[0];\n const separatorLimit: string = this.separatorLimit.replace(/\\s/g, '');\n if (separatorLimit && +separatorLimit) {\n if (res[0] === '-') {\n res = `-${res.slice(1, res.length).slice(0, separatorLimit.length)}`;\n } else {\n res = res.slice(0, separatorLimit.length);\n }\n }\n const rgx: RegExp = /(\\d+)(\\d{3})/;\n\n while (thousandSeparatorChar && rgx.test(res)) {\n res = res.replace(rgx, '$1' + thousandSeparatorChar + '$2');\n }\n\n if (precision === undefined) {\n return res + decimals;\n } else if (precision === 0) {\n return res;\n }\n return res + decimals.substr(0, precision + 1);\n };\n\n private percentage = (str: string): boolean => {\n return Number(str) >= 0 && Number(str) <= 100;\n };\n\n private getPrecision = (maskExpression: string): number => {\n const x: string[] = maskExpression.split('.');\n if (x.length > 1) {\n return Number(x[x.length - 1]);\n }\n\n return Infinity;\n };\n\n private checkAndRemoveSuffix = (inputValue: string): string => {\n for (let i = this.suffix?.length - 1; i >= 0; i--) {\n const substr = this.suffix.substr(i, this.suffix?.length);\n if (\n inputValue.includes(substr) &&\n (i - 1 < 0 || !inputValue.includes(this.suffix.substr(i - 1, this.suffix?.length)))\n ) {\n return inputValue.replace(substr, '');\n }\n }\n return inputValue;\n };\n\n private checkInputPrecision = (\n inputValue: string,\n precision: number,\n decimalMarker: IConfig['decimalMarker']\n ): string => {\n if (precision < Infinity) {\n const precisionRegEx: RegExp = new RegExp(this._charToRegExpExpression(decimalMarker) + `\\\\d{${precision}}.*$`);\n\n const precisionMatch: RegExpMatchArray | null = inputValue.match(precisionRegEx);\n if (precisionMatch && precisionMatch[0].length - 1 > precision) {\n const diff = precisionMatch[0].length - 1 - precision;\n inputValue = inputValue.substring(0, inputValue.length - diff);\n }\n if (precision === 0 && inputValue.endsWith(decimalMarker)) {\n inputValue = inputValue.substring(0, inputValue.length - 1);\n }\n }\n return inputValue;\n };\n\n private _stripToDecimal(str: string): string {\n return str\n .split('')\n .filter((i: string, idx: number) => {\n return (\n i.match('^-?\\\\d') ||\n i.match('\\\\s') ||\n i === '.' ||\n i === ',' ||\n (i === '-' && idx === 0 && this.allowNegativeNumbers)\n );\n })\n .join('');\n }\n\n private _charToRegExpExpression(char: string): string {\n if (char) {\n const charsToEscape = '[\\\\^$.|?*+()';\n return char === ' ' ? '\\\\s' : charsToEscape.indexOf(char) >= 0 ? '\\\\' + char : char;\n }\n return char;\n }\n\n private _shiftStep(maskExpression: string, cursor: number, inputLength: number) {\n const shiftStep: number = /[*?]/g.test(maskExpression.slice(0, cursor)) ? inputLength : cursor;\n this._shift.add(shiftStep + this.prefix.length || 0);\n }\n}\n","import { ElementRef, Inject, Injectable, Renderer2 } from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\n\nimport { config, IConfig } from './config';\nimport { MaskApplierService } from './mask-applier.service';\n\n@Injectable()\nexport class MaskService extends MaskApplierService {\n public maskExpression: string = '';\n public isNumberValue: boolean = false;\n public placeHolderCharacter: string = '_';\n public maskIsShown: string = '';\n public selStart: number | null = null;\n public selEnd: number | null = null;\n\n /**\n * Whether we are currently in writeValue function, in this case when applying the mask we don't want to trigger onChange function,\n * since writeValue should be a one way only process of writing the DOM value based on the Angular model value.\n */\n public writingValue: boolean = false;\n\n public onChange = (_: any) => {};\n\n public constructor(\n @Inject(DOCUMENT) private document: any,\n @Inject(config) protected _config: IConfig,\n private _elementRef: ElementRef,\n private _renderer: Renderer2\n ) {\n super(_config);\n }\n\n // tslint:disable-next-line:cyclomatic-complexity\n public applyMask(\n inputValue: string,\n maskExpression: string,\n position: number = 0,\n justPasted = false,\n backspaced = false,\n cb: Function = () => {}\n ): string {\n if (!maskExpression) {\n return inputValue;\n }\n this.maskIsShown = this.showMaskTyped ? this.showMaskInInput() : '';\n if (this.maskExpression === 'IP' && this.showMaskTyped) {\n this.maskIsShown = this.showMaskInInput(inputValue || '#');\n }\n if (this.maskExpression === 'CPF_CNPJ' && this.showMaskTyped) {\n this.maskIsShown = this.showMaskInInput(inputValue || '#');\n }\n if (!inputValue && this.showMaskTyped) {\n this.formControlResult(this.prefix);\n return this.prefix + this.maskIsShown;\n }\n const getSymbol: string = !!inputValue && typeof this.selStart === 'number' ? inputValue[this.selStart] : '';\n let newInputValue = '';\n if (this.hiddenInput && !this.writingValue) {\n let actualResult: string[] = this.actualValue.split('');\n // tslint:disable no-unused-expression\n inputValue !== '' && actualResult.length\n ? typeof this.selStart === 'number' && typeof this.selEnd === 'number'\n ? inputValue.length > actualResult.length\n ? actualResult.splice(this.selStart, 0, getSymbol)\n : inputValue.length < actualResult.length\n ? actualResult.length - inputValue.length === 1\n ? actualResult.splice(this.selStart - 1, 1)\n : actualResult.splice(this.selStart, this.selEnd - this.selStart)\n : null\n : null\n : (actualResult = []);\n // tslint:enable no-unused-expression\n newInputValue =\n this.actualValue.length && actualResult.length <= inputValue.length\n ? this.shiftTypedSymbols(actualResult.join(''))\n : inputValue;\n }\n newInputValue = Boolean(newInputValue) && newInputValue.length ? newInputValue : inputValue;\n const result: string = super.applyMask(newInputValue, maskExpression, position, justPasted, backspaced, cb);\n this.actualValue = this.getActualValue(result);\n\n // handle some separator implications:\n // a.) adjust decimalMarker default (. -> ,) if thousandSeparator is a dot\n if (this.thousandSeparator === '.' && this.decimalMarker === '.') {\n this.decimalMarker = ',';\n }\n\n // b) remove decimal marker from list of special characters to mask\n if (this.maskExpression.startsWith('separator') && this.dropSpecialCharacters === true) {\n this.maskSpecialCharacters = this.maskSpecialCharacters.filter((item: string) => item !== this.decimalMarker);\n }\n\n this.formControlResult(result);\n\n if (!this.showMaskTyped) {\n if (this.hiddenInput) {\n return result && result.length ? this.hideInput(result, this.maskExpression) : result;\n }\n return result;\n }\n const resLen: number = result.length;\n const prefNmask: string = this.prefix + this.maskIsShown;\n\n if (this.maskExpression.includes('H')) {\n const countSkipedSymbol = this._numberSkipedSymbols(result);\n return result + prefNmask.slice(resLen + countSkipedSymbol);\n } else if (this.maskExpression === 'IP' || this.maskExpression === 'CPF_CNPJ') {\n return result + prefNmask;\n }\n return result + prefNmask.slice(resLen);\n }\n\n // get the number of characters that were shifted\n private _numberSkipedSymbols(value: string): number {\n const regex = /(^|\\D)(\\d\\D)/g;\n let match = regex.exec(value);\n let countSkipedSymbol = 0;\n while (match != null) {\n countSkipedSymbol += 1;\n match = regex.exec(value);\n }\n return countSkipedSymbol;\n }\n\n public applyValueChanges(\n position: number = 0,\n justPasted: boolean,\n backspaced: boolean,\n cb: Function = () => {}\n ): void {\n const formElement = this._elementRef.nativeElement;\n formElement.value = this.applyMask(formElement.value, this.maskExpression, position, justPasted, backspaced, cb);\n if (formElement === this.document.activeElement) {\n return;\n }\n this.clearIfNotMatchFn();\n }\n\n public hideInput(inputValue: string, maskExpression: string): string {\n return inputValue\n .split('')\n .map((curr: string, index: number) => {\n if (\n this.maskAvailablePatterns &&\n this.maskAvailablePatterns[maskExpression[index]] &&\n this.maskAvailablePatterns[maskExpression[index]].symbol\n ) {\n return this.maskAvailablePatterns[maskExpression[index]].symbol;\n }\n return curr;\n })\n .join('');\n }\n\n // this function is not necessary, it checks result against maskExpression\n public getActualValue(res: string): string {\n const compare: string[] = res\n .split('')\n .filter(\n (symbol: string, i: number) =>\n this._checkSymbolMask(symbol, this.maskExpression[i]) ||\n (this.maskSpecialCharacters.includes(this.maskExpression[i]) && symbol === this.maskExpression[i])\n );\n if (compare.join('') === res) {\n return compare.join('');\n }\n return res;\n }\n\n public shiftTypedSymbols(inputValue: string): string {\n let symbolToReplace = '';\n const newInputValue: string[] =\n (inputValue &&\n inputValue.split('').map((currSymbol: string, index: number) => {\n if (\n this.maskSpecialCharacters.includes(inputValue[index + 1]) &&\n inputValue[index + 1] !== this.maskExpression[index + 1]\n ) {\n symbolToReplace = currSymbol;\n return inputValue[index + 1];\n }\n if (symbolToReplace.length) {\n const replaceSymbol: string = symbolToReplace;\n symbolToReplace = '';\n return replaceSymbol;\n }\n return currSymbol;\n })) ||\n [];\n return newInputValue.join('');\n }\n\n public showMaskInInput(inputVal?: string): string {\n if (this.showMaskTyped && !!this.shownMaskExpression) {\n if (this.maskExpression.length !== this.shownMaskExpression.length) {\n throw new Error('Mask expression must match mask placeholder length');\n } else {\n return this.shownMaskExpression;\n }\n } else if (this.showMaskTyped) {\n if (inputVal) {\n if (this.maskExpression === 'IP') {\n return this._checkForIp(inputVal);\n }\n if (this.maskExpression === 'CPF_CNPJ') {\n return this._checkForCpfCnpj(inputVal);\n }\n }\n return this.maskExpression.replace(/\\w/g, this.placeHolderCharacter);\n }\n return '';\n }\n\n public clearIfNotMatchFn(): void {\n const formElement = this._elementRef.nativeElement;\n if (\n this.clearIfNotMatch &&\n this.prefix.length + this.maskExpression.length + this.suffix.length !==\n formElement.value.replace(/_/g, '').length\n ) {\n this.formElementProperty = ['value', ''];\n this.applyMask(formElement.value, this.maskExpression);\n }\n }\n\n public set formElementProperty([name, value]: [string, string | boolean]) {\n Promise.resolve().then(() => this._renderer.setProperty(this._elementRef.nativeElement, name, value));\n }\n\n public checkSpecialCharAmount(mask: string): number {\n const chars: string[] = mask.split('').filter((item: string) => this._findSpecialChar(item));\n return chars.length;\n }\n\n public removeMask(inputValue: string): string {\n return this._removeMask(\n this._removeSuffix(this._removePrefix(inputValue)),\n this.maskSpecialCharacters.concat('_').concat(this.placeHolderCharacter)\n );\n }\n\n private _checkForIp(inputVal: string): string {\n if (inputVal === '#') {\n return `${this.placeHolderCharacter}.${this.placeHolderCharacter}.${this.placeHolderCharacter}.${this.placeHolderCharacter}`;\n }\n const arr: string[] = [];\n for (let i = 0; i < inputVal.length; i++) {\n if (inputVal[i].match('\\\\d')) {\n arr.push(inputVal[i]);\n }\n }\n if (arr.length <= 3) {\n return `${this.placeHolderCharacter}.${this.placeHolderCharacter}.${this.placeHolderCharacter}`;\n }\n if (arr.length > 3 && arr.length <= 6) {\n return `${this.placeHolderCharacter}.${this.placeHolderCharacter}`;\n }\n if (arr.length > 6 && arr.length <= 9) {\n return this.placeHolderCharacter;\n }\n if (arr.length > 9 && arr.length <= 12) {\n return '';\n }\n return '';\n }\n\n private _checkForCpfCnpj(inputVal: string): string {\n const cpf =\n `${this.placeHolderCharacter}${this.placeHolderCharacter}${this.placeHolderCharacter}` +\n `.${this.placeHolderCharacter}${this.placeHolderCharacter}${this.placeHolderCharacter}` +\n `.${this.placeHolderCharacter}${this.placeHolderCharacter}${this.placeHolderCharacter}` +\n `-${this.placeHolderCharacter}${this.placeHolderCharacter}`;\n const cnpj =\n `${this.placeHolderCharacter}${this.placeHolderCharacter}` +\n `.${this.placeHolderCharacter}${this.placeHolderCharacter}${this.placeHolderCharacter}` +\n `.${this.placeHolderCharacter}${this.placeHolderCharacter}${this.placeHolderCharacter}` +\n `/${this.placeHolderCharacter}${this.placeHolderCharacter}${this.placeHolderCharacter}${this.placeHolderCharacter}` +\n `-${this.placeHolderCharacter}${this.placeHolderCharacter}`;\n\n if (inputVal === '#') {\n return cpf;\n }\n const arr: string[] = [];\n for (let i = 0; i < inputVal.length; i++) {\n if (inputVal[i].match('\\\\d')) {\n arr.push(inputVal[i]);\n }\n }\n if (arr.length <= 3) {\n return cpf.slice(arr.length, cpf.length);\n }\n if (arr.length > 3 && arr.length <= 6) {\n return cpf.slice(arr.length + 1, cpf.length);\n }\n if (arr.length > 6 && arr.length <= 9) {\n return cpf.slice(arr.length + 2, cpf.length);\n }\n if (arr.length > 9 && arr.length < 11) {\n return cpf.slice(arr.length + 3, cpf.length);\n }\n if (arr.length === 11) {\n return '';\n }\n if (arr.length === 12) {\n if (inputVal.length === 17) {\n return cnpj.slice(16, cnpj.length);\n }\n return cnpj.slice(15, cnpj.length);\n }\n if (arr.length > 12 && arr.length <= 14) {\n return cnpj.slice(arr.length + 4, cnpj.length);\n }\n return '';\n }\n\n /**\n * Propogates the input value back to the Angular model by triggering the onChange function. It won't do this if writingValue\n * is true. If that is true it means we are currently in the writeValue function, which is supposed to only update the actual\n * DOM element based on the Angular model value. It should be a one way process, i.e. writeValue should not be modifying the Angular\n * model value too. Therefore, we don't trigger onChange in this scenario.\n * @param inputValue the current form input value\n */\n private formControlResult(inputValue: string): void {\n if (this.writingValue) {\n return;\n }\n if (Array.isArray(this.dropSpecialCharacters)) {\n this.onChange(\n this._toNumber(this._removeMask(this._removeSuffix(this._removePrefix(inputValue)), this.dropSpecialCharacters))\n );\n } else if (this.dropSpecialCharacters) {\n this.onChange(this._toNumber(this._checkSymbols(inputValue)));\n } else {\n this.onChange(this._removeSuffix(inputValue));\n }\n }\n\n private _toNumber(value: string | number | undefined | null) {\n if (!this.isNumberValue || value === '') {\n return value;\n }\n const num = Number(value);\n return Number.isNaN(num) ? value : num;\n }\n\n private _removeMask(value: string, specialCharactersForRemove: string[]): string {\n return value ? value.replace(this._regExpForRemove(specialCharactersForRemove), '') : value;\n }\n\n private _removePrefix(value: string): string {\n if (!this.prefix) {\n return value;\n }\n return value ? value.replace(this.prefix, '') : value;\n }\n\n private _removeSuffix(value: string): string {\n if (!this.suffix) {\n return value;\n }\n return value ? value.replace(this.suffix, '') : value;\n }\n\n private _retrieveSeparatorValue(result: string): string {\n return this._removeMask(this._removeSuffix(this._removePrefix(result)), this.maskSpecialCharacters);\n }\n\n private _regExpForRemove(specialCharactersForRemove: string[]): RegExp {\n return new RegExp(specialCharactersForRemove.map((item: string) => `\\\\${item}`).join('|'), 'gi');\n }\n\n private _checkSymbols(result: string): string | number | undefined | null {\n if (result === '') {\n return result;\n }\n\n const separatorPrecision: number | null = this._retrieveSeparatorPrecision(this.maskExpression);\n let separatorValue: string = this._retrieveSeparatorValue(result);\n if (this.decimalMarker !== '.') {\n separatorValue = separatorValue.replace(this.decimalMarker, '.');\n }\n\n if (!this.isNumberValue) {\n return separatorValue;\n }\n if (separatorPrecision) {\n if (result === this.decimalMarker) {\n return null;\n }\n return this._checkPrecision(this.maskExpression, separatorValue);\n } else {\n return Number(separatorValue);\n }\n }\n\n // TODO should think about helpers or separting decimal precision to own property\n private _retrieveSeparatorPrecision(maskExpretion: string): number | null {\n const matcher: RegExpMatchArray | null = maskExpretion.match(new RegExp(`^separator\\\\.([^d]*)`));\n return matcher ? Number(matcher[1]) : null;\n }\n\n private _checkPrecision(separatorExpression: string, separatorValue: string): number | string {\n if (separatorExpression.indexOf('2') > 0) {\n return Number(separatorValue).toFixed(2);\n }\n return Number(separatorValue);\n }\n}\n","import {\n ControlValueAccessor,\n FormControl,\n NG_VALIDATORS,\n NG_VALUE_ACCESSOR,\n ValidationErrors,\n Validator,\n} from '@angular/forms';\nimport { Directive, forwardRef, HostListener, Inject, Input, OnChanges, SimpleChanges } from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\n\nimport { CustomKeyboardEvent } from