@ivujs/i-utils 1.1.18 → 2.1.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.
Files changed (142) hide show
  1. package/README.md +122 -58
  2. package/dist/cjs/ID-card/index.cjs +95 -0
  3. package/dist/cjs/array/index.cjs +476 -0
  4. package/dist/cjs/clipboard/index.cjs +132 -0
  5. package/dist/cjs/color/index.cjs +207 -0
  6. package/dist/cjs/constants/date.cjs +178 -0
  7. package/dist/cjs/constants/id-card.cjs +52 -0
  8. package/dist/cjs/constants/keycode.cjs +117 -0
  9. package/dist/cjs/constants/lang.cjs +13 -0
  10. package/dist/cjs/constants/math.cjs +13 -0
  11. package/dist/cjs/constants/regexp.cjs +53 -0
  12. package/dist/cjs/constants/sort.cjs +15 -0
  13. package/dist/cjs/cookie/index.cjs +73 -0
  14. package/dist/cjs/crypto/base64/base64.cjs +540 -0
  15. package/dist/cjs/crypto/base64/index.cjs +82 -0
  16. package/dist/cjs/crypto/md5/index.cjs +49 -0
  17. package/dist/cjs/crypto/md5/md5.cjs +351 -0
  18. package/dist/cjs/crypto/sha256/index.cjs +95 -0
  19. package/dist/cjs/crypto/sha256/sha256.cjs +557 -0
  20. package/dist/cjs/crypto/sm3/index.cjs +27 -0
  21. package/dist/cjs/crypto/sm3/sm3.cjs +200 -0
  22. package/dist/cjs/crypto/sm4/index.cjs +101 -0
  23. package/dist/cjs/crypto/sm4/sm4.cjs +498 -0
  24. package/dist/cjs/date/index.cjs +1310 -0
  25. package/dist/cjs/desensitized/index.cjs +78 -0
  26. package/dist/cjs/device/index.cjs +154 -0
  27. package/dist/cjs/dom/index.cjs +132 -0
  28. package/dist/cjs/file/index.cjs +343 -0
  29. package/dist/cjs/function/index.cjs +72 -0
  30. package/dist/cjs/id/index.cjs +6 -2
  31. package/dist/cjs/index.cjs +383 -7
  32. package/dist/cjs/keycode/index.cjs +30 -0
  33. package/dist/cjs/math/index.cjs +310 -0
  34. package/dist/cjs/number/index.cjs +34 -0
  35. package/dist/cjs/object/index.cjs +319 -0
  36. package/dist/cjs/pagination/index.cjs +146 -0
  37. package/dist/cjs/random/index.cjs +27 -0
  38. package/dist/cjs/regexp/index.cjs +103 -0
  39. package/dist/cjs/storage/index.cjs +14 -0
  40. package/dist/cjs/storage/localStorage.cjs +37 -0
  41. package/dist/cjs/storage/sessionStorage.cjs +37 -0
  42. package/dist/cjs/string/index.cjs +361 -0
  43. package/dist/cjs/url/index.cjs +261 -0
  44. package/dist/cjs/validate/index.cjs +484 -0
  45. package/dist/es/ID-card/index.d.ts +36 -0
  46. package/dist/es/ID-card/index.mjs +89 -0
  47. package/dist/es/array/index.d.ts +209 -0
  48. package/dist/es/array/index.mjs +447 -0
  49. package/dist/es/clipboard/index.d.ts +32 -0
  50. package/dist/es/clipboard/index.mjs +126 -0
  51. package/dist/es/color/index.d.ts +55 -0
  52. package/dist/es/color/index.mjs +197 -0
  53. package/dist/es/constants/date.d.ts +4 -0
  54. package/dist/es/constants/date.mjs +176 -0
  55. package/dist/es/constants/id-card.d.ts +4 -0
  56. package/dist/es/constants/id-card.mjs +50 -0
  57. package/dist/es/constants/index.d.ts +11 -0
  58. package/dist/es/constants/keycode.d.ts +1 -0
  59. package/dist/es/constants/keycode.mjs +115 -0
  60. package/dist/es/constants/lang.d.ts +4 -0
  61. package/dist/es/constants/lang.mjs +11 -0
  62. package/dist/es/constants/math.d.ts +4 -0
  63. package/dist/es/constants/math.mjs +11 -0
  64. package/dist/es/constants/regexp.d.ts +4 -0
  65. package/dist/es/constants/regexp.mjs +51 -0
  66. package/dist/es/constants/sort.d.ts +4 -0
  67. package/dist/es/constants/sort.mjs +13 -0
  68. package/dist/es/cookie/index.d.ts +29 -0
  69. package/dist/es/cookie/index.mjs +67 -0
  70. package/dist/es/crypto/base64/base64.d.ts +8 -0
  71. package/dist/es/crypto/base64/base64.mjs +531 -0
  72. package/dist/es/crypto/base64/index.d.ts +53 -0
  73. package/dist/es/crypto/base64/index.mjs +73 -0
  74. package/dist/es/crypto/index.d.ts +8 -0
  75. package/dist/es/crypto/md5/index.d.ts +26 -0
  76. package/dist/es/crypto/md5/index.mjs +44 -0
  77. package/dist/es/crypto/md5/md5.d.ts +11 -0
  78. package/dist/es/crypto/md5/md5.mjs +349 -0
  79. package/dist/es/crypto/sha256/index.d.ts +52 -0
  80. package/dist/es/crypto/sha256/index.mjs +86 -0
  81. package/dist/es/crypto/sha256/sha256.d.ts +82 -0
  82. package/dist/es/crypto/sha256/sha256.mjs +548 -0
  83. package/dist/es/crypto/sm3/index.d.ts +13 -0
  84. package/dist/es/crypto/sm3/index.mjs +24 -0
  85. package/dist/es/crypto/sm3/sm3.d.ts +3 -0
  86. package/dist/es/crypto/sm3/sm3.mjs +197 -0
  87. package/dist/es/crypto/sm4/index.d.ts +56 -0
  88. package/dist/es/crypto/sm4/index.mjs +95 -0
  89. package/dist/es/crypto/sm4/sm4.d.ts +48 -0
  90. package/dist/es/crypto/sm4/sm4.mjs +490 -0
  91. package/dist/es/date/index.d.ts +608 -0
  92. package/dist/es/date/index.mjs +1222 -0
  93. package/dist/es/desensitized/index.d.ts +41 -0
  94. package/dist/es/desensitized/index.mjs +72 -0
  95. package/dist/es/device/index.d.ts +73 -0
  96. package/dist/es/device/index.mjs +140 -0
  97. package/dist/es/dom/index.d.ts +60 -0
  98. package/dist/es/dom/index.mjs +122 -0
  99. package/dist/es/file/index.d.ts +93 -0
  100. package/dist/es/file/index.mjs +327 -0
  101. package/dist/es/function/index.d.ts +26 -0
  102. package/dist/es/function/index.mjs +68 -0
  103. package/dist/es/id/index.d.ts +3 -0
  104. package/dist/es/id/index.mjs +6 -2
  105. package/dist/es/index.d.ts +26 -2
  106. package/dist/es/index.mjs +40 -4
  107. package/dist/es/keycode/index.d.ts +12 -0
  108. package/dist/es/keycode/index.mjs +27 -0
  109. package/dist/es/math/index.d.ts +66 -0
  110. package/dist/es/math/index.mjs +300 -0
  111. package/dist/es/number/index.d.ts +14 -0
  112. package/dist/es/number/index.mjs +31 -0
  113. package/dist/es/object/index.d.ts +84 -0
  114. package/dist/es/object/index.mjs +306 -0
  115. package/dist/es/pagination/index.d.ts +67 -0
  116. package/dist/es/pagination/index.mjs +140 -0
  117. package/dist/es/random/index.d.ts +18 -0
  118. package/dist/es/random/index.mjs +24 -0
  119. package/dist/es/regexp/index.d.ts +63 -0
  120. package/dist/es/regexp/index.mjs +92 -0
  121. package/dist/es/storage/index.d.ts +13 -0
  122. package/dist/es/storage/index.mjs +12 -0
  123. package/dist/es/storage/localStorage.d.ts +21 -0
  124. package/dist/es/storage/localStorage.mjs +32 -0
  125. package/dist/es/storage/sessionStorage.d.ts +21 -0
  126. package/dist/es/storage/sessionStorage.mjs +32 -0
  127. package/dist/es/string/index.d.ts +124 -0
  128. package/dist/es/string/index.mjs +342 -0
  129. package/dist/es/url/index.d.ts +118 -0
  130. package/dist/es/url/index.mjs +243 -0
  131. package/dist/es/validate/index.d.ts +231 -0
  132. package/dist/es/validate/index.mjs +447 -0
  133. package/dist/index.d.ts +2394 -2
  134. package/dist/lib/index.full.umd.js +8059 -29
  135. package/dist/lib/index.full.umd.min.js +2 -2
  136. package/dist/lib/index.full.umd.min.js.map +1 -1
  137. package/dist/resolver/auto-imports.cjs +345 -2
  138. package/dist/resolver/auto-imports.mjs +345 -2
  139. package/dist/resolver/index.cjs +1 -2
  140. package/dist/resolver/index.d.ts +1 -1
  141. package/dist/resolver/index.mjs +1 -2
  142. package/package.json +16 -7
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @module 分页
5
+ */
6
+ /**
7
+ * 获得分页起始数
8
+ * @param {Object} pagination 分页参数
9
+ * @returns {Array} 返回起始数
10
+ */
11
+ function getLimit(pagination = {
12
+ page: 1,
13
+ pageSize: 10,
14
+ total: 0,
15
+ totalPage: 0,
16
+ pagerCount: 7,
17
+ }) {
18
+ return [pagination.pageSize * (pagination.page - 1), pagination.pageSize * pagination.page];
19
+ }
20
+ /**
21
+ * 获得总条数
22
+ * @param {Object} pagination 分页参数
23
+ * @returns {number} 返回总条数
24
+ */
25
+ function getTotalPage(pagination = {
26
+ page: 1,
27
+ pageSize: 10,
28
+ total: 0,
29
+ totalPage: 0,
30
+ pagerCount: 7,
31
+ }) {
32
+ return Math.ceil((pagination.total || 0) / (pagination.pageSize || 0));
33
+ }
34
+ /**
35
+ * 获得彩虹分页器
36
+ * @param {Object} pagination 分页参数
37
+ * @param {Function} callback 回调函数
38
+ * @returns {Promise} 返回彩虹分页器数据
39
+ */
40
+ function getRainbowPager(pagination = {
41
+ page: 1,
42
+ pageSize: 10,
43
+ total: 0,
44
+ totalPage: 0,
45
+ pagerCount: 7,
46
+ }, callback) {
47
+ return new Promise((resolve) => {
48
+ // 分页参数
49
+ const page = pagination.page || 1;
50
+ const totalPage = pagination.totalPage > 0 ? pagination.totalPage : getTotalPage(pagination);
51
+ const pagerCount = pagination.pagerCount || 7;
52
+ // 计算参数
53
+ const isEven = (pagerCount & 1) === 0;
54
+ const left = pagerCount >> 1;
55
+ let right = pagerCount >> 1;
56
+ let pagerLength = pagerCount;
57
+ // 计算生成的分页器数量
58
+ if (isEven) {
59
+ right++;
60
+ }
61
+ if (totalPage < pagerCount) {
62
+ pagerLength = totalPage;
63
+ }
64
+ // 分页器数组
65
+ const pager = new Array(pagerLength);
66
+ // 生成分页器
67
+ if (totalPage >= pagerCount) {
68
+ if (page <= left) {
69
+ for (let i = 0; i < pager.length; i++) {
70
+ pager[i] = i + 1;
71
+ }
72
+ }
73
+ else if (page > totalPage - right) {
74
+ for (let i = 0; i < pager.length; i++) {
75
+ pager[i] = i + totalPage - pagerCount + 1;
76
+ }
77
+ }
78
+ else {
79
+ for (let i = 0; i < pager.length; i++) {
80
+ pager[i] = i + page - left + (isEven ? 1 : 0);
81
+ }
82
+ }
83
+ }
84
+ else {
85
+ for (let i = 0; i < pager.length; i++) {
86
+ pager[i] = i + 1;
87
+ }
88
+ }
89
+ // 支持回调函数和Promise
90
+ callback && callback(pager);
91
+ resolve(pager);
92
+ });
93
+ }
94
+ /**
95
+ * 获得上一页
96
+ * @param {Object} pagination 分页参数
97
+ * @param {Function} callback 回调函数
98
+ * @returns {Promise} 返回上一页
99
+ */
100
+ function getPrevPage(pagination = { page: 1, pageSize: 10, total: 0, totalPage: 0, pagerCount: 7 }, callback) {
101
+ return new Promise((resolve) => {
102
+ if (pagination.page > 1) {
103
+ pagination.page--;
104
+ }
105
+ else {
106
+ pagination.page = 1;
107
+ }
108
+ // 支持回调函数和Promise
109
+ callback && callback(pagination.page);
110
+ resolve(pagination.page);
111
+ });
112
+ }
113
+ /**
114
+ * 获得下一页
115
+ * @description 最后一页会根据totalPage参数判断,如果不传此参数,则会根据参数中pageSize和total重新计算总页数
116
+ * @param {Object} pagination 分页参数
117
+ * @param {Function} callback 回调函数
118
+ * @returns {Promise} 返回下一页
119
+ */
120
+ function getNextPage(pagination = { page: 1, pageSize: 10, total: 0, totalPage: 0, pagerCount: 7 }, callback) {
121
+ return new Promise((resolve) => {
122
+ // 获得总页数,如果没有传totalPage,则需要根据传的pageSize和total计算
123
+ const totalPage = pagination.totalPage > 0 ? pagination.totalPage : getTotalPage(pagination);
124
+ // 计算当前页大于0和小与0的情况
125
+ if (pagination.page > 0) {
126
+ if (pagination.page < totalPage) {
127
+ pagination.page++;
128
+ }
129
+ else {
130
+ pagination.page = totalPage;
131
+ }
132
+ }
133
+ else {
134
+ pagination.page = 1;
135
+ }
136
+ // 支持回调函数和Promise
137
+ callback && callback(pagination.page);
138
+ resolve(pagination.page);
139
+ });
140
+ }
141
+
142
+ exports.getLimit = getLimit;
143
+ exports.getNextPage = getNextPage;
144
+ exports.getPrevPage = getPrevPage;
145
+ exports.getRainbowPager = getRainbowPager;
146
+ exports.getTotalPage = getTotalPage;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @module 随机数
5
+ */
6
+ /**
7
+ * 生成指定大小的随机整数
8
+ * @description n和m参数表示最小和最大范围值,默认0-9之间范围
9
+ * @param {number} min 随机数的最小值,默认 0
10
+ * @param {number} max 随机数的最大值,默认 9
11
+ * @returns {number} 返回指定大小的随机整数
12
+ */
13
+ function getRandom(min = 0, max = 9) {
14
+ return Math.floor(Math.random() * (max - min + 1) + min);
15
+ }
16
+ /**
17
+ * 生成固定位数的随机整数
18
+ * @description 默认是1,代表生成0-9之间一位,如果是2,则生成10-99之间两位,以此类推
19
+ * @param {number} len 固定的位数
20
+ * @returns {number} 返回固定位数的随机数
21
+ */
22
+ function getRandomDigit(len = 1) {
23
+ return Math.floor((Math.random() + Math.floor(Math.random() * 9 + 1)) * Math.pow(10, len - 1));
24
+ }
25
+
26
+ exports.getRandom = getRandom;
27
+ exports.getRandomDigit = getRandomDigit;
@@ -0,0 +1,103 @@
1
+ 'use strict';
2
+
3
+ var regexp = require('../constants/regexp.cjs');
4
+
5
+ /**
6
+ * @module 正则
7
+ */
8
+ /* 正则校验方法 */
9
+ /**
10
+ * 正则校验的方法
11
+ * @description 类型为REGEXP对应的正则
12
+ * @param {string} value 校验的参数
13
+ * @param {RegExp} regex 使用的REGEXP中的正则
14
+ * @returns {boolean} 返回校验的结果
15
+ */
16
+ function regexpTest(value, regex) {
17
+ return new RegExp(regex).test(value);
18
+ }
19
+ /* 常用校验 */
20
+ /**
21
+ * 是中文
22
+ * @param {string} value 校验的参数
23
+ * @returns {boolean} 返回校验的结果
24
+ */
25
+ function isChinese(value) {
26
+ return regexpTest(value, regexp.REGEXP.CH);
27
+ }
28
+ /**
29
+ * 是英文
30
+ * @param {string} value 校验的参数
31
+ * @returns {boolean} 返回校验的结果
32
+ */
33
+ function isEnglish(value) {
34
+ return regexpTest(value, regexp.REGEXP.EN);
35
+ }
36
+ /**
37
+ * 是外链
38
+ * @description 支持http,https,mail,tel电话
39
+ * @param {string} value 校验的参数
40
+ * @returns {boolean} 返回校验的结果
41
+ */
42
+ function isExternal(value) {
43
+ return regexpTest(value, regexp.REGEXP.EXTERNAL);
44
+ }
45
+ /**
46
+ * 是小写字母
47
+ * @param {string} value 校验的参数
48
+ * @returns {boolean} 返回校验的结果
49
+ */
50
+ function isLowerCase(value) {
51
+ return regexpTest(value, regexp.REGEXP.LOWER_CASE);
52
+ }
53
+ /**
54
+ * 是大写字母
55
+ * @param {string} value 校验的参数
56
+ * @returns {boolean} 返回校验的结果
57
+ */
58
+ function isUpperCase(value) {
59
+ return regexpTest(value, regexp.REGEXP.UPPER_CASE);
60
+ }
61
+ /**
62
+ * 是11位手机号码
63
+ * @param {string} value 校验的参数
64
+ * @returns {boolean} 返回校验的结果
65
+ */
66
+ function isMobile(value) {
67
+ return regexpTest(value, regexp.REGEXP.MOBILE);
68
+ }
69
+ /**
70
+ * 是邮箱
71
+ * @param {string} value 校验的参数
72
+ * @returns {boolean} 返回校验的结果
73
+ */
74
+ function isEmail(value) {
75
+ return regexpTest(value, regexp.REGEXP.EMAIL);
76
+ }
77
+ /**
78
+ * 是身份证号码(15-18位)
79
+ * @param {string} value 校验的参数
80
+ * @returns {boolean} 返回校验的结果
81
+ */
82
+ function isIdCard(value) {
83
+ return regexpTest(value, regexp.REGEXP.ID_CARD);
84
+ }
85
+ /**
86
+ * 是url链接
87
+ * @param {string} value 校验的参数
88
+ * @returns {boolean} 返回校验的结果
89
+ */
90
+ function isUrl(value) {
91
+ return regexpTest(value, regexp.REGEXP.URL);
92
+ }
93
+
94
+ exports.isChinese = isChinese;
95
+ exports.isEmail = isEmail;
96
+ exports.isEnglish = isEnglish;
97
+ exports.isExternal = isExternal;
98
+ exports.isIdCard = isIdCard;
99
+ exports.isLowerCase = isLowerCase;
100
+ exports.isMobile = isMobile;
101
+ exports.isUpperCase = isUpperCase;
102
+ exports.isUrl = isUrl;
103
+ exports.regexpTest = regexpTest;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @module 浏览器Storage
5
+ */
6
+ /**
7
+ * 浏览器是否支持 Storage
8
+ * @returns {boolean} 返回true和false
9
+ */
10
+ function isSupportStorage() {
11
+ return !!(window.localStorage && window.sessionStorage);
12
+ }
13
+
14
+ exports.isSupportStorage = isSupportStorage;
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ /* localStorage存储 */
4
+ /**
5
+ * 通过key从localStorage缓存中获取数据
6
+ * @param {string} key key值
7
+ * @returns {string} 返回数据
8
+ */
9
+ function getLocalStorage(key) {
10
+ return window.localStorage.getItem(key) || undefined;
11
+ }
12
+ /**
13
+ * 设置localStorage缓存数据
14
+ * @param {string} key key值
15
+ * @param {string} value value值
16
+ */
17
+ function setLocalStorage(key, value) {
18
+ window.localStorage.setItem(key, value);
19
+ }
20
+ /**
21
+ * 通过key从localStorage缓存中删除数据
22
+ * @param {string} key key值
23
+ */
24
+ function removeLocalStorage(key) {
25
+ window.localStorage.removeItem(key);
26
+ }
27
+ /**
28
+ * 清空localStorage缓存中所有数据
29
+ */
30
+ function clearLocalStorage() {
31
+ window.localStorage.clear();
32
+ }
33
+
34
+ exports.clearLocalStorage = clearLocalStorage;
35
+ exports.getLocalStorage = getLocalStorage;
36
+ exports.removeLocalStorage = removeLocalStorage;
37
+ exports.setLocalStorage = setLocalStorage;
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ /* sessionStorage存储 */
4
+ /**
5
+ * 通过key从sessionStorage缓存中获取数据
6
+ * @param {string} key key值
7
+ * @returns {string} 返回数据
8
+ */
9
+ function getSessionStorage(key) {
10
+ return window.sessionStorage.getItem(key) || undefined;
11
+ }
12
+ /**
13
+ * 设置sessionStorage缓存数据
14
+ * @param {string} key key值
15
+ * @param {string} value value值
16
+ */
17
+ function setSessionStorage(key, value) {
18
+ window.sessionStorage.setItem(key, value);
19
+ }
20
+ /**
21
+ * 通过key从sessionStorage缓存中删除数据
22
+ * @param {string} key key值
23
+ */
24
+ function removeSessionStorage(key) {
25
+ window.sessionStorage.removeItem(key);
26
+ }
27
+ /**
28
+ * 清空sessionStorage缓存中所有数据
29
+ */
30
+ function clearSessionStorage() {
31
+ window.sessionStorage.clear();
32
+ }
33
+
34
+ exports.clearSessionStorage = clearSessionStorage;
35
+ exports.getSessionStorage = getSessionStorage;
36
+ exports.removeSessionStorage = removeSessionStorage;
37
+ exports.setSessionStorage = setSessionStorage;