import { MaskString } from 'mask';
// Function call
const result = StringMask.convert('abcd', { mask: 'AAAA' }); // value and object with options
console.log(result.original); // 'abcd'
console.log(result.value); // 'ABCD'
console.log(result.isValid); // true
console.log(result.hasErrors); // false
// variable
const variable = new StringMask('abcd', { mask: 'AAAA' }); // value and object with options,
console.log(variable.original); // 'abcd'
console.log(variable.value); // 'ABCD'
console.log(variable.isValid); // true
console.log(variable.hasErrors); // false
console.log(variable.result); // same output as via function call
console.log(variable.errors); // [], array with object containing information about errors during conversion
console.log(variable.prefix); // undefined, if prefix is added via the options, this property contains the prefix
console.log(variable.suffix); // undefined, if suffix is added via the options, this property contains the suffix
variable.value = 'efgh'; // set a new value, console.log(variable.value) -> 'EFGH'
Characters not listed in table (or defined as custom masks) are placed in the result of the conversion
MaskNumber
Description
Converts a number (type number or string) via a mask (result is always a string)
Available has function or as object
import { MaskNumber } from 'mask';
// Function call
const result = StringNumber.convert(1234, { mask: '####' }); // value and object with options
console.log(result.original); // 1234
console.log(result.value); // '1234'
console.log(result.isValid); // true
console.log(result.hasErrors); // false
// variable
const variable = new StringMask(1234, { mask: '####' }); // value and object with options,
console.log(variable.original); // 1234
console.log(variable.value); // '1234'
console.log(variable.isValid); // true
console.log(variable.hasErrors); // false
console.log(variable.result); // same output as via function call
console.log(variable.errors); // [], array with object containing information about errors during conversion
console.log(variable.prefix); // undefined, if prefix is added via the options, this property contains the prefix
console.log(variable.suffix); // undefined, if suffix is added via the options, this property contains the suffix
variable.value = 4789; // set a new value, console.log(variable.value) -> '4789'