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);
}
}
'9': /[0-9]/,
U: /[A-Z]/,
A: /[a-zA-Z]/,
'*': /[0-9a-zA-Z]/
};
let { type, ...inputMask } = utils.toCamelCase(this.attrs.mask);
if (type === 'NumberMask') {
if (inputMask.includeThousandsSeparator) {
const regex = new RegExp(inputMask.thousandsSeparatorSymbol, 'g');
this._unmask = value => (typeof value == 'string' ? value.replace(regex, '') : value);
}
inputMask = createNumberMask(inputMask);
}
else inputMask = inputMask.mask.split('').map(c => (maskMap.hasOwnProperty(c) ? maskMap[c] : c));
this._textMask = createTextMaskInputElement({ inputElement: this._inputElement, mask: inputMask });
this._textMask.update(this.value || '');
}
}
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;
}
initTextMask() {
const { props, props: { value } } = this;
if (props.mask && this.inputControlRef) {
this.textMaskInputElement = createTextMaskInputElement({
inputElement: this.inputControlRef,
...props,
});
this.textMaskInputElement.update(value);
}
}
}
let conformedValue = value;
const {
guide, placeholderChar, placeholder, currentCaretPosition,
showMask, keepCharPositions,
} = props;
const conformToMaskConfig = {
previousPlaceholder: placeholder,
guide,
placeholderChar,
pipe,
currentCaretPosition,
keepCharPositions,
};
const conformed = conformToMask(safeValue, mask, conformToMaskConfig);
if (conformed) {
({ conformedValue } = conformed);
}
if (typeof pipe === 'function') {
const pipeResults = pipe(conformedValue, { rawValue: safeValue, ...conformToMaskConfig });
if (typeof pipeResults === 'string') {
conformedValue = pipeResults;
}
}
if (conformedValue === placeholder) {
conformedValue = showMask ? placeholder : '';
}
return conformedValue;
};