mm_matchs 1.1.10 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/index.js +10 -431
- package/lib/admin.js +17 -0
- package/lib/matchs.js +351 -0
- package/lib/util.js +75 -0
- package/package.json +15 -3
- package/tool/match/index.js +79 -0
- package/tool/match/tool.json +79 -0
- package/tool/match_admin/index.js +41 -0
- package/tool/match_admin/tool.json +11 -0
- package/.gitattributes +0 -5
- package/eslint.config.js +0 -106
- package/html.js +0 -250
- package/htmlformat.js +0 -396
- package/lang.js +0 -5
- package/test.js +0 -213
- package/test_html.js +0 -2679
package/htmlformat.js
DELETED
|
@@ -1,396 +0,0 @@
|
|
|
1
|
-
function styleHtml(html_source, indent_size, indent_char, max_char) {
|
|
2
|
-
//Wrapper function to invoke all the necessary constructors and deal with the output.
|
|
3
|
-
|
|
4
|
-
var parser, multi_parser;
|
|
5
|
-
|
|
6
|
-
function parser() {
|
|
7
|
-
|
|
8
|
-
this.pos = 0; //Parser position
|
|
9
|
-
this.token = '';
|
|
10
|
-
this.current_mode = 'CONTENT'; //reflects the current Parser mode: TAG/CONTENT
|
|
11
|
-
this.tags = { //An object to hold tags, their position, and their parent-tags, initiated with default values
|
|
12
|
-
parent: 'parent1',
|
|
13
|
-
parentcount: 1,
|
|
14
|
-
parent1: ''
|
|
15
|
-
};
|
|
16
|
-
this.tag_type = '';
|
|
17
|
-
this.token_text = this.last_token = this.last_text = this.token_type = '';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.Utils = { //Uilities made available to the various functions
|
|
21
|
-
whitespace: '\n\r\t '.split(''),
|
|
22
|
-
single_token: 'br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed'.split(','), //all the single tags for HTML
|
|
23
|
-
extra_liners: 'head,body,/html'.split(','), //for tags that need a line of whitespace before them
|
|
24
|
-
inArray: function (what, arr) {
|
|
25
|
-
var len = arr.length;
|
|
26
|
-
for (var i = 0; i < len; i++) {
|
|
27
|
-
if (what === arr[i]) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
this.getContent = function () { //function to capture regular content between tags
|
|
36
|
-
|
|
37
|
-
var char = '';
|
|
38
|
-
var content = [];
|
|
39
|
-
var space = false; //if a space is needed
|
|
40
|
-
while (this.input.charAt(this.pos) !== '<') {
|
|
41
|
-
if (this.pos >= this.input.length) {
|
|
42
|
-
return content.length ? content.join('') : ['', 'TK_EOF'];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
char = this.input.charAt(this.pos);
|
|
46
|
-
this.pos++;
|
|
47
|
-
this.line_char_count++;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (this.Utils.in_array(char, this.Utils.whitespace)) {
|
|
51
|
-
if (content.length) {
|
|
52
|
-
space = true;
|
|
53
|
-
}
|
|
54
|
-
this.line_char_count--;
|
|
55
|
-
continue; //don't want to insert unnecessary space
|
|
56
|
-
} else if (space) {
|
|
57
|
-
if (this.line_char_count >= this.max_char) { //insert a line when the max_char is reached
|
|
58
|
-
content.push('\n');
|
|
59
|
-
for (var i = 0; i < this.indent_level; i++) {
|
|
60
|
-
content.push(this.indent_string);
|
|
61
|
-
}
|
|
62
|
-
this.line_char_count = 0;
|
|
63
|
-
} else {
|
|
64
|
-
content.push(' ');
|
|
65
|
-
this.line_char_count++;
|
|
66
|
-
}
|
|
67
|
-
space = false;
|
|
68
|
-
}
|
|
69
|
-
content.push(char); //letter at-a-time (or string) inserted to an array
|
|
70
|
-
}
|
|
71
|
-
return content.length ? content.join('') : '';
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
this.getScript = function () { //get the full content of a script to pass to js_beautify
|
|
75
|
-
|
|
76
|
-
var char = '';
|
|
77
|
-
var content = [];
|
|
78
|
-
var reg_match = this.regex.scriptEndTag;
|
|
79
|
-
reg_match.lastIndex = this.pos;
|
|
80
|
-
var reg = reg_match.exec(this.input);
|
|
81
|
-
var end_script = reg_array ? reg_array.index : this.input.length; //absolute end of script
|
|
82
|
-
while (this.pos < end_script) { //get everything in between the script tags
|
|
83
|
-
if (this.pos >= this.input.length) {
|
|
84
|
-
return content.length ? content.join('') : ['', 'TK_EOF'];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
char = this.input.charAt(this.pos);
|
|
88
|
-
this.pos++;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
content.push(char);
|
|
92
|
-
}
|
|
93
|
-
return content.length ? content.join('') : ''; //we might not have any content at all
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
this.recordTag = function (tag) { //function to record a tag and its parent in this.tags Object
|
|
97
|
-
if (this.tags[tag + 'count']) { //check for the existence of this tag type
|
|
98
|
-
this.tags[tag + 'count']++;
|
|
99
|
-
this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
|
|
100
|
-
} else { //otherwise initialize this tag type
|
|
101
|
-
this.tags[tag + 'count'] = 1;
|
|
102
|
-
this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
|
|
103
|
-
}
|
|
104
|
-
this.tags[tag + this.tags[tag + 'count'] + 'parent'] = this.tags.parent; //set the parent (i.e. in the case of a div this.tags.div1parent)
|
|
105
|
-
this.tags.parent = tag + this.tags[tag + 'count']; //and make this the current parent (i.e. in the case of a div 'div1')
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
this.retrieveTag = function (tag) { //function to retrieve the opening tag to the corresponding closer
|
|
109
|
-
if (this.tags[tag + 'count']) { //if the openener is not in the Object we ignore it
|
|
110
|
-
var parent = this.tags.parent; //check to see if it's a closable tag.
|
|
111
|
-
while (temp_parent) { //till we reach '' (the initial value);
|
|
112
|
-
if (tag + this.tags[tag + 'count'] === temp_parent) { //if this is it use it
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
temp_parent = this.tags[temp_parent + 'parent']; //otherwise keep on climbing up the DOM Tree
|
|
116
|
-
}
|
|
117
|
-
if (temp_parent) { //if we caught something
|
|
118
|
-
this.indent_level = this.tags[tag + this.tags[tag + 'count']]; //set the indent_level accordingly
|
|
119
|
-
this.tags.parent = this.tags[temp_parent + 'parent']; //and set the current parent
|
|
120
|
-
}
|
|
121
|
-
delete this.tags[tag + this.tags[tag + 'count'] + 'parent']; //delete the closed tags parent reference...
|
|
122
|
-
delete this.tags[tag + this.tags[tag + 'count']]; //...and the tag itself
|
|
123
|
-
if (this.tags[tag + 'count'] == 1) {
|
|
124
|
-
delete this.tags[tag + 'count'];
|
|
125
|
-
} else {
|
|
126
|
-
this.tags[tag + 'count']--;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
this.getTag = function () { //function to get a full tag and parse its type
|
|
132
|
-
var char = '';
|
|
133
|
-
var content = [];
|
|
134
|
-
var space = false;
|
|
135
|
-
|
|
136
|
-
do {
|
|
137
|
-
if (this.pos >= this.input.length) {
|
|
138
|
-
return content.length ? content.join('') : ['', 'TK_EOF'];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
char = this.input.charAt(this.pos);
|
|
142
|
-
this.pos++;
|
|
143
|
-
this.line_char_count++;
|
|
144
|
-
|
|
145
|
-
if (this.Utils.in_array(char, this.Utils.whitespace)) { //don't want to insert unnecessary space
|
|
146
|
-
space = true;
|
|
147
|
-
this.line_char_count--;
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (char === "'" || char === '"') {
|
|
152
|
-
if (!content[1] || content[1] !== '!') { //if we're in a comment strings don't get treated specially
|
|
153
|
-
char += this.getUnfo(char);
|
|
154
|
-
space = true;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (char === '=') { //no space before =
|
|
159
|
-
space = false;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (content.length && content[content.length - 1] !== '=' && char !== '>' &&
|
|
163
|
-
space) { //no space after = or before >
|
|
164
|
-
if (this.line_char_count >= this.max_char) {
|
|
165
|
-
this.printNewline(false, content);
|
|
166
|
-
this.line_char_count = 0;
|
|
167
|
-
} else {
|
|
168
|
-
content.push(' ');
|
|
169
|
-
this.line_char_count++;
|
|
170
|
-
}
|
|
171
|
-
space = false;
|
|
172
|
-
}
|
|
173
|
-
content.push(char); //inserts character at-a-time (or string)
|
|
174
|
-
} while (char !== '>');
|
|
175
|
-
|
|
176
|
-
var tag_complete = content.join('');
|
|
177
|
-
var tag;
|
|
178
|
-
if (tag_complete.indexOf(' ') != -1) { //if there's whitespace, thats where the tag name ends
|
|
179
|
-
tag_index = tag_complete.indexOf(' ');
|
|
180
|
-
} else { //otherwise go with the tag ending
|
|
181
|
-
tag_index = tag_complete.indexOf('>');
|
|
182
|
-
}
|
|
183
|
-
var tag_check = tag_complete.substring(1, tag_index).toLowerCase();
|
|
184
|
-
if (tag_complete.charAt(tag_complete.length - 2) === '/' ||
|
|
185
|
-
this.Utils.in_array(tag_check, this.Utils.single_token)) { //if this tag name is a single tag type (either in the list or has a closing /)
|
|
186
|
-
this.tag_type = 'SINGLE';
|
|
187
|
-
} else if (tag_check === 'script') { //for later script handling
|
|
188
|
-
this.recordTag(tag_check);
|
|
189
|
-
this.tag_type = 'SCRIPT';
|
|
190
|
-
} else if (tag_check === 'style') { //for future style handling (for now it justs uses get_content)
|
|
191
|
-
this.recordTag(tag_check);
|
|
192
|
-
this.tag_type = 'STYLE';
|
|
193
|
-
} else if (tag_check.charAt(0) === '!') { //peek for <!-- comment
|
|
194
|
-
if (tag_check.indexOf('[if') != -1) { //peek for <!--[if conditional comment
|
|
195
|
-
if (tag_complete.indexOf('!IE') != -1) { //this type needs a closing --> so...
|
|
196
|
-
var comment = this.getUnfo(this.regex.commentEnd, tag_complete); //...delegate to get_unformatted
|
|
197
|
-
content.push(comment);
|
|
198
|
-
}
|
|
199
|
-
this.tag_type = 'START';
|
|
200
|
-
} else if (tag_check.indexOf('[endif') != -1) { //peek for <!--[endif end conditional comment
|
|
201
|
-
this.tag_type = 'END';
|
|
202
|
-
this.unindent();
|
|
203
|
-
} else if (tag_check.indexOf('[cdata[') != -1) { //if it's a <[cdata[ comment...
|
|
204
|
-
var comment = this.getUnfo(this.regex.cdataEnd, tag_complete); //...delegate to get_unformatted function
|
|
205
|
-
content.push(comment);
|
|
206
|
-
this.tag_type = 'SINGLE'; //<![CDATA[ comments are treated like single tags
|
|
207
|
-
} else {
|
|
208
|
-
var comment = this.getUnfo('-->', tag_complete);
|
|
209
|
-
content.push(comment);
|
|
210
|
-
this.tag_type = 'SINGLE';
|
|
211
|
-
}
|
|
212
|
-
} else {
|
|
213
|
-
if (tag_check.charAt(0) === '/') { //this tag is a double tag so check for tag-ending
|
|
214
|
-
this.retrieveTag(tag_check.substring(1)); //remove it and all ancestors
|
|
215
|
-
this.tag_type = 'END';
|
|
216
|
-
} else { //otherwise it's a start-tag
|
|
217
|
-
this.recordTag(tag_check); //push it on the tag stack
|
|
218
|
-
this.tag_type = 'START';
|
|
219
|
-
}
|
|
220
|
-
if (this.Utils.in_array(tag_check, this.Utils.extra_liners)) { //check if this double needs an extra line
|
|
221
|
-
this.printNewline(true, this.output);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return content.join(''); //returns fully formatted tag
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
this.getUnfo = function (delimiter, orig_tag) { //function to return unformatted content in its entirety
|
|
228
|
-
|
|
229
|
-
if (orig_tag && orig_tag.indexOf(delimiter) != -1) {
|
|
230
|
-
return '';
|
|
231
|
-
}
|
|
232
|
-
var char = '';
|
|
233
|
-
var content = '';
|
|
234
|
-
var space = true;
|
|
235
|
-
do {
|
|
236
|
-
|
|
237
|
-
char = this.input.charAt(this.pos);
|
|
238
|
-
this.pos++;
|
|
239
|
-
|
|
240
|
-
if (this.Utils.in_array(char, this.Utils.whitespace)) {
|
|
241
|
-
if (!space) {
|
|
242
|
-
this.line_char_count--;
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
if (char === '\n' || char === '\r') {
|
|
246
|
-
content += '\n';
|
|
247
|
-
for (var i = 0; i < this.indent_level; i++) {
|
|
248
|
-
content += this.indent_string;
|
|
249
|
-
}
|
|
250
|
-
space = false; //...and make sure other indentation is erased
|
|
251
|
-
this.line_char_count = 0;
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
content += char;
|
|
256
|
-
this.line_char_count++;
|
|
257
|
-
space = true;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
} while (content.indexOf(delimiter) == -1);
|
|
261
|
-
return content;
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
this.getToken = function () { //initial handler for token-retrieval
|
|
265
|
-
var token;
|
|
266
|
-
|
|
267
|
-
if (this.last_token === 'TK_TAG_SCRIPT') { //check if we need to format javascript
|
|
268
|
-
var token = this.getScript();
|
|
269
|
-
if (typeof temp_token !== 'string') {
|
|
270
|
-
return temp_token;
|
|
271
|
-
}
|
|
272
|
-
token = js_beautify(temp_token, this.indent_size, this.indent_character, this.indent_level); //call the JS Beautifier
|
|
273
|
-
return [token, 'TK_CONTENT'];
|
|
274
|
-
}
|
|
275
|
-
if (this.current_mode === 'CONTENT') {
|
|
276
|
-
token = this.getContent();
|
|
277
|
-
if (typeof token !== 'string') {
|
|
278
|
-
return token;
|
|
279
|
-
} else {
|
|
280
|
-
return [token, 'TK_CONTENT'];
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (this.current_mode === 'TAG') {
|
|
285
|
-
token = this.getTag();
|
|
286
|
-
if (typeof token !== 'string') {
|
|
287
|
-
return token;
|
|
288
|
-
} else {
|
|
289
|
-
var tag_name_type = 'TK_TAG_' + this.tag_type;
|
|
290
|
-
return [token, tag_name_type];
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
this.printer = function (js_source, indent_char, indent_size, max_char) { //handles input/output and some other printing functions
|
|
296
|
-
|
|
297
|
-
this.input = js_source || ''; //gets the input for the Parser
|
|
298
|
-
this.output = [];
|
|
299
|
-
this.indent_character = indent_character || ' ';
|
|
300
|
-
this.indent_string = '';
|
|
301
|
-
this.indent_size = indent_size || 2;
|
|
302
|
-
this.indent_level = 0;
|
|
303
|
-
this.max_char = max_char || 7000; //maximum amount of characters per line
|
|
304
|
-
this.line_char_count = 0; //count to see if max_char was exceeded
|
|
305
|
-
|
|
306
|
-
for (var i = 0; i < this.indent_size; i++) {
|
|
307
|
-
this.indent_string += this.indent_character;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
this.printNewline = function (ignore, arr) {
|
|
311
|
-
this.line_char_count = 0;
|
|
312
|
-
if (!arr || !arr.length) {
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
if (!ignore) { //we might want the extra line
|
|
316
|
-
while (this.Utils.in_array(arr[arr.length - 1], this.Utils.whitespace)) {
|
|
317
|
-
arr.pop();
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
arr.push('\n');
|
|
321
|
-
for (var i = 0; i < this.indent_level; i++) {
|
|
322
|
-
arr.push(this.indent_string);
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
this.printToken = function (text) {
|
|
328
|
-
this.output.push(text);
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
this.indent = function () {
|
|
332
|
-
this.indent_level++;
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
this.unindent = function () {
|
|
336
|
-
if (this.indent_level > 0) {
|
|
337
|
-
this.indent_level--;
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
};
|
|
341
|
-
return this;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/*_____________________--------------------_____________________*/
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
multi_parser = new Parser(); //wrapping functions Parser
|
|
348
|
-
multi_parser.printer(html_source, indent_character, indent_size); //initialize starting values
|
|
349
|
-
|
|
350
|
-
var f = true;
|
|
351
|
-
while (true) {
|
|
352
|
-
var t = multi_parser.get_token();
|
|
353
|
-
multi_parser.token_text = t[0];
|
|
354
|
-
multi_parser.token_type = t[1];
|
|
355
|
-
|
|
356
|
-
if (multi_parser.token_type === 'TK_EOF') {
|
|
357
|
-
break;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
switch (multi_parser.token_type) {
|
|
361
|
-
case 'TK_TAG_START':
|
|
362
|
-
case 'TK_TAG_SCRIPT':
|
|
363
|
-
case 'TK_TAG_STYLE':
|
|
364
|
-
multi_parser.print_newline(false, multi_parser.output);
|
|
365
|
-
multi_parser.print_token(multi_parser.token_text);
|
|
366
|
-
multi_parser.indent();
|
|
367
|
-
multi_parser.current_mode = 'CONTENT';
|
|
368
|
-
break;
|
|
369
|
-
case 'TK_TAG_END':
|
|
370
|
-
if (f)
|
|
371
|
-
multi_parser.print_newline(true, multi_parser.output);
|
|
372
|
-
multi_parser.print_token(multi_parser.token_text);
|
|
373
|
-
multi_parser.current_mode = 'CONTENT';
|
|
374
|
-
f = true;
|
|
375
|
-
break;
|
|
376
|
-
case 'TK_TAG_SINGLE':
|
|
377
|
-
multi_parser.print_newline(false, multi_parser.output);
|
|
378
|
-
multi_parser.print_token(multi_parser.token_text);
|
|
379
|
-
multi_parser.current_mode = 'CONTENT';
|
|
380
|
-
break;
|
|
381
|
-
case 'TK_CONTENT':
|
|
382
|
-
if (multi_parser.token_text !== '') {
|
|
383
|
-
f = false;
|
|
384
|
-
//multi_parser.print_newline(false, multi_parser.output);
|
|
385
|
-
multi_parser.print_token(multi_parser.token_text);
|
|
386
|
-
}
|
|
387
|
-
multi_parser.current_mode = 'TAG';
|
|
388
|
-
break;
|
|
389
|
-
}
|
|
390
|
-
multi_parser.last_token = multi_parser.token_type;
|
|
391
|
-
multi_parser.last_text = multi_parser.token_text;
|
|
392
|
-
}
|
|
393
|
-
return multi_parser.output.join('');
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
module.exports = style_html;
|
package/lang.js
DELETED
package/test.js
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
const Matchs = require('./index.js');
|
|
2
|
-
|
|
3
|
-
async function test() {
|
|
4
|
-
const ms = new Matchs();
|
|
5
|
-
let str = '';
|
|
6
|
-
// 基础匹配测试 OK
|
|
7
|
-
$.log.debug('=== 基础匹配测试 ===');
|
|
8
|
-
str = '职位不对的';
|
|
9
|
-
$.log.debug(str.matchs('*{不对}'));
|
|
10
|
-
|
|
11
|
-
// 数字正则匹配测试 OK
|
|
12
|
-
$.log.debug('\n=== 数字匹配测试 ===');
|
|
13
|
-
$.log.debug('今年28岁了'.matchs('/[0-9]+/'));
|
|
14
|
-
$.log.debug('手机号码是15817188866,哦5646546'.matchs('/[0-9]+/g'));
|
|
15
|
-
|
|
16
|
-
// 通配符匹配测试 OK
|
|
17
|
-
$.log.debug('\n=== 通配符匹配测试 ===');
|
|
18
|
-
str = '我叫文武, 手机号码是1581718881';
|
|
19
|
-
$.log.debug(str.matchs('手机号码*'));
|
|
20
|
-
$.log.debug(str.matchs('*武'));
|
|
21
|
-
|
|
22
|
-
str = '因为如果它是一只鸟,那么它就会飞';
|
|
23
|
-
$.log.debug(str.matchs('它*'));
|
|
24
|
-
$.log.debug(str.matchs('如果*鸟'));
|
|
25
|
-
$.log.debug(str.matchs('如果*就*'));
|
|
26
|
-
$.log.debug(str.matchs('*它*就*'));
|
|
27
|
-
|
|
28
|
-
// 职位匹配测试 OK
|
|
29
|
-
$.log.debug('\n=== 职位匹配测试 ===');
|
|
30
|
-
const JOB_TESTS = [
|
|
31
|
-
'酒店厨师长',
|
|
32
|
-
'宠物美容师',
|
|
33
|
-
'广告设计师',
|
|
34
|
-
'游戏设计总监',
|
|
35
|
-
'软件开发工程师'
|
|
36
|
-
];
|
|
37
|
-
JOB_TESTS.forEach(job => $.log.debug(job.matchs('{职位}')));
|
|
38
|
-
$.log.debug('游戏设计师'.matchs('{中文}'));
|
|
39
|
-
$.log.debug('游戏设计师'.matchs('{职位}'));
|
|
40
|
-
$.log.debug('游戏设计师'.matchs('{中文}{职位}'));
|
|
41
|
-
$.log.debug('游戏设计师'.matchs('[\u4e00-\u9fa5]{2,4}{职位}'));
|
|
42
|
-
$.log.debug('广告设计实习生'.matchs('[\u4e00-\u9fa5]{2,4}{职位}'));
|
|
43
|
-
$.log.debug('广告设计学徒'.matchs('{中文}{2,4}{职位}'));
|
|
44
|
-
|
|
45
|
-
// 日期时间测试
|
|
46
|
-
$.log.debug('\n=== 日期时间测试 ===');
|
|
47
|
-
str = '今天不是我的生日, 我是一九九一年四月一日生的,生日是4月1日';
|
|
48
|
-
$.log.debug(str.matchs('{时态}'));
|
|
49
|
-
$.log.debug(str.matchs('{日期}'));
|
|
50
|
-
$.log.debug(str.matchs('{年月日}'));
|
|
51
|
-
$.log.debug(str.matchs('{月日}'));
|
|
52
|
-
|
|
53
|
-
str = '1991-04-01 12:15:36';
|
|
54
|
-
$.log.debug(str.matchs('{年月日}'));
|
|
55
|
-
$.log.debug(str.matchs('{月日}'));
|
|
56
|
-
$.log.debug(str.matchs('{日期时间}'));
|
|
57
|
-
$.log.debug(str.matchs('{时分}'));
|
|
58
|
-
$.log.debug(str.matchs('{时分秒}'));
|
|
59
|
-
|
|
60
|
-
str = '1991年4月1日,小宝宝诞生了';
|
|
61
|
-
$.log.debug(str.matchs('{年月日}'));
|
|
62
|
-
$.log.debug(str.matchs('{月日}'));
|
|
63
|
-
|
|
64
|
-
str = '1991年04月01日 12时15分36秒';
|
|
65
|
-
$.log.debug(str.matchs('{年月日}'));
|
|
66
|
-
$.log.debug(str.matchs('{月日}'));
|
|
67
|
-
$.log.debug(str.matchs('{日期时间}'));
|
|
68
|
-
$.log.debug(str.matchs('{日期}'));
|
|
69
|
-
$.log.debug(str.matchs('{时间}'));
|
|
70
|
-
$.log.debug(str.matchs('{日期} {时间}'));
|
|
71
|
-
$.log.debug(str.matchs('{时分}'));
|
|
72
|
-
$.log.debug(str.matchs('{时分秒}'));
|
|
73
|
-
|
|
74
|
-
// 周期匹配测试OK
|
|
75
|
-
$.log.debug('\n=== 周期匹配测试 ===');
|
|
76
|
-
const CYCLE_TESTS = [
|
|
77
|
-
'十五天内',
|
|
78
|
-
'10-15天左右',
|
|
79
|
-
'十到十五天内',
|
|
80
|
-
'10至15天内',
|
|
81
|
-
'15号之前',
|
|
82
|
-
'数日内',
|
|
83
|
-
'几个小时后',
|
|
84
|
-
'从现在起几个小时之内'
|
|
85
|
-
];
|
|
86
|
-
CYCLE_TESTS.forEach(cycle => $.log.debug(cycle.matchs('{周期}')));
|
|
87
|
-
|
|
88
|
-
// 手机号码和数字测试 OK
|
|
89
|
-
$.log.debug('\n=== 手机号码和数字测试 ===');
|
|
90
|
-
str = '我叫文武, 手机号码是15817188866';
|
|
91
|
-
$.log.debug(str.matchs('{手机号码}'));
|
|
92
|
-
$.log.debug(str.matchs('{数字}'));
|
|
93
|
-
|
|
94
|
-
// 时间格式测试 OK
|
|
95
|
-
$.log.debug('\n=== 时间格式测试 ===');
|
|
96
|
-
const TIME_TESTS = [
|
|
97
|
-
'现在的时间是十九点三十五分五十九秒',
|
|
98
|
-
'现在的时间是19点35分59秒',
|
|
99
|
-
'现在的时间是19:35:59'
|
|
100
|
-
];
|
|
101
|
-
TIME_TESTS.forEach(time => {
|
|
102
|
-
$.log.debug(time.matchs('{时间}'));
|
|
103
|
-
$.log.debug(time.matchs('{时分秒}'));
|
|
104
|
-
$.log.debug(time.matchs('{时分}'));
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// 其他格式测试 OK
|
|
108
|
-
$.log.debug('\n=== 其他格式测试 ===');
|
|
109
|
-
const OTHER_TESTS = [{
|
|
110
|
-
str: '星期天去哪玩?',
|
|
111
|
-
pattern: '{星期}'
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
str: 'http://www.elins.cn',
|
|
115
|
-
pattern: '{网址}'
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
str: '573242395@qq.com',
|
|
119
|
-
pattern: '{邮箱}'
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
str: '身份证号441423199104018012',
|
|
123
|
-
pattern: '{身份证号}'
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
str: 'QQ号是573242395',
|
|
127
|
-
pattern: '{QQ}'
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
str: 'my name is qww, QQ号是573242395',
|
|
131
|
-
pattern: '{中英文}'
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
str: '我的名字叫文武qww',
|
|
135
|
-
pattern: '{中文或英文}'
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
str: 'Hello World!',
|
|
139
|
-
pattern: '{中英文}'
|
|
140
|
-
},
|
|
141
|
-
];
|
|
142
|
-
OTHER_TESTS.forEach(test => $.log.debug(test.str.matchs(test.pattern)));
|
|
143
|
-
|
|
144
|
-
// HTML标签测试 OK
|
|
145
|
-
$.log.debug('\n=== HTML标签测试 ===');
|
|
146
|
-
str = '<img src="http://www.elins.cn/logo.png" />';
|
|
147
|
-
$.log.debug(str.matchs('{img标签}'));
|
|
148
|
-
$.log.debug(str.matchs('{网址}'));
|
|
149
|
-
$.log.debug(str.matchs('{域名}'));
|
|
150
|
-
str = `这是一个链接<a href="http://www.elins.cn/logo.png">
|
|
151
|
-
<div class="test">你好吗?</div>
|
|
152
|
-
</a>`;
|
|
153
|
-
$.log.debug(str.matchs('{链接}'));
|
|
154
|
-
$.log.debug(str.matchs('{html标签}'));
|
|
155
|
-
$.log.debug(str.matchs('{标签之间}'));
|
|
156
|
-
|
|
157
|
-
// 地理位置测试OK
|
|
158
|
-
$.log.debug('\n=== 地理位置测试 ===');
|
|
159
|
-
str = '广东省深圳市南山区粤海街道在中国南方';
|
|
160
|
-
$.log.debug(str.matchs('{省份}'));
|
|
161
|
-
$.log.debug(str.matchs('{城市}'));
|
|
162
|
-
$.log.debug(str.matchs('{管辖区}'));
|
|
163
|
-
$.log.debug(str.matchs('{方位}'));
|
|
164
|
-
$.log.debug(str.matchs('在*{方位}'));
|
|
165
|
-
$.log.debug(str.matchs('在{国家}'));
|
|
166
|
-
|
|
167
|
-
// 车牌和数字测试OK
|
|
168
|
-
$.log.debug('\n=== 车牌和数字测试 ===');
|
|
169
|
-
$.log.debug('我乘坐的车的车牌号是粤B12312'.matchs('{车牌号}'));
|
|
170
|
-
$.log.debug('圆周率是3.1415926'.matchs('{浮点数}'));
|
|
171
|
-
$.log.debug('圆周率是3.1415926'.matchs('{数值}'));
|
|
172
|
-
$.log.debug('圆周率是3.1415926'.matchs('{数字}'));
|
|
173
|
-
|
|
174
|
-
// 疑问句测试OK
|
|
175
|
-
$.log.debug('\n=== 疑问句测试 ===');
|
|
176
|
-
const QUESTION_TESTS = [
|
|
177
|
-
'做到了什么程度?',
|
|
178
|
-
'买了什么东西?',
|
|
179
|
-
'摸到了什么东西?',
|
|
180
|
-
'获得了什么东西?',
|
|
181
|
-
'想到了什么?',
|
|
182
|
-
'今天天气怎么样?',
|
|
183
|
-
'听见什么没?',
|
|
184
|
-
'你到哪里了?',
|
|
185
|
-
'买到了没?'
|
|
186
|
-
];
|
|
187
|
-
QUESTION_TESTS.forEach(q => $.log.debug(q.matchs('{疑问}')));
|
|
188
|
-
|
|
189
|
-
// 颜色测试OK
|
|
190
|
-
$.log.debug('\n=== 颜色测试 ===');
|
|
191
|
-
const COLOR_TESTS = ['紫红色', '朱红色', '大红大紫', '深红色', '浅绿色', '墨黑色'];
|
|
192
|
-
COLOR_TESTS.forEach(color => $.log.debug(color.matchs('{颜色}')));
|
|
193
|
-
|
|
194
|
-
// 年龄测试OK
|
|
195
|
-
$.log.debug('\n=== 年龄测试 ===');
|
|
196
|
-
const AGE_TESTS = ['年方二八', '28岁了', '十八岁了'];
|
|
197
|
-
AGE_TESTS.forEach(age => $.log.debug(age.matchs('{年龄}')));
|
|
198
|
-
|
|
199
|
-
str = '/user';
|
|
200
|
-
$.log.debug(str.matchs('/user'));
|
|
201
|
-
|
|
202
|
-
str = '/user/1';
|
|
203
|
-
$.log.debug(str.matchs('/user:id'));
|
|
204
|
-
|
|
205
|
-
str = '/user/1';
|
|
206
|
-
$.log.debug(str.matchs('/user/*'));
|
|
207
|
-
|
|
208
|
-
str = '/user/1';
|
|
209
|
-
$.log.debug(str.matchs('/user/'));
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
test();
|