Skip to content

Instantly share code, notes, and snippets.

@edgvi10
Created December 30, 2021 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edgvi10/0fc238ad30090559b9bbf2295f9f3c36 to your computer and use it in GitHub Desktop.
Save edgvi10/0fc238ad30090559b9bbf2295f9f3c36 to your computer and use it in GitHub Desktop.
export const mask = function (m, str) {
if (str === undefined || str === null) return '';
var m,
l = (m = m.split("")).length,
s = str.split(""),
j = 0,
h = "";
for (var i = -1; ++i < l;)
if (m[i] != "#") {
if (m[i] == "\\" && (h += m[++i])) continue;
h += m[i];
i + 1 == l && (s[j - 1] += h, h = "");
}
else {
if (!s[j] && !(h = "")) break;
(s[j] = h + s[j++]) && (h = "");
}
return s.join("") + h;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment