@heking.wu/validate 1.0.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 +391 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.es.js +147 -0
- package/dist/index.umd.js +1 -0
- package/package.json +29 -0
package/README.MD
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
# @heking.wu/validate
|
|
2
|
+
|
|
3
|
+
🚀 一个轻量、零依赖的 JavaScript 校验工具库,提供常见数据格式验证函数,支持 **ESM / CJS** 使用方式,适用于 Web、Node.js 等多种场景。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# 📦 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @heking.wu/validate
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
或:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @heking.wu/validate
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
或:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @heking.wu/validate
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
# 🔥 使用方式
|
|
28
|
+
|
|
29
|
+
## ESM(推荐)
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { email, mobile } from "@heking.wu/validate";
|
|
33
|
+
|
|
34
|
+
email("test@example.com"); // true
|
|
35
|
+
mobile("13800000000"); // true
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## CommonJS
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
const { email, mobile } = require("@heking.wu/validate");
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
# ✅ API 文档
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 📧 email(value)
|
|
53
|
+
|
|
54
|
+
验证电子邮箱格式。
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
email("test@example.com"); // true
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 📱 mobile(value)
|
|
63
|
+
|
|
64
|
+
验证中国大陆手机号。
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
mobile("13800000000"); // true
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 🌐 url(value)
|
|
73
|
+
|
|
74
|
+
验证 URL 地址。
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
url("https://example.com"); // true
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 📅 date(value)
|
|
83
|
+
|
|
84
|
+
验证是否为有效日期(支持时间戳)。
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
date("2024-01-01"); // true
|
|
88
|
+
date(1704067200000); // true
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 🧾 dateISO(value)
|
|
94
|
+
|
|
95
|
+
验证 ISO 日期格式:
|
|
96
|
+
|
|
97
|
+
- `YYYY-MM-DD`
|
|
98
|
+
- `YYYY/MM/DD`
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
dateISO("2024-01-01"); // true
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## 🔢 number(value)
|
|
107
|
+
|
|
108
|
+
验证是否为十进制数字。
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
number("3.14"); // true
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 🔤 string(value)
|
|
117
|
+
|
|
118
|
+
是否为字符串。
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
string("hello"); // true
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 🔢 digits(value)
|
|
127
|
+
|
|
128
|
+
是否为整数(仅数字)。
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
digits("123456"); // true
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 🪪 idCard(value)
|
|
137
|
+
|
|
138
|
+
验证中国身份证号码。
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
idCard("110101199003071234"); // true
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 🚗 carNo(value)
|
|
147
|
+
|
|
148
|
+
验证车牌号(支持新能源)。
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
carNo("京A12345"); // true
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 💰 amount(value)
|
|
157
|
+
|
|
158
|
+
验证金额格式(最多 2 位小数)。
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
amount("99.99"); // true
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 🇨🇳 chinese(value)
|
|
167
|
+
|
|
168
|
+
是否仅包含中文字符。
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
chinese("你好"); // true
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 🔠 letter(value)
|
|
177
|
+
|
|
178
|
+
是否仅包含字母。
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
letter("abc"); // true
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## 🔡 enOrNum(value)
|
|
187
|
+
|
|
188
|
+
是否为字母或数字。
|
|
189
|
+
|
|
190
|
+
```js
|
|
191
|
+
enOrNum("abc123"); // true
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## 🔍 contains(value, param)
|
|
197
|
+
|
|
198
|
+
是否包含指定值。
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
contains("hello world", "world"); // true
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## 📏 range(value, [min, max])
|
|
207
|
+
|
|
208
|
+
验证数值范围(闭区间)。
|
|
209
|
+
|
|
210
|
+
```js
|
|
211
|
+
range(5, [1, 10]); // true
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## 📐 rangeLength(value, [min, max])
|
|
217
|
+
|
|
218
|
+
验证字符串或数组长度范围。
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
rangeLength("hello", [1, 10]); // true
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## ☎️ landline(value)
|
|
227
|
+
|
|
228
|
+
验证固定电话。
|
|
229
|
+
|
|
230
|
+
```js
|
|
231
|
+
landline("010-12345678"); // true
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## 🧹 empty(value)
|
|
237
|
+
|
|
238
|
+
判断是否为空,支持:
|
|
239
|
+
|
|
240
|
+
- undefined
|
|
241
|
+
- null
|
|
242
|
+
- 空字符串
|
|
243
|
+
- 0
|
|
244
|
+
- NaN
|
|
245
|
+
- 空数组
|
|
246
|
+
- 空对象
|
|
247
|
+
|
|
248
|
+
```js
|
|
249
|
+
empty(""); // true
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## 🧠 jsonString(value)
|
|
255
|
+
|
|
256
|
+
是否为合法 JSON 字符串。
|
|
257
|
+
|
|
258
|
+
```js
|
|
259
|
+
jsonString('{"name":"test"}'); // true
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## 📚 array(value)
|
|
265
|
+
|
|
266
|
+
是否为数组。
|
|
267
|
+
|
|
268
|
+
```js
|
|
269
|
+
array([]); // true
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## 🧱 object(value)
|
|
275
|
+
|
|
276
|
+
是否为普通对象。
|
|
277
|
+
|
|
278
|
+
```js
|
|
279
|
+
object({}); // true
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## 🔐 code(value, len = 6)
|
|
285
|
+
|
|
286
|
+
验证短信验证码(默认 6 位数字)。
|
|
287
|
+
|
|
288
|
+
```js
|
|
289
|
+
code("123456"); // true
|
|
290
|
+
code("1234", 4); // true
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## ⚙️ func(value)
|
|
296
|
+
|
|
297
|
+
是否为函数。
|
|
298
|
+
|
|
299
|
+
```js
|
|
300
|
+
func(() => {}); // true
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## ⏳ promise(value)
|
|
306
|
+
|
|
307
|
+
是否为 Promise 对象。
|
|
308
|
+
|
|
309
|
+
```js
|
|
310
|
+
promise(fetch("/api")); // true
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## 🖼️ image(value)
|
|
316
|
+
|
|
317
|
+
是否为图片格式:
|
|
318
|
+
|
|
319
|
+
支持:
|
|
320
|
+
|
|
321
|
+
- jpg
|
|
322
|
+
- jpeg
|
|
323
|
+
- png
|
|
324
|
+
- gif
|
|
325
|
+
- svg
|
|
326
|
+
- webp
|
|
327
|
+
- bmp
|
|
328
|
+
- jfif 等
|
|
329
|
+
|
|
330
|
+
```js
|
|
331
|
+
image("test.png"); // true
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## 🎬 video(value)
|
|
337
|
+
|
|
338
|
+
是否为视频格式:
|
|
339
|
+
|
|
340
|
+
支持:
|
|
341
|
+
|
|
342
|
+
- mp4
|
|
343
|
+
- mov
|
|
344
|
+
- m3u8
|
|
345
|
+
- avi
|
|
346
|
+
- mkv 等
|
|
347
|
+
|
|
348
|
+
```js
|
|
349
|
+
video("demo.mp4"); // true
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## 🧩 regExp(value)
|
|
355
|
+
|
|
356
|
+
是否为正则对象。
|
|
357
|
+
|
|
358
|
+
```js
|
|
359
|
+
regExp(/test/); // true
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
# ⚡ 特性
|
|
365
|
+
|
|
366
|
+
✅ 零依赖
|
|
367
|
+
✅ 体积小
|
|
368
|
+
✅ 高性能正则
|
|
369
|
+
✅ 支持 Tree Shaking
|
|
370
|
+
✅ TypeScript 友好(建议生成 `.d.ts`)
|
|
371
|
+
✅ 同时支持 ESM / CJS
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
# 🎯 适用场景
|
|
376
|
+
|
|
377
|
+
- 表单校验
|
|
378
|
+
- 后台管理系统
|
|
379
|
+
- 移动端 H5
|
|
380
|
+
- Node.js 服务
|
|
381
|
+
- 通用工具库
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
# 📄 License
|
|
386
|
+
|
|
387
|
+
ISC
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
⭐ 如果这个库对你有帮助,欢迎点个 Star!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(t){return/^\w+((-\w+)|(\.\w+))*@[A-Z0-9]+((\.|-)[A-Z0-9]+)*\.[A-Z0-9]+$/i.test(t)}function c(t){return/^1([3589]\d|4[5-9]|6[12,4-7]|7[0-8])\d{8}$/.test(t)}function s(t){return/^((https|http|ftp|rtsp|mms):\/\/)(([\w!~*'().&=+$%-]+: )?[\w!~*'().&=+$%-]+@)?((\d{1,3}.){3}\d{1,3}|([\w!~*'()-]+.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z].[a-zA-Z]{2,6})(:\d{1,4})?((\/?)|(\/[\w!~*'().;?:@&=+$,%#-]+)+\/?)$/.test(t)}function f(t){return t?(i(t)&&(t=+t),!/Invalid|NaN/.test(new Date(t).toString())):!1}function d(t){return/^\d{4}[/\-](0?[1-9]|1[012])[/\-](0?[1-9]|[12]\d|3[01])$/.test(t)}function i(t){return/^[+-]?(\d+(?:\.\d*)?|\.\d+|\d\.\d+e\+\d+)$/.test(t)}function g(t){return typeof t=="string"}function a(t){return/^\d+$/.test(t)}function p(t){return/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|12]\d)|3[01])\d{3}([0-9X])$/.test(t)}function m(t){const n=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z][A-Z]((\d{5}[DF]$)|([DF][A-HJ-NP-Z0-9]\d{4}$))/,r=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/;return t.length===7?r.test(t):t.length===8?n.test(t):!1}function b(t){return/^[1-9]\d*(,\d{3})*(\.\d{1,2})?$|^0\.\d{1,2}$/.test(t)}function l(t){return/^[\u4E00-\u9FA5]+$/g.test(t)}function A(t){return/^[a-z]*$/i.test(t)}function $(t){return/^[0-9a-z]*$/gi.test(t)}function y(t,n){return t.includes(n)}function j(t,n){return t>=n[0]&&t<=n[1]}function E(t,n){return t.length>=n[0]&&t.length<=n[1]}function h(t){return/^\d{3,4}-\d{7,8}(-\d{3,4})?$/.test(t)}function Z(t){switch(typeof t){case"undefined":return!0;case"string":if(t.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,"").length==0)return!0;break;case"boolean":if(!t)return!0;break;case"number":if(t===0||isNaN(t))return!0;break;case"object":if(t===null||t.length===0)return!0;for(const n in t)return!1;return!0}return!1}function w(t){if(typeof t=="string")try{const n=JSON.parse(t);return!!(typeof n=="object"&&n)}catch{return!1}return!1}function N(t){return typeof Array.isArray=="function"?Array.isArray(t):Object.prototype.toString.call(t)==="[object Array]"}function o(t){return Object.prototype.toString.call(t)==="[object Object]"}function O(t,n=6){return new RegExp(`^\\d{${n}}$`).test(t)}function e(t){return typeof t=="function"}function S(t){return o(t)&&e(t.then)&&e(t.catch)}function P(t){const n=t.split("?")[0];return/\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i.test(n)}function I(t){return/\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv|m3u8)/i.test(t)}function z(t){return t&&Object.prototype.toString.call(t)==="[object RegExp]"}exports.amount=b;exports.array=N;exports.carNo=m;exports.chinese=l;exports.code=O;exports.contains=y;exports.date=f;exports.dateISO=d;exports.digits=a;exports.email=u;exports.empty=Z;exports.enOrNum=$;exports.func=e;exports.idCard=p;exports.image=P;exports.jsonString=w;exports.landline=h;exports.letter=A;exports.mobile=c;exports.number=i;exports.object=o;exports.promise=S;exports.range=j;exports.rangeLength=E;exports.regExp=z;exports.string=g;exports.url=s;exports.video=I;
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
function u(t) {
|
|
2
|
+
return /^\w+((-\w+)|(\.\w+))*@[A-Z0-9]+((\.|-)[A-Z0-9]+)*\.[A-Z0-9]+$/i.test(t);
|
|
3
|
+
}
|
|
4
|
+
function c(t) {
|
|
5
|
+
return /^1([3589]\d|4[5-9]|6[12,4-7]|7[0-8])\d{8}$/.test(t);
|
|
6
|
+
}
|
|
7
|
+
function f(t) {
|
|
8
|
+
return /^((https|http|ftp|rtsp|mms):\/\/)(([\w!~*'().&=+$%-]+: )?[\w!~*'().&=+$%-]+@)?((\d{1,3}.){3}\d{1,3}|([\w!~*'()-]+.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z].[a-zA-Z]{2,6})(:\d{1,4})?((\/?)|(\/[\w!~*'().;?:@&=+$,%#-]+)+\/?)$/.test(t);
|
|
9
|
+
}
|
|
10
|
+
function s(t) {
|
|
11
|
+
return t ? (i(t) && (t = +t), !/Invalid|NaN/.test(new Date(t).toString())) : !1;
|
|
12
|
+
}
|
|
13
|
+
function d(t) {
|
|
14
|
+
return /^\d{4}[/\-](0?[1-9]|1[012])[/\-](0?[1-9]|[12]\d|3[01])$/.test(t);
|
|
15
|
+
}
|
|
16
|
+
function i(t) {
|
|
17
|
+
return /^[+-]?(\d+(?:\.\d*)?|\.\d+|\d\.\d+e\+\d+)$/.test(t);
|
|
18
|
+
}
|
|
19
|
+
function g(t) {
|
|
20
|
+
return typeof t == "string";
|
|
21
|
+
}
|
|
22
|
+
function p(t) {
|
|
23
|
+
return /^\d+$/.test(t);
|
|
24
|
+
}
|
|
25
|
+
function a(t) {
|
|
26
|
+
return /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|12]\d)|3[01])\d{3}([0-9X])$/.test(
|
|
27
|
+
t
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
function A(t) {
|
|
31
|
+
const n = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z][A-Z]((\d{5}[DF]$)|([DF][A-HJ-NP-Z0-9]\d{4}$))/, r = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/;
|
|
32
|
+
return t.length === 7 ? r.test(t) : t.length === 8 ? n.test(t) : !1;
|
|
33
|
+
}
|
|
34
|
+
function $(t) {
|
|
35
|
+
return /^[1-9]\d*(,\d{3})*(\.\d{1,2})?$|^0\.\d{1,2}$/.test(t);
|
|
36
|
+
}
|
|
37
|
+
function b(t) {
|
|
38
|
+
return /^[\u4E00-\u9FA5]+$/g.test(t);
|
|
39
|
+
}
|
|
40
|
+
function m(t) {
|
|
41
|
+
return /^[a-z]*$/i.test(t);
|
|
42
|
+
}
|
|
43
|
+
function y(t) {
|
|
44
|
+
return /^[0-9a-z]*$/gi.test(t);
|
|
45
|
+
}
|
|
46
|
+
function E(t, n) {
|
|
47
|
+
return t.includes(n);
|
|
48
|
+
}
|
|
49
|
+
function j(t, n) {
|
|
50
|
+
return t >= n[0] && t <= n[1];
|
|
51
|
+
}
|
|
52
|
+
function h(t, n) {
|
|
53
|
+
return t.length >= n[0] && t.length <= n[1];
|
|
54
|
+
}
|
|
55
|
+
function l(t) {
|
|
56
|
+
return /^\d{3,4}-\d{7,8}(-\d{3,4})?$/.test(t);
|
|
57
|
+
}
|
|
58
|
+
function Z(t) {
|
|
59
|
+
switch (typeof t) {
|
|
60
|
+
case "undefined":
|
|
61
|
+
return !0;
|
|
62
|
+
case "string":
|
|
63
|
+
if (t.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, "").length == 0)
|
|
64
|
+
return !0;
|
|
65
|
+
break;
|
|
66
|
+
case "boolean":
|
|
67
|
+
if (!t)
|
|
68
|
+
return !0;
|
|
69
|
+
break;
|
|
70
|
+
case "number":
|
|
71
|
+
if (t === 0 || isNaN(t))
|
|
72
|
+
return !0;
|
|
73
|
+
break;
|
|
74
|
+
case "object":
|
|
75
|
+
if (t === null || t.length === 0)
|
|
76
|
+
return !0;
|
|
77
|
+
for (const n in t)
|
|
78
|
+
return !1;
|
|
79
|
+
return !0;
|
|
80
|
+
}
|
|
81
|
+
return !1;
|
|
82
|
+
}
|
|
83
|
+
function w(t) {
|
|
84
|
+
if (typeof t == "string")
|
|
85
|
+
try {
|
|
86
|
+
const n = JSON.parse(t);
|
|
87
|
+
return !!(typeof n == "object" && n);
|
|
88
|
+
} catch {
|
|
89
|
+
return !1;
|
|
90
|
+
}
|
|
91
|
+
return !1;
|
|
92
|
+
}
|
|
93
|
+
function N(t) {
|
|
94
|
+
return typeof Array.isArray == "function" ? Array.isArray(t) : Object.prototype.toString.call(t) === "[object Array]";
|
|
95
|
+
}
|
|
96
|
+
function o(t) {
|
|
97
|
+
return Object.prototype.toString.call(t) === "[object Object]";
|
|
98
|
+
}
|
|
99
|
+
function O(t, n = 6) {
|
|
100
|
+
return new RegExp(`^\\d{${n}}$`).test(t);
|
|
101
|
+
}
|
|
102
|
+
function e(t) {
|
|
103
|
+
return typeof t == "function";
|
|
104
|
+
}
|
|
105
|
+
function P(t) {
|
|
106
|
+
return o(t) && e(t.then) && e(t.catch);
|
|
107
|
+
}
|
|
108
|
+
function S(t) {
|
|
109
|
+
const n = t.split("?")[0];
|
|
110
|
+
return /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i.test(n);
|
|
111
|
+
}
|
|
112
|
+
function z(t) {
|
|
113
|
+
return /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv|m3u8)/i.test(t);
|
|
114
|
+
}
|
|
115
|
+
function G(t) {
|
|
116
|
+
return t && Object.prototype.toString.call(t) === "[object RegExp]";
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
$ as amount,
|
|
120
|
+
N as array,
|
|
121
|
+
A as carNo,
|
|
122
|
+
b as chinese,
|
|
123
|
+
O as code,
|
|
124
|
+
E as contains,
|
|
125
|
+
s as date,
|
|
126
|
+
d as dateISO,
|
|
127
|
+
p as digits,
|
|
128
|
+
u as email,
|
|
129
|
+
Z as empty,
|
|
130
|
+
y as enOrNum,
|
|
131
|
+
e as func,
|
|
132
|
+
a as idCard,
|
|
133
|
+
S as image,
|
|
134
|
+
w as jsonString,
|
|
135
|
+
l as landline,
|
|
136
|
+
m as letter,
|
|
137
|
+
c as mobile,
|
|
138
|
+
i as number,
|
|
139
|
+
o as object,
|
|
140
|
+
P as promise,
|
|
141
|
+
j as range,
|
|
142
|
+
h as rangeLength,
|
|
143
|
+
G as regExp,
|
|
144
|
+
g as string,
|
|
145
|
+
f as url,
|
|
146
|
+
z as video
|
|
147
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(n,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(n=typeof globalThis<"u"?globalThis:n||self,r((n["@heking"]=n["@heking"]||{},n["@heking"]["wu/validate"]={})))})(this,(function(n){"use strict";function r(t){return/^\w+((-\w+)|(\.\w+))*@[A-Z0-9]+((\.|-)[A-Z0-9]+)*\.[A-Z0-9]+$/i.test(t)}function o(t){return/^1([3589]\d|4[5-9]|6[12,4-7]|7[0-8])\d{8}$/.test(t)}function d(t){return/^((https|http|ftp|rtsp|mms):\/\/)(([\w!~*'().&=+$%-]+: )?[\w!~*'().&=+$%-]+@)?((\d{1,3}.){3}\d{1,3}|([\w!~*'()-]+.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z].[a-zA-Z]{2,6})(:\d{1,4})?((\/?)|(\/[\w!~*'().;?:@&=+$,%#-]+)+\/?)$/.test(t)}function g(t){return t?(u(t)&&(t=+t),!/Invalid|NaN/.test(new Date(t).toString())):!1}function s(t){return/^\d{4}[/\-](0?[1-9]|1[012])[/\-](0?[1-9]|[12]\d|3[01])$/.test(t)}function u(t){return/^[+-]?(\d+(?:\.\d*)?|\.\d+|\d\.\d+e\+\d+)$/.test(t)}function a(t){return typeof t=="string"}function m(t){return/^\d+$/.test(t)}function b(t){return/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|12]\d)|3[01])\d{3}([0-9X])$/.test(t)}function y(t){const e=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z][A-Z]((\d{5}[DF]$)|([DF][A-HJ-NP-Z0-9]\d{4}$))/,f=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/;return t.length===7?f.test(t):t.length===8?e.test(t):!1}function h(t){return/^[1-9]\d*(,\d{3})*(\.\d{1,2})?$|^0\.\d{1,2}$/.test(t)}function l(t){return/^[\u4E00-\u9FA5]+$/g.test(t)}function A(t){return/^[a-z]*$/i.test(t)}function $(t){return/^[0-9a-z]*$/gi.test(t)}function j(t,e){return t.includes(e)}function E(t,e){return t>=e[0]&&t<=e[1]}function p(t,e){return t.length>=e[0]&&t.length<=e[1]}function w(t){return/^\d{3,4}-\d{7,8}(-\d{3,4})?$/.test(t)}function Z(t){switch(typeof t){case"undefined":return!0;case"string":if(t.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,"").length==0)return!0;break;case"boolean":if(!t)return!0;break;case"number":if(t===0||isNaN(t))return!0;break;case"object":if(t===null||t.length===0)return!0;for(const e in t)return!1;return!0}return!1}function N(t){if(typeof t=="string")try{const e=JSON.parse(t);return!!(typeof e=="object"&&e)}catch{return!1}return!1}function O(t){return typeof Array.isArray=="function"?Array.isArray(t):Object.prototype.toString.call(t)==="[object Array]"}function c(t){return Object.prototype.toString.call(t)==="[object Object]"}function S(t,e=6){return new RegExp(`^\\d{${e}}$`).test(t)}function i(t){return typeof t=="function"}function P(t){return c(t)&&i(t.then)&&i(t.catch)}function k(t){const e=t.split("?")[0];return/\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i.test(e)}function I(t){return/\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv|m3u8)/i.test(t)}function z(t){return t&&Object.prototype.toString.call(t)==="[object RegExp]"}n.amount=h,n.array=O,n.carNo=y,n.chinese=l,n.code=S,n.contains=j,n.date=g,n.dateISO=s,n.digits=m,n.email=r,n.empty=Z,n.enOrNum=$,n.func=i,n.idCard=b,n.image=k,n.jsonString=N,n.landline=w,n.letter=A,n.mobile=o,n.number=u,n.object=c,n.promise=P,n.range=E,n.rangeLength=p,n.regExp=z,n.string=a,n.url=d,n.video=I,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@heking.wu/validate",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
|
+
"module": "./dist/index.es.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.es.js",
|
|
13
|
+
"require": "./dist/index.cjs.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"validate",
|
|
18
|
+
"校验"
|
|
19
|
+
],
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"vite": "^7.3.1"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "vite build",
|
|
27
|
+
"release": "pnpm build && pnpm version patch && pnpm publish --access public"
|
|
28
|
+
}
|
|
29
|
+
}
|