mm_matchs 1.1.8 → 1.1.10
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 +125 -125
- package/eslint.config.js +106 -0
- package/html.js +220 -220
- package/htmlformat.js +391 -395
- package/index.js +340 -311
- package/package.json +4 -2
- package/regex.js +80 -80
- package/test.js +206 -206
- package/test_html.js +2284 -2284
- package/index copy.js +0 -897
package/README.md
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
# mm_matchs
|
|
2
|
-
|
|
3
|
-
这是一个用于匹配复杂字符串结构的Node.js模块,提供了丰富的字符串匹配功能,可以匹配前缀包含、后缀包含、以及时间、地点等多种模式。
|
|
4
|
-
|
|
5
|
-
## 特点
|
|
6
|
-
|
|
7
|
-
- 支持多种匹配模式:前缀匹配、后缀匹配、正则匹配等
|
|
8
|
-
- 内置丰富的匹配规则:时间、日期、地点、网址等
|
|
9
|
-
- 使用简单,支持链式调用
|
|
10
|
-
- 可扩展性强,支持自定义匹配规则
|
|
11
|
-
|
|
12
|
-
## 安装
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npm install mm_matchs
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## 基础用法
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
const Matchs = require('mm_matchs');
|
|
22
|
-
const ms = new Matchs();
|
|
23
|
-
|
|
24
|
-
// 使用String原型扩展方法
|
|
25
|
-
const str = "我叫文武, 手机号码是15817188866";
|
|
26
|
-
|
|
27
|
-
// 前缀匹配
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// 后缀匹配
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// 区间匹配
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## 内置匹配规则
|
|
38
|
-
|
|
39
|
-
### 时间日期类
|
|
40
|
-
|
|
41
|
-
```javascript
|
|
42
|
-
// 匹配日期时间
|
|
43
|
-
str = "1991-04-01 12:15:36";
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// 匹配年月日
|
|
47
|
-
str = "1991年4月1日";
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// 匹配时间
|
|
51
|
-
str = "现在的时间是19:35:59";
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### 地理位置类
|
|
56
|
-
|
|
57
|
-
```javascript
|
|
58
|
-
// 匹配省份
|
|
59
|
-
str = "广东省深圳市南山区";
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// 匹配城市
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// 匹配方位
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### 网络通信类
|
|
70
|
-
|
|
71
|
-
```javascript
|
|
72
|
-
// 匹配网址
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// 匹配邮箱
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// 匹配手机号码
|
|
79
|
-
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### 其他常用匹配
|
|
83
|
-
|
|
84
|
-
```javascript
|
|
85
|
-
// 匹配身份证号
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// 匹配车牌号
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// 匹配中英文
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## API文档
|
|
96
|
-
|
|
97
|
-
### 主要方法
|
|
98
|
-
|
|
99
|
-
- `matchs(pattern)`: 字符串匹配方法,支持通配符和预定义规则
|
|
100
|
-
- `tense(str, format)`: 匹配时态
|
|
101
|
-
- `bearing(str, format)`: 匹配方位
|
|
102
|
-
- `province(str, format)`: 匹配省份
|
|
103
|
-
- `city(str, format)`: 匹配城市
|
|
104
|
-
|
|
105
|
-
### 预定义规则
|
|
106
|
-
|
|
107
|
-
模块内置了多种匹配规则,使用花括号`{}`包裹规则名称:
|
|
108
|
-
|
|
109
|
-
- `{日期时间}`: 匹配日期时间格式
|
|
110
|
-
- `{日期}`: 匹配日期
|
|
111
|
-
- `{时间}`: 匹配时间
|
|
112
|
-
- `{网址}`: 匹配URL
|
|
113
|
-
- `{邮箱}`: 匹配电子邮箱
|
|
114
|
-
- `{手机号码}`: 匹配手机号
|
|
115
|
-
- `{身份证号}`: 匹配身份证号码
|
|
116
|
-
- `{车牌号}`: 匹配车牌号
|
|
117
|
-
- `{中英文}`: 匹配中英文混合
|
|
118
|
-
|
|
119
|
-
## 许可证
|
|
120
|
-
|
|
121
|
-
ISC License
|
|
122
|
-
|
|
123
|
-
## 作者
|
|
124
|
-
|
|
125
|
-
qww
|
|
1
|
+
# mm_matchs
|
|
2
|
+
|
|
3
|
+
这是一个用于匹配复杂字符串结构的Node.js模块,提供了丰富的字符串匹配功能,可以匹配前缀包含、后缀包含、以及时间、地点等多种模式。
|
|
4
|
+
|
|
5
|
+
## 特点
|
|
6
|
+
|
|
7
|
+
- 支持多种匹配模式:前缀匹配、后缀匹配、正则匹配等
|
|
8
|
+
- 内置丰富的匹配规则:时间、日期、地点、网址等
|
|
9
|
+
- 使用简单,支持链式调用
|
|
10
|
+
- 可扩展性强,支持自定义匹配规则
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install mm_matchs
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 基础用法
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const Matchs = require('mm_matchs');
|
|
22
|
+
const ms = new Matchs();
|
|
23
|
+
|
|
24
|
+
// 使用String原型扩展方法
|
|
25
|
+
const str = "我叫文武, 手机号码是15817188866";
|
|
26
|
+
|
|
27
|
+
// 前缀匹配
|
|
28
|
+
$.log.debug(str.matchs('手机号码*')); // 15817188866
|
|
29
|
+
|
|
30
|
+
// 后缀匹配
|
|
31
|
+
$.log.debug(str.matchs('*武')); // 文武
|
|
32
|
+
|
|
33
|
+
// 区间匹配
|
|
34
|
+
$.log.debug(str.matchs('如果*就*')); // 匹配两个通配符之间的内容
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 内置匹配规则
|
|
38
|
+
|
|
39
|
+
### 时间日期类
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
// 匹配日期时间
|
|
43
|
+
str = "1991-04-01 12:15:36";
|
|
44
|
+
$.log.debug(str.matchs('{日期时间}'));
|
|
45
|
+
|
|
46
|
+
// 匹配年月日
|
|
47
|
+
str = "1991年4月1日";
|
|
48
|
+
$.log.debug(str.matchs('{年月日}'));
|
|
49
|
+
|
|
50
|
+
// 匹配时间
|
|
51
|
+
str = "现在的时间是19:35:59";
|
|
52
|
+
$.log.debug(str.matchs('{时间}'));
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 地理位置类
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
// 匹配省份
|
|
59
|
+
str = "广东省深圳市南山区";
|
|
60
|
+
$.log.debug(str.matchs('{省份}'));
|
|
61
|
+
|
|
62
|
+
// 匹配城市
|
|
63
|
+
$.log.debug(str.matchs('{城市}'));
|
|
64
|
+
|
|
65
|
+
// 匹配方位
|
|
66
|
+
$.log.debug(str.matchs('{方位}'));
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 网络通信类
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
// 匹配网址
|
|
73
|
+
$.log.debug("http://www.example.com".matchs('{网址}'));
|
|
74
|
+
|
|
75
|
+
// 匹配邮箱
|
|
76
|
+
$.log.debug("test@example.com".matchs('{邮箱}'));
|
|
77
|
+
|
|
78
|
+
// 匹配手机号码
|
|
79
|
+
$.log.debug("13812345678".matchs('{手机号码}'));
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 其他常用匹配
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
// 匹配身份证号
|
|
86
|
+
$.log.debug("440123199001011234".matchs('{身份证号}'));
|
|
87
|
+
|
|
88
|
+
// 匹配车牌号
|
|
89
|
+
$.log.debug("粤B12345".matchs('{车牌号}'));
|
|
90
|
+
|
|
91
|
+
// 匹配中英文
|
|
92
|
+
$.log.debug("Hello世界".matchs('{中英文}'));
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## API文档
|
|
96
|
+
|
|
97
|
+
### 主要方法
|
|
98
|
+
|
|
99
|
+
- `matchs(pattern)`: 字符串匹配方法,支持通配符和预定义规则
|
|
100
|
+
- `tense(str, format)`: 匹配时态
|
|
101
|
+
- `bearing(str, format)`: 匹配方位
|
|
102
|
+
- `province(str, format)`: 匹配省份
|
|
103
|
+
- `city(str, format)`: 匹配城市
|
|
104
|
+
|
|
105
|
+
### 预定义规则
|
|
106
|
+
|
|
107
|
+
模块内置了多种匹配规则,使用花括号`{}`包裹规则名称:
|
|
108
|
+
|
|
109
|
+
- `{日期时间}`: 匹配日期时间格式
|
|
110
|
+
- `{日期}`: 匹配日期
|
|
111
|
+
- `{时间}`: 匹配时间
|
|
112
|
+
- `{网址}`: 匹配URL
|
|
113
|
+
- `{邮箱}`: 匹配电子邮箱
|
|
114
|
+
- `{手机号码}`: 匹配手机号
|
|
115
|
+
- `{身份证号}`: 匹配身份证号码
|
|
116
|
+
- `{车牌号}`: 匹配车牌号
|
|
117
|
+
- `{中英文}`: 匹配中英文混合
|
|
118
|
+
|
|
119
|
+
## 许可证
|
|
120
|
+
|
|
121
|
+
ISC License
|
|
122
|
+
|
|
123
|
+
## 作者
|
|
124
|
+
|
|
125
|
+
qww
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const mmEslint = require('mm_eslint');
|
|
2
|
+
const jsdoc = require('eslint-plugin-jsdoc');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 基于个人规则的ESLint配置
|
|
6
|
+
* 符合最新ESLint Flat Config格式
|
|
7
|
+
*/
|
|
8
|
+
module.exports = [
|
|
9
|
+
{
|
|
10
|
+
name: 'mos/base',
|
|
11
|
+
files: ['**/*.js'],
|
|
12
|
+
ignores: [
|
|
13
|
+
'**/node_modules/**',
|
|
14
|
+
'eslint.config.js',
|
|
15
|
+
'tests/**',
|
|
16
|
+
'regex.js',
|
|
17
|
+
'test.js'
|
|
18
|
+
],
|
|
19
|
+
languageOptions: {
|
|
20
|
+
ecmaVersion: 'latest',
|
|
21
|
+
sourceType: 'module'
|
|
22
|
+
},
|
|
23
|
+
plugins: {
|
|
24
|
+
mm_eslint: {
|
|
25
|
+
rules: mmEslint
|
|
26
|
+
},
|
|
27
|
+
jsdoc: jsdoc
|
|
28
|
+
},
|
|
29
|
+
rules: {
|
|
30
|
+
'mm_eslint/class-name': 'error', // 类名命名规则
|
|
31
|
+
'mm_eslint/class-instance-name': 'error', // 类实例名命名规则
|
|
32
|
+
'mm_eslint/function-name': 'error', // 函数(方法)名命名规则
|
|
33
|
+
'mm_eslint/object-name': 'error', // 对象名命名规则
|
|
34
|
+
'mm_eslint/param-name': 'error', // 参数名命名规则
|
|
35
|
+
'mm_eslint/variable-name': 'error', // 变量名命名规则
|
|
36
|
+
'mm_eslint/constant-name': 'error', // 常量名命名规则
|
|
37
|
+
|
|
38
|
+
// 代码风格规则
|
|
39
|
+
'max-len': ['error', {
|
|
40
|
+
code: 100,
|
|
41
|
+
ignoreComments: true,
|
|
42
|
+
ignoreUrls: true,
|
|
43
|
+
ignoreStrings: true,
|
|
44
|
+
ignoreTemplateLiterals: true
|
|
45
|
+
}],
|
|
46
|
+
'indent': ['error', 2, {
|
|
47
|
+
SwitchCase: 1,
|
|
48
|
+
VariableDeclarator: 1,
|
|
49
|
+
outerIIFEBody: 1,
|
|
50
|
+
MemberExpression: 1,
|
|
51
|
+
FunctionDeclaration: { parameters: 1, body: 1 },
|
|
52
|
+
FunctionExpression: { parameters: 1, body: 1 },
|
|
53
|
+
CallExpression: { arguments: 1 },
|
|
54
|
+
ArrayExpression: 1,
|
|
55
|
+
ObjectExpression: 1,
|
|
56
|
+
ImportDeclaration: 1
|
|
57
|
+
}],
|
|
58
|
+
'quotes': ['error', 'single', {
|
|
59
|
+
avoidEscape: true,
|
|
60
|
+
allowTemplateLiterals: true
|
|
61
|
+
}],
|
|
62
|
+
'no-tabs': 'error',
|
|
63
|
+
'semi': ['error', 'always'],
|
|
64
|
+
'comma-style': ['error', 'last'],
|
|
65
|
+
'comma-spacing': ['error', { before: false, after: true }],
|
|
66
|
+
|
|
67
|
+
// 错误处理规则
|
|
68
|
+
'no-unused-vars': ['error', {
|
|
69
|
+
args: 'none',
|
|
70
|
+
caughtErrors: 'all',
|
|
71
|
+
ignoreRestSiblings: true
|
|
72
|
+
}],
|
|
73
|
+
'no-unsafe-finally': 'warn',
|
|
74
|
+
'no-throw-literal': 'error',
|
|
75
|
+
|
|
76
|
+
// 最佳实践规则
|
|
77
|
+
'prefer-promise-reject-errors': 'error',
|
|
78
|
+
'no-param-reassign': ['error', {
|
|
79
|
+
props: true,
|
|
80
|
+
ignorePropertyModificationsFor: [
|
|
81
|
+
'acc', 'accumulator', 'e', '$', 'db', 'ctx', 'target', 'self',
|
|
82
|
+
'context', 'req', 'request', 'res', 'response', 'ret', 'msg', 'query', 'body', 'model', 'o', 'm', 'player', 'entity',
|
|
83
|
+
'$scope', 'staticContext'
|
|
84
|
+
]
|
|
85
|
+
}],
|
|
86
|
+
'prefer-object-spread': 'error',
|
|
87
|
+
'prefer-arrow-callback': 'error',
|
|
88
|
+
'max-lines-per-function': ['warn', {
|
|
89
|
+
max: 40,
|
|
90
|
+
skipBlankLines: true,
|
|
91
|
+
skipComments: true
|
|
92
|
+
}],
|
|
93
|
+
'complexity': ['warn', 10],
|
|
94
|
+
|
|
95
|
+
// JSDoc规则
|
|
96
|
+
'jsdoc/check-alignment': 'warn',
|
|
97
|
+
'jsdoc/check-indentation': 'warn',
|
|
98
|
+
'jsdoc/check-param-names': 'warn',
|
|
99
|
+
'jsdoc/check-syntax': 'warn',
|
|
100
|
+
'jsdoc/check-tag-names': 'warn',
|
|
101
|
+
'jsdoc/check-types': 'warn',
|
|
102
|
+
'jsdoc/no-undefined-types': 'warn',
|
|
103
|
+
'jsdoc/require-description': 'warn',
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
];
|