Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_setupMask(create = false) {
if (!this.inputElement) {
if (this._elementRef.nativeElement.tagName.toUpperCase() === 'INPUT') {
// `textMask` directive is used directly on an input element
this.inputElement = this._elementRef.nativeElement
} else {
// `textMask` directive is used on an abstracted input element, `md-input-container`, etc
this.inputElement = this._elementRef.nativeElement.getElementsByTagName('INPUT')[0]
}
}
if (this.inputElement && create) {
this.textMaskInputElement = createTextMaskInputElement(
Object.assign({ inputElement: this.inputElement }, this.textMaskConfig)
)
}
}
private setUpMask(): void {
// istanbul ignore else
if (this.inputElement) {
// tslint:disable-next-line no-any
const maskOptions: {[key: string]: any} = {
inputElement: this.inputElement.nativeElement,
...this.textMaskConfig,
};
// Initialize the mask
this.textMaskInputElement = createTextMaskInputElement(maskOptions);
}
}
private setupMask(create?: boolean): void {
// istanbul ignore else
if (!this.inputElement) {
this.inputElement = this.elementRef.nativeElement;
}
// istanbul ignore else
if (this.inputElement && create) {
const maskOptions = Object.assign({inputElement: this.inputElement}, this.textMaskConfig);
// Initialize the mask
this.textMaskInputElement = createTextMaskInputElement(maskOptions);
}
}
export function transformByRegex(value: string | number, mask: Mask.Config): string {
if (typeof value === 'number') value = String(value);
const inputElement = document.createElement('input');
inputElement.type = 'text';
const textMaskInputElement = createTextMaskInputElement({ ...mask, inputElement });
textMaskInputElement.update(value);
return inputElement.value;
}