mm_matchs 1.1.0 → 1.1.2

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.
Files changed (3) hide show
  1. package/index.js +14 -3
  2. package/package.json +36 -36
  3. package/test.js +14 -4
package/index.js CHANGED
@@ -37,6 +37,7 @@ class Matchs {
37
37
  "{职位}": "job",
38
38
 
39
39
  "{网址}": "url",
40
+ "{域名}": "web",
40
41
  "{邮箱}": "email",
41
42
  "{账号}": "account",
42
43
  "{强账号}": "account_advanced",
@@ -58,7 +59,6 @@ class Matchs {
58
59
  "{数值}": "number",
59
60
  "{浮点数}": "float",
60
61
 
61
-
62
62
  "{IP}": "ip",
63
63
  "{QQ}": "qq",
64
64
  "{a标签}": "a_tag",
@@ -435,6 +435,17 @@ Matchs.prototype.post_code = function(str, format) {
435
435
  return change(str, format, rx, '{邮政编码}');
436
436
  };
437
437
 
438
+ /**
439
+ * 匹配{域名}
440
+ * @param {String} str 匹配的字符串
441
+ * @param {String} format 匹配格式
442
+ * @return {String} 返回新的格式
443
+ */
444
+ Matchs.prototype.web = function(str, format) {
445
+ var rx = /((https|http|ftp|rtsp|mms)?:\/\/)?[a-zA-Z0-9_\-.]+/;
446
+ return change(str, format, rx, '{域名}').replace(/((https|http|ftp|rtsp|mms)?:\/\/)?/, "");
447
+ };
448
+
438
449
  /**
439
450
  * 匹配{网址}
440
451
  * @param {String} str 匹配的字符串
@@ -442,7 +453,7 @@ Matchs.prototype.post_code = function(str, format) {
442
453
  * @return {String} 返回新的格式
443
454
  */
444
455
  Matchs.prototype.url = function(str, format) {
445
- var rx = /((https|http|ftp|rtsp|mms)?:\/\/)[a-zA-Z0-9/.%&#:?]+/;
456
+ var rx = /((https|http|ftp|rtsp|mms)?:\/\/)?[a-zA-Z0-9_\-.]+[/a-zA-Z0-9_\-]+\/?\??[a-zA-Z0-9_\-.=&%]*/;
446
457
  return change(str, format, rx, '{网址}');
447
458
  };
448
459
 
@@ -784,7 +795,7 @@ String.prototype.matchs = function(format) {
784
795
  f = matchs.get(this, format);
785
796
  }
786
797
 
787
- f = '/' + f.replace(/\//g, '\\/').replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/\*/g, '.*') + '/';
798
+ f = '/' + f.replace(/\//g, '\\/').replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/\*/g, '.*').replace(/\?/g, '\\?') + '/';
788
799
 
789
800
  try {
790
801
  rx = eval(f);
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "mm_matchs",
3
- "version": "1.1.0",
4
- "description": "这是用来匹配复杂的字符串结构的函数,可以匹配前缀包含、后缀包含、以及时间、地点等",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "node test.js"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/qiuwenwu/mm_matchs.git"
12
- },
13
- "keywords": [
14
- "myhttp",
15
- "async",
16
- "await",
17
- "promise",
18
- "add",
19
- "del",
20
- "set",
21
- "get",
22
- "query",
23
- "run",
24
- "exec"
25
- ],
26
- "author": "邱文武",
27
- "license": "ISC",
28
- "bugs": {
29
- "url": "https://github.com/qiuwenwu/mm_matchs/issues"
30
- },
31
- "homepage": "https://github.com/qiuwenwu/mm_matchs#readme",
32
- "dependencies": {
33
- "mm_expand": "^1.4.5"
34
- },
35
- "devDependencies": {}
36
- }
1
+ {
2
+ "name": "mm_matchs",
3
+ "version": "1.1.2",
4
+ "description": "这是用来匹配复杂的字符串结构的函数,可以匹配前缀包含、后缀包含、以及时间、地点等",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "dev": "nodemon test.js",
8
+ "test": "node test.js"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/qiuwenwu/mm_matchs.git"
13
+ },
14
+ "keywords": [
15
+ "myhttp",
16
+ "async",
17
+ "await",
18
+ "promise",
19
+ "add",
20
+ "del",
21
+ "set",
22
+ "get",
23
+ "query",
24
+ "run",
25
+ "exec"
26
+ ],
27
+ "author": "邱文武",
28
+ "license": "ISC",
29
+ "bugs": {
30
+ "url": "https://github.com/qiuwenwu/mm_matchs/issues"
31
+ },
32
+ "homepage": "https://github.com/qiuwenwu/mm_matchs#readme",
33
+ "dependencies": {
34
+ "mm_expand": "^1.5.1"
35
+ }
36
+ }
package/test.js CHANGED
@@ -31,11 +31,21 @@ var str = '职位不对';
31
31
  // console.log("游戏设计师".matchs('[\u4e00-\u9fa5]{2}{职位}'));
32
32
  // console.log("广告设计实习生".matchs('[\u4e00-\u9fa5]{1,2}{职位}'));
33
33
 
34
- // str = "今天不是我的生日, 我是1991-04-01日生的,生日是4月1日";
35
- str = "今天不是我的生日, 我是一九九一年四月一日生的,生日是4月1日";
34
+ // // str = "今天不是我的生日, 我是1991-04-01日生的,生日是4月1日";
35
+ // str = "今天不是我的生日, 我是一九九一年四月一日生的,生日是4月1日";
36
36
 
37
- console.log(str.matchs('{时态}'));
38
- console.log(str.matchs('{日期}'));
37
+ // console.log(str.matchs('{时态}'));
38
+ // console.log(str.matchs('{日期}'));
39
+
40
+ // console.log("梅州市丰顺县汤坑镇金溪村150号".matchs('*村'));
41
+
42
+ // console.log("http://www.baidu.com".matchs('{网址}'));
43
+ // console.log("www.baidu.com".matchs('{网址}'));
44
+ console.log("http://www.baidu.com/?test=demo&keyword=isay中华任命功获".matchs('{网址}'));
45
+ console.log("http://www.baidu.com/ad/city?test=demo&keyword=isay中华任命功获".matchs('{网址}'));
46
+ console.log("http://www.baidu.com/ad/city?".matchs('{网址}'));
47
+ console.log("http://www.baidu.com/ad/city".matchs('{网址}'));
48
+ console.log("http://www.baidu.com/ad/city/".matchs('{网址}'));
39
49
 
40
50
  // str = "1991-04-01 12:15:36";
41
51
  // console.log(str.matchs('{日期时间}'));