@ivujs/i-utils 1.1.14 → 1.1.16

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 (213) hide show
  1. package/dist/cjs/ID-card/index.cjs +87 -0
  2. package/dist/cjs/array/index.cjs +470 -0
  3. package/dist/cjs/clipboard/index.cjs +128 -0
  4. package/dist/cjs/color/index.cjs +193 -0
  5. package/dist/cjs/constants/date.cjs +178 -0
  6. package/dist/cjs/constants/id-card.cjs +52 -0
  7. package/dist/cjs/constants/keycode.cjs +117 -0
  8. package/dist/cjs/constants/lang.cjs +13 -0
  9. package/dist/cjs/constants/math.cjs +13 -0
  10. package/dist/cjs/constants/regexp.cjs +53 -0
  11. package/dist/cjs/constants/sort.cjs +15 -0
  12. package/dist/cjs/cookie/index.cjs +70 -0
  13. package/dist/cjs/crypto/aes/aes.cjs +480 -0
  14. package/dist/cjs/crypto/aes/index.cjs +27 -0
  15. package/dist/cjs/crypto/base32/base32.cjs +357 -0
  16. package/dist/cjs/crypto/base32/index.cjs +41 -0
  17. package/dist/cjs/crypto/base64/base64.cjs +348 -0
  18. package/dist/cjs/crypto/base64/index.cjs +59 -0
  19. package/dist/cjs/crypto/des/des.cjs +257 -0
  20. package/dist/cjs/crypto/des/index.cjs +28 -0
  21. package/dist/cjs/crypto/md5/index.cjs +24 -0
  22. package/dist/cjs/crypto/md5/md5.cjs +897 -0
  23. package/dist/cjs/crypto/sha/sha1/index.cjs +24 -0
  24. package/dist/cjs/crypto/sha/sha1/sha1.cjs +529 -0
  25. package/dist/cjs/crypto/sha/sha256/index.cjs +43 -0
  26. package/dist/cjs/crypto/sha/sha256/sha256.cjs +595 -0
  27. package/dist/cjs/crypto/sha/sha3/index.cjs +41 -0
  28. package/dist/cjs/crypto/sha/sha3/sha3.cjs +624 -0
  29. package/dist/cjs/crypto/sha/sha512/index.cjs +81 -0
  30. package/dist/cjs/crypto/sha/sha512/sha512.cjs +950 -0
  31. package/dist/cjs/crypto/sm/lib/asn1.cjs +149 -0
  32. package/dist/cjs/crypto/sm/lib/ec.cjs +315 -0
  33. package/dist/cjs/crypto/sm/lib/jsbn.cjs +1608 -0
  34. package/dist/cjs/crypto/sm/lib/sm3.cjs +158 -0
  35. package/dist/cjs/crypto/sm/lib/utils.cjs +170 -0
  36. package/dist/cjs/crypto/sm/sm2/index.cjs +112 -0
  37. package/dist/cjs/crypto/sm/sm2/sm2.cjs +231 -0
  38. package/dist/cjs/crypto/sm/sm3/index.cjs +15 -0
  39. package/dist/cjs/crypto/sm/sm3/sm3.cjs +93 -0
  40. package/dist/cjs/crypto/sm/sm4/index.cjs +27 -0
  41. package/dist/cjs/crypto/sm/sm4/sm4.cjs +327 -0
  42. package/dist/cjs/crypto/tea/index.cjs +25 -0
  43. package/dist/cjs/crypto/tea/tea.cjs +187 -0
  44. package/dist/cjs/date/index.cjs +1266 -0
  45. package/dist/cjs/desensitized/index.cjs +75 -0
  46. package/dist/cjs/device/index.cjs +151 -0
  47. package/dist/cjs/dom/index.cjs +129 -0
  48. package/dist/cjs/file/index.cjs +333 -0
  49. package/dist/cjs/function/index.cjs +69 -0
  50. package/dist/cjs/id/index.cjs +1 -1
  51. package/dist/cjs/index.cjs +398 -47
  52. package/dist/cjs/keycode/index.cjs +33 -0
  53. package/dist/cjs/math/index.cjs +278 -0
  54. package/dist/cjs/number/index.cjs +31 -0
  55. package/dist/cjs/object/index.cjs +272 -0
  56. package/dist/cjs/pagination/index.cjs +131 -0
  57. package/dist/cjs/random/index.cjs +24 -0
  58. package/dist/cjs/regexp/index.cjs +100 -0
  59. package/dist/cjs/storage/index.cjs +11 -0
  60. package/dist/cjs/storage/localStorage.cjs +37 -0
  61. package/dist/cjs/storage/sessionStorage.cjs +37 -0
  62. package/dist/cjs/string/index.cjs +358 -0
  63. package/dist/cjs/url/index.cjs +258 -0
  64. package/dist/cjs/validate/index.cjs +468 -0
  65. package/dist/cjs/weapp/index.cjs +142 -0
  66. package/dist/es/ID-card/index.d.ts +31 -0
  67. package/dist/es/ID-card/index.mjs +81 -0
  68. package/dist/es/array/index.d.ts +203 -0
  69. package/dist/es/array/index.mjs +441 -0
  70. package/dist/es/clipboard/index.d.ts +29 -0
  71. package/dist/es/clipboard/index.mjs +122 -0
  72. package/dist/es/color/index.d.ts +52 -0
  73. package/dist/es/color/index.mjs +183 -0
  74. package/dist/es/constants/date.d.ts +174 -0
  75. package/dist/es/constants/date.mjs +176 -0
  76. package/dist/es/constants/id-card.d.ts +43 -0
  77. package/dist/es/constants/id-card.mjs +50 -0
  78. package/dist/es/constants/index.d.ts +7 -0
  79. package/dist/es/constants/keycode.d.ts +103 -0
  80. package/dist/es/constants/keycode.mjs +115 -0
  81. package/dist/es/constants/lang.d.ts +4 -0
  82. package/dist/es/constants/lang.mjs +11 -0
  83. package/dist/es/constants/math.d.ts +4 -0
  84. package/dist/es/constants/math.mjs +11 -0
  85. package/dist/es/constants/regexp.d.ts +24 -0
  86. package/dist/es/constants/regexp.mjs +51 -0
  87. package/dist/es/constants/sort.d.ts +5 -0
  88. package/dist/es/constants/sort.mjs +13 -0
  89. package/dist/es/cookie/index.d.ts +29 -0
  90. package/dist/es/cookie/index.mjs +64 -0
  91. package/dist/es/crypto/aes/aes.d.ts +156 -0
  92. package/dist/es/crypto/aes/aes.mjs +478 -0
  93. package/dist/es/crypto/aes/index.d.ts +16 -0
  94. package/dist/es/crypto/aes/index.mjs +24 -0
  95. package/dist/es/crypto/base32/base32.d.ts +3 -0
  96. package/dist/es/crypto/base32/base32.mjs +353 -0
  97. package/dist/es/crypto/base32/index.d.ts +24 -0
  98. package/dist/es/crypto/base32/index.mjs +36 -0
  99. package/dist/es/crypto/base64/base64.d.ts +5 -0
  100. package/dist/es/crypto/base64/base64.mjs +342 -0
  101. package/dist/es/crypto/base64/index.d.ts +36 -0
  102. package/dist/es/crypto/base64/index.mjs +52 -0
  103. package/dist/es/crypto/des/des.d.ts +52 -0
  104. package/dist/es/crypto/des/des.mjs +255 -0
  105. package/dist/es/crypto/des/index.d.ts +14 -0
  106. package/dist/es/crypto/des/index.mjs +25 -0
  107. package/dist/es/crypto/index.d.ts +8 -0
  108. package/dist/es/crypto/md5/index.d.ts +13 -0
  109. package/dist/es/crypto/md5/index.mjs +21 -0
  110. package/dist/es/crypto/md5/md5.d.ts +144 -0
  111. package/dist/es/crypto/md5/md5.mjs +894 -0
  112. package/dist/es/crypto/sha/index.d.ts +4 -0
  113. package/dist/es/crypto/sha/sha1/index.d.ts +13 -0
  114. package/dist/es/crypto/sha/sha1/index.mjs +21 -0
  115. package/dist/es/crypto/sha/sha1/sha1.d.ts +2 -0
  116. package/dist/es/crypto/sha/sha1/sha1.mjs +526 -0
  117. package/dist/es/crypto/sha/sha256/index.d.ts +26 -0
  118. package/dist/es/crypto/sha/sha256/index.mjs +38 -0
  119. package/dist/es/crypto/sha/sha256/sha256.d.ts +4 -0
  120. package/dist/es/crypto/sha/sha256/sha256.mjs +590 -0
  121. package/dist/es/crypto/sha/sha3/index.d.ts +24 -0
  122. package/dist/es/crypto/sha/sha3/index.mjs +36 -0
  123. package/dist/es/crypto/sha/sha3/sha3.d.ts +4 -0
  124. package/dist/es/crypto/sha/sha3/sha3.mjs +619 -0
  125. package/dist/es/crypto/sha/sha512/index.d.ts +52 -0
  126. package/dist/es/crypto/sha/sha512/index.mjs +72 -0
  127. package/dist/es/crypto/sha/sha512/sha512.d.ts +8 -0
  128. package/dist/es/crypto/sha/sha512/sha512.mjs +941 -0
  129. package/dist/es/crypto/sm/index.d.ts +3 -0
  130. package/dist/es/crypto/sm/lib/asn1.d.ts +12 -0
  131. package/dist/es/crypto/sm/lib/asn1.mjs +146 -0
  132. package/dist/es/crypto/sm/lib/ec.d.ts +126 -0
  133. package/dist/es/crypto/sm/lib/ec.mjs +312 -0
  134. package/dist/es/crypto/sm/lib/jsbn.d.ts +198 -0
  135. package/dist/es/crypto/sm/lib/jsbn.mjs +1605 -0
  136. package/dist/es/crypto/sm/lib/sm3.d.ts +5 -0
  137. package/dist/es/crypto/sm/lib/sm3.mjs +155 -0
  138. package/dist/es/crypto/sm/lib/utils.d.ts +53 -0
  139. package/dist/es/crypto/sm/lib/utils.mjs +158 -0
  140. package/dist/es/crypto/sm/sm2/index.d.ts +71 -0
  141. package/dist/es/crypto/sm/sm2/index.mjs +101 -0
  142. package/dist/es/crypto/sm/sm2/sm2.d.ts +34 -0
  143. package/dist/es/crypto/sm/sm2/sm2.mjs +220 -0
  144. package/dist/es/crypto/sm/sm3/index.d.ts +7 -0
  145. package/dist/es/crypto/sm/sm3/index.mjs +13 -0
  146. package/dist/es/crypto/sm/sm3/sm3.d.ts +1 -0
  147. package/dist/es/crypto/sm/sm3/sm3.mjs +91 -0
  148. package/dist/es/crypto/sm/sm4/index.d.ts +16 -0
  149. package/dist/es/crypto/sm/sm4/index.mjs +24 -0
  150. package/dist/es/crypto/sm/sm4/sm4.d.ts +2 -0
  151. package/dist/es/crypto/sm/sm4/sm4.mjs +324 -0
  152. package/dist/es/crypto/tea/index.d.ts +14 -0
  153. package/dist/es/crypto/tea/index.mjs +22 -0
  154. package/dist/es/crypto/tea/tea.d.ts +69 -0
  155. package/dist/es/crypto/tea/tea.mjs +185 -0
  156. package/dist/es/date/index.d.ts +547 -0
  157. package/dist/es/date/index.mjs +1179 -0
  158. package/dist/es/desensitized/index.d.ts +38 -0
  159. package/dist/es/desensitized/index.mjs +69 -0
  160. package/dist/es/device/index.d.ts +67 -0
  161. package/dist/es/device/index.mjs +137 -0
  162. package/dist/es/dom/index.d.ts +57 -0
  163. package/dist/es/dom/index.mjs +119 -0
  164. package/dist/es/file/index.d.ts +93 -0
  165. package/dist/es/file/index.mjs +317 -0
  166. package/dist/es/function/index.d.ts +23 -0
  167. package/dist/es/function/index.mjs +65 -0
  168. package/dist/es/id/index.mjs +1 -1
  169. package/dist/es/index.d.ts +25 -42
  170. package/dist/es/index.mjs +54 -40
  171. package/dist/es/keycode/index.d.ts +12 -0
  172. package/dist/es/keycode/index.mjs +30 -0
  173. package/dist/es/math/index.d.ts +66 -0
  174. package/dist/es/math/index.mjs +268 -0
  175. package/dist/es/number/index.d.ts +14 -0
  176. package/dist/es/number/index.mjs +28 -0
  177. package/dist/es/object/index.d.ts +83 -0
  178. package/dist/es/object/index.mjs +259 -0
  179. package/dist/es/pagination/index.d.ts +34 -0
  180. package/dist/es/pagination/index.mjs +125 -0
  181. package/dist/es/random/index.d.ts +15 -0
  182. package/dist/es/random/index.mjs +21 -0
  183. package/dist/es/regexp/index.d.ts +63 -0
  184. package/dist/es/regexp/index.mjs +89 -0
  185. package/dist/es/storage/index.d.ts +7 -0
  186. package/dist/es/storage/index.mjs +9 -0
  187. package/dist/es/storage/localStorage.d.ts +21 -0
  188. package/dist/es/storage/localStorage.mjs +32 -0
  189. package/dist/es/storage/sessionStorage.d.ts +21 -0
  190. package/dist/es/storage/sessionStorage.mjs +32 -0
  191. package/dist/es/string/index.d.ts +121 -0
  192. package/dist/es/string/index.mjs +339 -0
  193. package/dist/es/url/index.d.ts +118 -0
  194. package/dist/es/url/index.mjs +240 -0
  195. package/dist/es/validate/index.d.ts +228 -0
  196. package/dist/es/validate/index.mjs +431 -0
  197. package/dist/es/weapp/index.d.ts +57 -0
  198. package/dist/es/weapp/index.mjs +131 -0
  199. package/dist/index.d.ts +2850 -53
  200. package/dist/lib/index.full.cjs.js +14230 -67
  201. package/dist/lib/index.full.cjs.min.js +64 -2
  202. package/dist/lib/index.full.cjs.min.js.map +1 -1
  203. package/dist/lib/index.full.esm.js +13881 -63
  204. package/dist/lib/index.full.esm.min.js +59 -2
  205. package/dist/lib/index.full.esm.min.js.map +1 -1
  206. package/dist/lib/index.full.umd.js +14230 -67
  207. package/dist/lib/index.full.umd.min.js +64 -2
  208. package/dist/lib/index.full.umd.min.js.map +1 -1
  209. package/dist/resolver/auto-imports.cjs +337 -11
  210. package/dist/resolver/auto-imports.mjs +337 -11
  211. package/dist/resolver/index.cjs +1 -1
  212. package/dist/resolver/index.mjs +1 -1
  213. package/package.json +1 -1
