-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
format.js
41 lines (37 loc) 路 759 Bytes
/
format.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (data, mask) {
if (!mask) return data;
var text = '';
for (var i = 0, x = 1; x && i < mask.length; ++i) {
var c = data.charAt(i);
var m = mask.charAt(i);
switch (m) {
case '#':
if (/\d/.test(c)) {
text += c;
} else {
x = 0;
}break;
case 'A':
if (/[a-z]/i.test(c)) {
text += c;
} else {
x = 0;
}break;
case 'N':
if (/[a-z0-9]/i.test(c)) {
text += c;
} else {
x = 0;
}break;
case 'X':
text += c;break;
default:
text += m;break;
}
}
return text;
};