UNPKG

@technobuddha/library

Version:
30 lines (29 loc) 1.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mask = void 0; var constants_1 = require("../constants"); var splitChars_1 = __importDefault(require("../splitChars")); var tokenizer = /\\#|#|./gu; /** * Use a simple mask to display a string * * @remark The simple mask is a string where '#' characters are replaced by characters from the input string. Other characters in the mask * are output as-is, to output a '#' use '\#' * * @param input The string * @param mask The mask * @param __namedParameters see {@link Options} * @default missing space * @returns The mask filled with characters from the string */ function mask(input, maskStr, _a) { var _b = _a === void 0 ? {} : _a, _c = _b.missing, missing = _c === void 0 ? constants_1.space : _c; var chars = splitChars_1.default(input); var index = 0; return maskStr.replace(tokenizer, function (token) { var _a; return (token === '\\#' ? '#' : token === '#' ? ((_a = chars[index++]) !== null && _a !== void 0 ? _a : missing) : token); }); } exports.mask = mask; exports.default = mask;