@@ -0,0 +1,468 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * 判断是整数
5
+ * @param {*} value 参数
6
+ * @returns {Boolean} result 返回结果
7
+ */
8
+ function isInteger(value) {
9
+ return Number.isInteger(value);
10
+ }
11
+ /**
12
+ * 判断是小数
13
+ * @param {*} value 参数
14
+ * @returns {Boolean} result 返回结果
15
+ */
16
+ function isDecimal(value) {
17
+ return /^\d+\.\d+$/.test(value);
18
+ }
19
+ /**
20
+ * 判断类型是数字 Number
21
+ * @param {Number} value 参数
22
+ * @returns {Boolean} 返回结果
23
+ */
24
+ function isNumber(value) {
25
+ return Object.prototype.toString.call(value).slice(8, -1) === "Number";
26
+ }
27
+ /**
28
+ * 判断类型是字符串 String
29
+ * @param {*} value 参数
30
+ * @returns {Boolean} 返回结果
31
+ */
32
+ function isString(value) {
33
+ return Object.prototype.toString.call(value).slice(8, -1) === "String";
34
+ }
35
+ /**
36
+ * 判断类型是数组 Array
37
+ * @param {*} value 参数
38
+ * @returns {Boolean} 返回结果
39
+ */
40
+ function isArray(value) {
41
+ return Object.prototype.toString.call(value).slice(8, -1) === "Array";
42
+ }
43
+ /**
44
+ * 判断类型是对象 Object
45
+ * @param {*} value 参数
46
+ * @returns {Boolean} 返回结果
47
+ */
48
+ function isObject(value) {
49
+ return Object.prototype.toString.call(value).slice(8, -1) === "Object";
50
+ }
51
+ /**
52
+ * 判断类型是布尔 Boolean
53
+ * @param {*} value 参数
54
+ * @returns {Boolean} 返回结果
55
+ */
56
+ function isBoolean(value) {
57
+ return Object.prototype.toString.call(value).slice(8, -1) === "Boolean";
58
+ }
59
+ /**
60
+ * 判断类型是日期 Date
61
+ * @param {*} value 参数
62
+ * @returns {Boolean} 返回结果
63
+ */
64
+ function isDate(value) {
65
+ return Object.prototype.toString.call(value).slice(8, -1) === "Date";
66
+ }
67
+ /**
68
+ * 判断类型是函数 Function
69
+ * @param {*} value 参数
70
+ * @returns {Boolean} 返回结果
71
+ */
72
+ function isFunction(value) {
73
+ return Object.prototype.toString.call(value).slice(8, -1) === "Function";
74
+ }
75
+ /**
76
+ * 判断类型是函数字符串 FunctionString
77
+ * @description 支持普通函数,异步函数,箭头函数
78
+ * @param {*} value 参数
79
+ * @returns {Boolean} 返回结果
80
+ */
81
+ function isFunctionString(value) {
82
+ if (value) {
83
+ try {
84
+ let fn = new Function(`return ${value}`)();
85
+ return typeof fn === "function";
86
+ }
87
+ catch (e) {
88
+ // 如果发生错误,比如语法错误,那么这不是一个有效的函数
89
+ return false;
90
+ }
91
+ }
92
+ else {
93
+ return false;
94
+ }
95
+ }
96
+ /**
97
+ * 判断类型是异步函数 AsyncFunction
98
+ * @param {*} value 参数
99
+ * @returns {Boolean} 返回结果
100
+ */
101
+ function isAsyncFunction(value) {
102
+ return Object.prototype.toString.call(value).slice(8, -1) === "AsyncFunction";
103
+ }
104
+ /**
105
+ * 判断类型是 Symbol
106
+ * @param {*} value 参数
107
+ * @returns {Boolean} 返回结果
108
+ */
109
+ function isSymbol(value) {
110
+ return Object.prototype.toString.call(value).slice(8, -1) === "Symbol";
111
+ }
112
+ /**
113
+ * 判断类型是正则 RegExp
114
+ * @param {*} value 参数
115
+ * @returns {Boolean} 返回结果
116
+ */
117
+ function isRegExp(value) {
118
+ return Object.prototype.toString.call(value).slice(8, -1) === "RegExp";
119
+ }
120
+ /**
121
+ * 判断类型是错误 Error
122
+ * @param {*} value 参数
123
+ * @returns {Boolean} 返回结果
124
+ */
125
+ function isError(value) {
126
+ return Object.prototype.toString.call(value).slice(8, -1) === "Error";
127
+ }
128
+ /**
129
+ * 判断类型是 Promise
130
+ * @param {*} value 参数
131
+ * @returns {Boolean} 返回结果
132
+ */
133
+ function isPromise(value) {
134
+ return Object.prototype.toString.call(value).slice(8, -1) === "Promise";
135
+ }
136
+ /**
137
+ *判断类型是 Map
138
+ * @param {*} value 参数
139
+ * @returns {Boolean} 返回结果
140
+ */
141
+ function isMap(value) {
142
+ return Object.prototype.toString.call(value).slice(8, -1) === "Map";
143
+ }
144
+ /**
145
+ * 判断类型是 WeakMap
146
+ * @param {*} value 参数
147
+ * @returns {Boolean} 返回结果
148
+ */
149
+ function isWeakMap(value) {
150
+ return Object.prototype.toString.call(value).slice(8, -1) === "WeakMap";
151
+ }
152
+ /**
153
+ * 判断类型是 Set
154
+ * @param {*} value 参数
155
+ * @returns {Boolean} 返回结果
156
+ */
157
+ function isSet(value) {
158
+ return Object.prototype.toString.call(value).slice(8, -1) === "Set";
159
+ }
160
+ /**
161
+ * 判断类型是 WeakSet
162
+ * @param {*} value 参数
163
+ * @returns {Boolean} 返回结果
164
+ */
165
+ function isWeakSet(value) {
166
+ return Object.prototype.toString.call(value).slice(8, -1) === "WeakSet";
167
+ }
168
+ /**
169
+ * 判断类型是 BigInt
170
+ * @param {*} value 参数
171
+ * @returns {Boolean} 返回结果
172
+ */
173
+ function isBigInt(value) {
174
+ return Object.prototype.toString.call(value).slice(8, -1) === "BigInt";
175
+ }
176
+ /**
177
+ * 判断类型是 Json
178
+ * @param {*} value 参数
179
+ * @returns {Boolean} 返回结果
180
+ */
181
+ function isJson(value) {
182
+ try {
183
+ JSON.parse(value);
184
+ return true;
185
+ }
186
+ catch (error) {
187
+ return false;
188
+ }
189
+ }
190
+ /* 数据值校验 */
191
+ /**
192
+ * 判断值为真
193
+ * @param {*} value 校验的参数
194
+ * @returns {Boolean} 返回结果
195
+ */
196
+ function isTrue(value) {
197
+ return !isFalse(value);
198
+ }
199
+ /**
200
+ * 判断值为假
201
+ * @param {*} value 校验的参数
202
+ * @returns {Boolean} 返回结果
203
+ */
204
+ function isFalse(value) {
205
+ return (value === undefined ||
206
+ value === null ||
207
+ value === "undefined" ||
208
+ value === "null" ||
209
+ value === 0 ||
210
+ value === false ||
211
+ isNaN(value));
212
+ }
213
+ /**
214
+ * 判断非数字
215
+ * @param {*} value 参数
216
+ * @returns {Boolean} 返回结果
217
+ */
218
+ function isNaN(value) {
219
+ // window的isNaN函数是有缺陷的,空数组/数组有一个元素,null,空字符串 都会被认为是数字
220
+ return window.isNaN(value) || isArray(value) || value == null || value === "";
221
+ }
222
+ /**
223
+ * 判断是数字
224
+ * @description 等同于isNumber()
225
+ * @param {*} value 参数
226
+ * @returns {Boolean} 返回结果
227
+ */
228
+ function isNotNaN(value) {
229
+ return !isNaN(value);
230
+ }
231
+ /**
232
+ * 判断对象为空
233
+ * @description 判断值是否为空,如果对象初始化了值则不为空
234
+ * @param {*} value 校验的参数
235
+ * @returns {Boolean} 返回结果
236
+ */
237
+ function isNull(value) {
238
+ return value === undefined || value === null || value === "";
239
+ }
240
+ /**
241
+ * 判断对象不为空
242
+ * @description 判断值是否为空,如果对象初始化了值则不为空
243
+ * @param {*} value 校验的参数
244
+ * @returns {Boolean} 返回结果
245
+ */
246
+ function isNotNull(value) {
247
+ return !isNull(value);
248
+ }
249
+ /**
250
+ * 判断值为空
251
+ * @description 判断是否是有意义不为空的值,如果值是{},[]空的数据则为空
252
+ * @param {*} value 校验的参数
253
+ * @returns {Boolean} 返回结果
254
+ */
255
+ function isEmpty(value) {
256
+ if (isNull(value))
257
+ return true;
258
+ if (typeof value === "string" || Array.isArray(value)) {
259
+ return value.length === 0;
260
+ }
261
+ if (typeof value === "object") {
262
+ if (value instanceof Map || value instanceof Set) {
263
+ return value.size === 0;
264
+ }
265
+ if (value instanceof Date || value instanceof RegExp || value instanceof Error) {
266
+ return false;
267
+ }
268
+ return Object.keys(value).length === 0;
269
+ }
270
+ return false;
271
+ }
272
+ /**
273
+ * 判断值不为空
274
+ * @description 判断是否是有意义不为空的值,如果值是{},[]空的数据则为空
275
+ * @param {*} value 校验的参数
276
+ * @returns {Boolean} 返回结果
277
+ */
278
+ function isNotEmpty(value) {
279
+ return !isEmpty(value);
280
+ }
281
+ /**
282
+ * 判断值是空白的
283
+ * @description 同时会校验空值,空对象,以及空白符号
284
+ * @param {*} value 校验的参数
285
+ * @returns {Boolean} 返回结果
286
+ */
287
+ function isBlank(value) {
288
+ return isEmpty(value) || /^\s*$/.test(value);
289
+ }
290
+ /**
291
+ * 判断值不是空白的
292
+ * @description 同时会校验空值,空对象,以及空白符号
293
+ * @param {*} value 校验的参数
294
+ * @returns {Boolean} 返回结果
295
+ */
296
+ function isNotBlank(value) {
297
+ return !isBlank(value);
298
+ }
299
+ /**
300
+ * 判断值是undefined
301
+ * @param {*} value 校验的参数
302
+ * @returns {Boolean} 返回结果
303
+ */
304
+ function isUndefined(value) {
305
+ return value === undefined;
306
+ }
307
+ /**
308
+ * 判断值不是undefined
309
+ * @param {*} value 校验的参数
310
+ * @returns {Boolean} 返回结果
311
+ */
312
+ function isNotUndefined(value) {
313
+ return !isUndefined(value);
314
+ }
315
+ /* 数据比较 */
316
+ /**
317
+ * 判断两个值是否相等
318
+ * @param {String|Number} value1 参数1
319
+ * @param {String|Number} value2 参数2
320
+ * @returns {Boolean} 返回结果
321
+ */
322
+ function equals(value1, value2) {
323
+ return Object.is(value1, value2);
324
+ }
325
+ /**
326
+ * 判断两个值是否相等(忽略大小写)
327
+ * @param {String|Number} value1 参数1
328
+ * @param {String|Number} value2 参数2
329
+ * @returns {Boolean} 返回结果
330
+ */
331
+ function equalsIgnoreCase(value1, value2) {
332
+ return Object.is(value1.toLowerCase(), value2.toLowerCase());
333
+ }
334
+ /**
335
+ * 深度对比数据
336
+ * @description 可以对比任意数据,对象,数组,日期等也可深度对比,对象不区分先后顺序
337
+ * @param {*} x 数据1
338
+ * @param {*} y 数据2
339
+ * @returns {Boolean} 返回结果
340
+ */
341
+ function deepCompare(x, y) {
342
+ let i, l, leftChain, rightChain;
343
+ function compare2Objects(x, y) {
344
+ let p;
345
+ // remember that NaN === NaN returns false
346
+ // and isNaN(undefined) returns true
347
+ if (isNaN(x) && isNaN(y) && typeof x === "number" && typeof y === "number") {
348
+ return true;
349
+ }
350
+ // Compare primitives and functions.
351
+ // Check if both arguments link to the same object.
352
+ // Especially useful on the step where we compare prototypes
353
+ if (x === y) {
354
+ return true;
355
+ }
356
+ // Works in case when functions are created in constructor.
357
+ // Comparing dates is a common scenario. Another built-ins?
358
+ // We can even handle functions passed across iframes
359
+ if ((typeof x === "function" && typeof y === "function") ||
360
+ (x instanceof Date && y instanceof Date) ||
361
+ (x instanceof RegExp && y instanceof RegExp) ||
362
+ (x instanceof String && y instanceof String) ||
363
+ (x instanceof Number && y instanceof Number)) {
364
+ return x.toString() === y.toString();
365
+ }
366
+ // At last checking prototypes as good as we can
367
+ if (!(x instanceof Object && y instanceof Object)) {
368
+ return false;
369
+ }
370
+ if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) {
371
+ return false;
372
+ }
373
+ if (x.constructor !== y.constructor) {
374
+ return false;
375
+ }
376
+ if (x.prototype !== y.prototype) {
377
+ return false;
378
+ }
379
+ // Check for infinitive linking loops
380
+ if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) {
381
+ return false;
382
+ }
383
+ // Quick checking of one object being a subset of another.
384
+ for (p in y) {
385
+ if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
386
+ return false;
387
+ }
388
+ else if (typeof y[p] !== typeof x[p]) {
389
+ return false;
390
+ }
391
+ }
392
+ for (p in x) {
393
+ if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
394
+ return false;
395
+ }
396
+ else if (typeof y[p] !== typeof x[p]) {
397
+ return false;
398
+ }
399
+ switch (typeof x[p]) {
400
+ case "object":
401
+ case "function":
402
+ leftChain.push(x);
403
+ rightChain.push(y);
404
+ if (!compare2Objects(x[p], y[p])) {
405
+ return false;
406
+ }
407
+ leftChain.pop();
408
+ rightChain.pop();
409
+ break;
410
+ default:
411
+ if (x[p] !== y[p]) {
412
+ return false;
413
+ }
414
+ break;
415
+ }
416
+ }
417
+ return true;
418
+ }
419
+ if (arguments.length < 1) {
420
+ return true; // Die silently? Don't know how to handle such case, please help...
421
+ // throw "Need two or more arguments to compare";
422
+ }
423
+ for (i = 1, l = arguments.length; i < l; i++) {
424
+ leftChain = [];
425
+ rightChain = [];
426
+ if (!compare2Objects(arguments[0], arguments[i])) {
427
+ return false;
428
+ }
429
+ }
430
+ return true;
431
+ }
432
+
433
+ exports.deepCompare = deepCompare;
434
+ exports.equals = equals;
435
+ exports.equalsIgnoreCase = equalsIgnoreCase;
436
+ exports.isArray = isArray;
437
+ exports.isAsyncFunction = isAsyncFunction;
438
+ exports.isBigInt = isBigInt;
439
+ exports.isBlank = isBlank;
440
+ exports.isBoolean = isBoolean;
441
+ exports.isDate = isDate;
442
+ exports.isDecimal = isDecimal;
443
+ exports.isEmpty = isEmpty;
444
+ exports.isError = isError;
445
+ exports.isFalse = isFalse;
446
+ exports.isFunction = isFunction;
447
+ exports.isFunctionString = isFunctionString;
448
+ exports.isInteger = isInteger;
449
+ exports.isJson = isJson;
450
+ exports.isMap = isMap;
451
+ exports.isNaN = isNaN;
452
+ exports.isNotBlank = isNotBlank;
453
+ exports.isNotEmpty = isNotEmpty;
454
+ exports.isNotNaN = isNotNaN;
455
+ exports.isNotNull = isNotNull;
456
+ exports.isNotUndefined = isNotUndefined;
457
+ exports.isNull = isNull;
458
+ exports.isNumber = isNumber;
459
+ exports.isObject = isObject;
460
+ exports.isPromise = isPromise;
461
+ exports.isRegExp = isRegExp;
462
+ exports.isSet = isSet;
463
+ exports.isString = isString;
464
+ exports.isSymbol = isSymbol;
465
+ exports.isTrue = isTrue;
466
+ exports.isUndefined = isUndefined;
467
+ exports.isWeakMap = isWeakMap;
468
+ exports.isWeakSet = isWeakSet;
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * 设置缓存
5
+ * @param {String} key key值
6
+ * @param {*} data data数据
7
+ */
8
+ function setStorageSync(key, data) {
9
+ wx.setStorageSync(key, data);
10
+ }
11
+ /**
12
+ * 获得缓存数据
13
+ * @param {String} key key值
14
+ * @returns {*} 返回获取的值
15
+ */
16
+ function getStorageSync(key) {
17
+ return wx.getStorageSync(key);
18
+ }
19
+ /**
20
+ * 获得缓存信息
21
+ * @returns {Object} 返回缓存信息
22
+ */
23
+ function getStorageInfoSync() {
24
+ return wx.getStorageInfoSync();
25
+ }
26
+ /**
27
+ * 删除缓存数据
28
+ * @param {String} key key值
29
+ */
30
+ function removeStorageSync(key) {
31
+ wx.removeStorageSync(key);
32
+ }
33
+ /**
34
+ * 清空所有缓存数据
35
+ */
36
+ function clearStorageSync() {
37
+ wx.clearStorageSync();
38
+ }
39
+ /* 缓存处理(异步) */
40
+ /**
41
+ * 设置缓存
42
+ * @param {String} key key值
43
+ * @param {*} data data数据
44
+ * @param {Boolean} encrypt 是否开启加密存储
45
+ * @returns {Promise} 返回Promise
46
+ */
47
+ function setStorage({ key, data, encrypt = false }) {
48
+ return new Promise((resolve, reject) => {
49
+ wx.setStorage({
50
+ key,
51
+ data,
52
+ encrypt,
53
+ success(res) {
54
+ resolve(res);
55
+ },
56
+ fail(err) {
57
+ reject(err);
58
+ },
59
+ });
60
+ });
61
+ }
62
+ /**
63
+ * 获得缓存数据
64
+ * @param {String} key key值
65
+ * @param {Boolean} encrypt 是否开启加密存储
66
+ * @returns {Promise} 返回Promise
67
+ */
68
+ function getStorage({ key, encrypt = false }) {
69
+ return new Promise((resolve, reject) => {
70
+ wx.getStorage({
71
+ key,
72
+ encrypt,
73
+ success(res) {
74
+ resolve(res);
75
+ },
76
+ fail(err) {
77
+ reject(err);
78
+ },
79
+ });
80
+ });
81
+ }
82
+ /**
83
+ * 获得缓存信息
84
+ * @returns {Object} 返回Promise
85
+ */
86
+ function getStorageInfo() {
87
+ return new Promise((resolve, reject) => {
88
+ wx.getStorageInfo({
89
+ success(res) {
90
+ resolve(res);
91
+ },
92
+ fail(err) {
93
+ reject(err);
94
+ },
95
+ });
96
+ });
97
+ }
98
+ /**
99
+ * 删除缓存数据
100
+ * @param {String} key key值
101
+ * @returns {Promise} 返回Promise
102
+ */
103
+ function removeStorage({ key }) {
104
+ return new Promise((resolve, reject) => {
105
+ wx.removeStorage({
106
+ key,
107
+ success(res) {
108
+ resolve(res);
109
+ },
110
+ fail(err) {
111
+ reject(err);
112
+ },
113
+ });
114
+ });
115
+ }
116
+ /**
117
+ * 清空所有缓存数据
118
+ * @returns {Promise} 返回Promise
119
+ */
120
+ function clearStorage() {
121
+ return new Promise((resolve, reject) => {
122
+ wx.clearStorage({
123
+ success(res) {
124
+ resolve(res);
125
+ },
126
+ fail(err) {
127
+ reject(err);
128
+ },
129
+ });
130
+ });
131
+ }
132
+
133
+ exports.clearStorage = clearStorage;
134
+ exports.clearStorageSync = clearStorageSync;
135
+ exports.getStorage = getStorage;
136
+ exports.getStorageInfo = getStorageInfo;
137
+ exports.getStorageInfoSync = getStorageInfoSync;
138
+ exports.getStorageSync = getStorageSync;
139
+ exports.removeStorage = removeStorage;
140
+ exports.removeStorageSync = removeStorageSync;
141
+ exports.setStorage = setStorage;
142
+ exports.setStorageSync = setStorageSync;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 根据身份证号码获取信息
3
+ * @description 能获取到 籍贯,出生日期,年龄,性别
4
+ * @param {String} idCard 身份证号码,支持一代15位和二代18位
5
+ * @returns {Object} 返回身份证信息对象
6
+ */
7
+ export function getInfoByIDCard(idCard: string): Object;
8
+ /**
9
+ * 根据身份证号码获得生日
10
+ * @param {String} idCard 身份证号码,支持一代15位和二代18位
11
+ * @returns {String} 返回生日
12
+ */
13
+ export function getBirthdayByIDCard(idCard: string): string;
14
+ /**
15
+ * 根据身份证号码获得年龄
16
+ * @param {String} idCard 身份证号码,支持一代15位和二代18位
17
+ * @returns {Number} 返回年龄
18
+ */
19
+ export function getAgeByIDCard(idCard: string): number;
20
+ /**
21
+ * 根据身份证号码获得性别
22
+ * @param {String} idCard 身份证号码,支持一代15位和二代18位
23
+ * @returns {String} 返回性别
24
+ */
25
+ export function getSexByIDCard(idCard: string): string;
26
+ /**
27
+ * 根据身份证号码获得省份
28
+ * @param {String} idCard 身份证号码,支持一代15位和二代18位
29
+ * @returns {String} 返回省份
30
+ */
31
+ export function getProvinceByIDCard(idCard: string): string;
@@ -0,0 +1,81 @@
1
+ import { isNull } from '../validate/index.mjs';
2
+ import { getAge, parseDate } from '../date/index.mjs';
3
+ import { ID_CARD } from '../constants/id-card.mjs';
4
+
5
+ /**
6
+ * 根据身份证号码获取信息
7
+ * @description 能获取到 籍贯,出生日期,年龄,性别
8
+ * @param {String} idCard 身份证号码,支持一代15位和二代18位
9
+ * @returns {Object} 返回身份证信息对象
10
+ */
11
+ function getInfoByIDCard(idCard) {
12
+ if (isNull(idCard))
13
+ return;
14
+ return {
15
+ // 省份
16
+ province: getProvinceByIDCard(idCard),
17
+ // 生日
18
+ birthday: getBirthdayByIDCard(idCard),
19
+ // 年龄
20
+ age: getAgeByIDCard(idCard),
21
+ // 性别
22
+ sex: getSexByIDCard(idCard),
23
+ };
24
+ }
25
+ /**
26
+ * 根据身份证号码获得生日
27
+ * @param {String} idCard 身份证号码,支持一代15位和二代18位
28
+ * @returns {String} 返回生日
29
+ */
30
+ function getBirthdayByIDCard(idCard) {
31
+ if (isNull(idCard))
32
+ return;
33
+ // 15位身份证
34
+ if (idCard.length === 15) {
35
+ return "19" + idCard.substring(6, 8) + "-" + idCard.substring(8, 10) + "-" + idCard.substring(10, 12);
36
+ }
37
+ // 18位身份证
38
+ if (idCard.length === 18) {
39
+ return idCard.substring(6, 10) + "-" + idCard.substring(10, 12) + "-" + idCard.substring(12, 14);
40
+ }
41
+ }
42
+ /**
43
+ * 根据身份证号码获得年龄
44
+ * @param {String} idCard 身份证号码,支持一代15位和二代18位
45
+ * @returns {Number} 返回年龄
46
+ */
47
+ function getAgeByIDCard(idCard) {
48
+ if (isNull(idCard))
49
+ return;
50
+ let birthday = getBirthdayByIDCard(idCard);
51
+ return getAge(parseDate(birthday));
52
+ }
53
+ /**
54
+ * 根据身份证号码获得性别
55
+ * @param {String} idCard 身份证号码,支持一代15位和二代18位
56
+ * @returns {String} 返回性别
57
+ */
58
+ function getSexByIDCard(idCard) {
59
+ if (isNull(idCard))
60
+ return;
61
+ // 15位身份证
62
+ if (idCard.length === 15) {
63
+ return Number(idCard.substring(14)) % 2 === 0 ? ID_CARD.SEX.WOMAN : ID_CARD.SEX.MAN;
64
+ }
65
+ // 18位身份证
66
+ if (idCard.length === 18) {
67
+ return Number(idCard.substring(16, 17)) % 2 === 0 ? ID_CARD.SEX.WOMAN : ID_CARD.SEX.MAN;
68
+ }
69
+ }
70
+ /**
71
+ * 根据身份证号码获得省份
72
+ * @param {String} idCard 身份证号码,支持一代15位和二代18位
73
+ * @returns {String} 返回省份
74
+ */
75
+ function getProvinceByIDCard(idCard) {
76
+ if (isNull(idCard))
77
+ return;
78
+ return ID_CARD.PROVINCE[idCard.substring(0, 2)];
79
+ }
80
+
81
+ export { getAgeByIDCard, getBirthdayByIDCard, getInfoByIDCard, getProvinceByIDCard, getSexByIDCard };