UNPKG

@ssibrahimbas/v-mask

Version:
45 lines (44 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.maskIt = void 0; const maskIt = (value, mask, tokens, masked = true) => { var _a; value = value || ""; mask = mask || ""; let iMask = 0, iValue = 0, output = ""; while (iMask < mask.length && iValue < value.length) { let cMask = mask[iMask]; const masker = tokens[cMask]; const cValue = value[iValue]; if (masker && !masker.escape) { if ((_a = masker.pattern) === null || _a === void 0 ? void 0 : _a.test(cValue)) { output += masker.transform ? masker.transform(cValue) : cValue; iMask++; } iValue++; } else { if (masker && masker.escape) { iMask++; cMask = mask[iMask]; } if (masked) output += cMask; if (cValue === cMask) iValue++; iMask++; } } let restOutput = ""; while (iMask < mask.length && masked) { const cMask = mask[iMask]; if (tokens[cMask]) { restOutput = ""; break; } restOutput += cMask; iMask++; } return output + restOutput; }; exports.maskIt = maskIt;