@innoways/drip-form-plugin-keywords 3.0.0
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 +11 -0
- package/dist/cjs/index.js +163 -0
- package/dist/esm/index.js +157 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
6
|
+
|
|
7
|
+
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* @Author: jiangxiaowei
|
|
11
|
+
* @Date: 2021-07-29 19:40:44
|
|
12
|
+
* @Last Modified by: jiangxiaowei
|
|
13
|
+
* @Last Modified time: 2021-08-17 18:40:36
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 针对对string类型的关键字:使用分割符分割之后的最长最短输入校验
|
|
18
|
+
* @schemaKey {string} delimiter 字符串分隔符
|
|
19
|
+
* @schemaKey {number} max 最大长度
|
|
20
|
+
* @schemaKey {number} min 最短长度
|
|
21
|
+
*/
|
|
22
|
+
var rangeDelimiter = function rangeDelimiter(ajv) {
|
|
23
|
+
if (!ajv.getKeyword('rangeDelimiter')) {
|
|
24
|
+
ajv.addKeyword({
|
|
25
|
+
// schema关键字
|
|
26
|
+
keyword: 'rangeDelimiter',
|
|
27
|
+
// 允许的校验类型
|
|
28
|
+
type: 'string',
|
|
29
|
+
// modifying:true,
|
|
30
|
+
// 校验函数
|
|
31
|
+
validate: function validate(schema, data) {
|
|
32
|
+
var delimiter = schema.delimiter,
|
|
33
|
+
max = schema.max,
|
|
34
|
+
min = schema.min;
|
|
35
|
+
var dataList = data.split(delimiter).filter(function (item) {
|
|
36
|
+
return item;
|
|
37
|
+
}).length; // TODO 使用codegen修改data数据
|
|
38
|
+
|
|
39
|
+
return !(dataList > max || dataList < min);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return ajv;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
* @Author: jiangxiaowei
|
|
49
|
+
* @Date: 2022-01-20 19:26:31
|
|
50
|
+
* @Last Modified by: jiangxiaowei
|
|
51
|
+
* @Last Modified time: 2022-01-20 19:48:12
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 计算中文、英文最长最短长度
|
|
56
|
+
* @schemaKey {number} max 最大长度
|
|
57
|
+
* @schemaKey {number} min 最短长度
|
|
58
|
+
*/
|
|
59
|
+
var gbkLength = function gbkLength(ajv) {
|
|
60
|
+
if (!ajv.getKeyword('gbkLength')) {
|
|
61
|
+
ajv.addKeyword({
|
|
62
|
+
// schema关键字
|
|
63
|
+
keyword: 'gbkLength',
|
|
64
|
+
// 允许的校验类型
|
|
65
|
+
type: 'string',
|
|
66
|
+
// modifying:true,
|
|
67
|
+
// 校验函数
|
|
68
|
+
validate: function validate(schema, data) {
|
|
69
|
+
var max = schema.max,
|
|
70
|
+
min = schema.min; // eslint-disable-next-line no-control-regex
|
|
71
|
+
|
|
72
|
+
var len = data.trim().replace(/[^\x00-\xff]/g, 'aa').length;
|
|
73
|
+
|
|
74
|
+
if (min !== undefined && min > len) {
|
|
75
|
+
return false;
|
|
76
|
+
} else if (max !== undefined && max < len) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return ajv;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/*
|
|
89
|
+
* @Author: jiangxiaowei
|
|
90
|
+
* @Date: 2022-01-20 19:26:31
|
|
91
|
+
* @Last Modified by: jiangxiaowei
|
|
92
|
+
* @Last Modified time: 2022-01-20 19:48:12
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 计算中文、英文最长最短长度
|
|
97
|
+
* @schemaKey {number} max 最大长度
|
|
98
|
+
* @schemaKey {number} min 最短长度
|
|
99
|
+
*/
|
|
100
|
+
var dateChecking = function dateChecking(ajv) {
|
|
101
|
+
if (!ajv.getKeyword('dateChecking')) {
|
|
102
|
+
ajv.addKeyword({
|
|
103
|
+
// schema关键字
|
|
104
|
+
keyword: 'dateChecking',
|
|
105
|
+
// 允许的校验类型
|
|
106
|
+
type: 'object',
|
|
107
|
+
// modifying:true,
|
|
108
|
+
// 校验函数
|
|
109
|
+
validate: function validate(schema, data) {
|
|
110
|
+
var earlierDateChecking = schema.earlierDateChecking,
|
|
111
|
+
authModeDateChecking = schema.authModeDateChecking; // // eslint-disable-next-line no-control-regex
|
|
112
|
+
|
|
113
|
+
if (_typeof__default["default"](data) === 'object' && data.self && data[earlierDateChecking]) {
|
|
114
|
+
var from = new Date(data[earlierDateChecking]).getTime();
|
|
115
|
+
var to = new Date(data.self).getTime();
|
|
116
|
+
|
|
117
|
+
if (to <= from && authModeDateChecking === 'lt') {
|
|
118
|
+
return false;
|
|
119
|
+
} else if (to < from && authModeDateChecking === 'lte') {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return ajv;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
var keywords = {
|
|
133
|
+
rangeDelimiter: rangeDelimiter,
|
|
134
|
+
gbkLength: gbkLength,
|
|
135
|
+
dateChecking: dateChecking
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/*
|
|
139
|
+
* addKeywords(ajv) 添加所有keywords
|
|
140
|
+
* addKeywords(ajv,['rangeDelimiter']) 仅添加rangeDelimiter关键字
|
|
141
|
+
* @Author: jiangxiaowei
|
|
142
|
+
* @Date: 2021-07-29 12:56:28
|
|
143
|
+
* @Last Modified by: jiangxiaowei
|
|
144
|
+
* @Last Modified time: 2021-08-17 15:45:38
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
var addKeywords = function addKeywords(ajv, options) {
|
|
148
|
+
if (Array.isArray(options)) {
|
|
149
|
+
Object.keys(keywords).filter(function (item) {
|
|
150
|
+
return options.includes(item);
|
|
151
|
+
}).map(function (item) {
|
|
152
|
+
keywords[item](ajv);
|
|
153
|
+
});
|
|
154
|
+
} else if (!options) {
|
|
155
|
+
Object.keys(keywords).map(function (item) {
|
|
156
|
+
keywords[item](ajv);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return ajv;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
module.exports = addKeywords;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* @Author: jiangxiaowei
|
|
5
|
+
* @Date: 2021-07-29 19:40:44
|
|
6
|
+
* @Last Modified by: jiangxiaowei
|
|
7
|
+
* @Last Modified time: 2021-08-17 18:40:36
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 针对对string类型的关键字:使用分割符分割之后的最长最短输入校验
|
|
12
|
+
* @schemaKey {string} delimiter 字符串分隔符
|
|
13
|
+
* @schemaKey {number} max 最大长度
|
|
14
|
+
* @schemaKey {number} min 最短长度
|
|
15
|
+
*/
|
|
16
|
+
var rangeDelimiter = function rangeDelimiter(ajv) {
|
|
17
|
+
if (!ajv.getKeyword('rangeDelimiter')) {
|
|
18
|
+
ajv.addKeyword({
|
|
19
|
+
// schema关键字
|
|
20
|
+
keyword: 'rangeDelimiter',
|
|
21
|
+
// 允许的校验类型
|
|
22
|
+
type: 'string',
|
|
23
|
+
// modifying:true,
|
|
24
|
+
// 校验函数
|
|
25
|
+
validate: function validate(schema, data) {
|
|
26
|
+
var delimiter = schema.delimiter,
|
|
27
|
+
max = schema.max,
|
|
28
|
+
min = schema.min;
|
|
29
|
+
var dataList = data.split(delimiter).filter(function (item) {
|
|
30
|
+
return item;
|
|
31
|
+
}).length; // TODO 使用codegen修改data数据
|
|
32
|
+
|
|
33
|
+
return !(dataList > max || dataList < min);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return ajv;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* @Author: jiangxiaowei
|
|
43
|
+
* @Date: 2022-01-20 19:26:31
|
|
44
|
+
* @Last Modified by: jiangxiaowei
|
|
45
|
+
* @Last Modified time: 2022-01-20 19:48:12
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 计算中文、英文最长最短长度
|
|
50
|
+
* @schemaKey {number} max 最大长度
|
|
51
|
+
* @schemaKey {number} min 最短长度
|
|
52
|
+
*/
|
|
53
|
+
var gbkLength = function gbkLength(ajv) {
|
|
54
|
+
if (!ajv.getKeyword('gbkLength')) {
|
|
55
|
+
ajv.addKeyword({
|
|
56
|
+
// schema关键字
|
|
57
|
+
keyword: 'gbkLength',
|
|
58
|
+
// 允许的校验类型
|
|
59
|
+
type: 'string',
|
|
60
|
+
// modifying:true,
|
|
61
|
+
// 校验函数
|
|
62
|
+
validate: function validate(schema, data) {
|
|
63
|
+
var max = schema.max,
|
|
64
|
+
min = schema.min; // eslint-disable-next-line no-control-regex
|
|
65
|
+
|
|
66
|
+
var len = data.trim().replace(/[^\x00-\xff]/g, 'aa').length;
|
|
67
|
+
|
|
68
|
+
if (min !== undefined && min > len) {
|
|
69
|
+
return false;
|
|
70
|
+
} else if (max !== undefined && max < len) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return ajv;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* @Author: jiangxiaowei
|
|
84
|
+
* @Date: 2022-01-20 19:26:31
|
|
85
|
+
* @Last Modified by: jiangxiaowei
|
|
86
|
+
* @Last Modified time: 2022-01-20 19:48:12
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 计算中文、英文最长最短长度
|
|
91
|
+
* @schemaKey {number} max 最大长度
|
|
92
|
+
* @schemaKey {number} min 最短长度
|
|
93
|
+
*/
|
|
94
|
+
var dateChecking = function dateChecking(ajv) {
|
|
95
|
+
if (!ajv.getKeyword('dateChecking')) {
|
|
96
|
+
ajv.addKeyword({
|
|
97
|
+
// schema关键字
|
|
98
|
+
keyword: 'dateChecking',
|
|
99
|
+
// 允许的校验类型
|
|
100
|
+
type: 'object',
|
|
101
|
+
// modifying:true,
|
|
102
|
+
// 校验函数
|
|
103
|
+
validate: function validate(schema, data) {
|
|
104
|
+
var earlierDateChecking = schema.earlierDateChecking,
|
|
105
|
+
authModeDateChecking = schema.authModeDateChecking; // // eslint-disable-next-line no-control-regex
|
|
106
|
+
|
|
107
|
+
if (_typeof(data) === 'object' && data.self && data[earlierDateChecking]) {
|
|
108
|
+
var from = new Date(data[earlierDateChecking]).getTime();
|
|
109
|
+
var to = new Date(data.self).getTime();
|
|
110
|
+
|
|
111
|
+
if (to <= from && authModeDateChecking === 'lt') {
|
|
112
|
+
return false;
|
|
113
|
+
} else if (to < from && authModeDateChecking === 'lte') {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return ajv;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
var keywords = {
|
|
127
|
+
rangeDelimiter: rangeDelimiter,
|
|
128
|
+
gbkLength: gbkLength,
|
|
129
|
+
dateChecking: dateChecking
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/*
|
|
133
|
+
* addKeywords(ajv) 添加所有keywords
|
|
134
|
+
* addKeywords(ajv,['rangeDelimiter']) 仅添加rangeDelimiter关键字
|
|
135
|
+
* @Author: jiangxiaowei
|
|
136
|
+
* @Date: 2021-07-29 12:56:28
|
|
137
|
+
* @Last Modified by: jiangxiaowei
|
|
138
|
+
* @Last Modified time: 2021-08-17 15:45:38
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
var addKeywords = function addKeywords(ajv, options) {
|
|
142
|
+
if (Array.isArray(options)) {
|
|
143
|
+
Object.keys(keywords).filter(function (item) {
|
|
144
|
+
return options.includes(item);
|
|
145
|
+
}).map(function (item) {
|
|
146
|
+
keywords[item](ajv);
|
|
147
|
+
});
|
|
148
|
+
} else if (!options) {
|
|
149
|
+
Object.keys(keywords).map(function (item) {
|
|
150
|
+
keywords[item](ajv);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return ajv;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export { addKeywords as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@innoways/drip-form-plugin-keywords",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "drip-form ajv关键字插件",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ajv",
|
|
7
|
+
"drip-form"
|
|
8
|
+
],
|
|
9
|
+
"author": "JDFED",
|
|
10
|
+
"homepage": "https://github.com/JDFED/drip-form/",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"main": "dist/cjs/index.js",
|
|
13
|
+
"types": "dist/esm/index.d.ts",
|
|
14
|
+
"module": "dist/esm/index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"link": "yarn link",
|
|
20
|
+
"build": "rollup --config --sourcemap",
|
|
21
|
+
"watch": "rollup --config --watch"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"registry": "https://registry.npmjs.org/",
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "github",
|
|
29
|
+
"url": "https://github.com/JDFED/drip-form/"
|
|
30
|
+
},
|
|
31
|
+
"distExports": {
|
|
32
|
+
"dist": "./dist",
|
|
33
|
+
"build-info": "./build-info",
|
|
34
|
+
"format": [
|
|
35
|
+
"esm",
|
|
36
|
+
"cjs"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@babel/runtime": "^7.10.2"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"ajv": "^8.6.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"ajv": "^8.6.2"
|
|
47
|
+
}
|
|
48
|
+
}
|