@ivujs/i-utils 1.1.16 → 1.1.17

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/README.md +21 -19
  2. package/dist/cjs/index.cjs +5 -400
  3. package/dist/es/index.d.ts +1 -26
  4. package/dist/es/index.mjs +2 -55
  5. package/dist/index.d.ts +11 -2851
  6. package/dist/lib/index.full.umd.js +33 -14240
  7. package/dist/lib/index.full.umd.min.js +2 -64
  8. package/dist/lib/index.full.umd.min.js.map +1 -1
  9. package/dist/resolver/auto-imports.cjs +1 -337
  10. package/dist/resolver/auto-imports.mjs +1 -337
  11. package/dist/resolver/index.cjs +1 -1
  12. package/dist/resolver/index.d.ts +1 -1
  13. package/dist/resolver/index.mjs +1 -1
  14. package/package.json +5 -13
  15. package/dist/cjs/ID-card/index.cjs +0 -87
  16. package/dist/cjs/array/index.cjs +0 -470
  17. package/dist/cjs/clipboard/index.cjs +0 -128
  18. package/dist/cjs/color/index.cjs +0 -193
  19. package/dist/cjs/constants/date.cjs +0 -178
  20. package/dist/cjs/constants/id-card.cjs +0 -52
  21. package/dist/cjs/constants/keycode.cjs +0 -117
  22. package/dist/cjs/constants/lang.cjs +0 -13
  23. package/dist/cjs/constants/math.cjs +0 -13
  24. package/dist/cjs/constants/regexp.cjs +0 -53
  25. package/dist/cjs/constants/sort.cjs +0 -15
  26. package/dist/cjs/cookie/index.cjs +0 -70
  27. package/dist/cjs/crypto/aes/aes.cjs +0 -480
  28. package/dist/cjs/crypto/aes/index.cjs +0 -27
  29. package/dist/cjs/crypto/base32/base32.cjs +0 -357
  30. package/dist/cjs/crypto/base32/index.cjs +0 -41
  31. package/dist/cjs/crypto/base64/base64.cjs +0 -348
  32. package/dist/cjs/crypto/base64/index.cjs +0 -59
  33. package/dist/cjs/crypto/des/des.cjs +0 -257
  34. package/dist/cjs/crypto/des/index.cjs +0 -28
  35. package/dist/cjs/crypto/md5/index.cjs +0 -24
  36. package/dist/cjs/crypto/md5/md5.cjs +0 -897
  37. package/dist/cjs/crypto/sha/sha1/index.cjs +0 -24
  38. package/dist/cjs/crypto/sha/sha1/sha1.cjs +0 -529
  39. package/dist/cjs/crypto/sha/sha256/index.cjs +0 -43
  40. package/dist/cjs/crypto/sha/sha256/sha256.cjs +0 -595
  41. package/dist/cjs/crypto/sha/sha3/index.cjs +0 -41
  42. package/dist/cjs/crypto/sha/sha3/sha3.cjs +0 -624
  43. package/dist/cjs/crypto/sha/sha512/index.cjs +0 -81
  44. package/dist/cjs/crypto/sha/sha512/sha512.cjs +0 -950
  45. package/dist/cjs/crypto/sm/lib/asn1.cjs +0 -149
  46. package/dist/cjs/crypto/sm/lib/ec.cjs +0 -315
  47. package/dist/cjs/crypto/sm/lib/jsbn.cjs +0 -1608
  48. package/dist/cjs/crypto/sm/lib/sm3.cjs +0 -158
  49. package/dist/cjs/crypto/sm/lib/utils.cjs +0 -170
  50. package/dist/cjs/crypto/sm/sm2/index.cjs +0 -112
  51. package/dist/cjs/crypto/sm/sm2/sm2.cjs +0 -231
  52. package/dist/cjs/crypto/sm/sm3/index.cjs +0 -15
  53. package/dist/cjs/crypto/sm/sm3/sm3.cjs +0 -93
  54. package/dist/cjs/crypto/sm/sm4/index.cjs +0 -27
  55. package/dist/cjs/crypto/sm/sm4/sm4.cjs +0 -327
  56. package/dist/cjs/crypto/tea/index.cjs +0 -25
  57. package/dist/cjs/crypto/tea/tea.cjs +0 -187
  58. package/dist/cjs/date/index.cjs +0 -1266
  59. package/dist/cjs/desensitized/index.cjs +0 -75
  60. package/dist/cjs/device/index.cjs +0 -151
  61. package/dist/cjs/dom/index.cjs +0 -129
  62. package/dist/cjs/file/index.cjs +0 -333
  63. package/dist/cjs/function/index.cjs +0 -69
  64. package/dist/cjs/keycode/index.cjs +0 -33
  65. package/dist/cjs/math/index.cjs +0 -278
  66. package/dist/cjs/number/index.cjs +0 -31
  67. package/dist/cjs/object/index.cjs +0 -272
  68. package/dist/cjs/pagination/index.cjs +0 -131
  69. package/dist/cjs/random/index.cjs +0 -24
  70. package/dist/cjs/regexp/index.cjs +0 -100
  71. package/dist/cjs/storage/index.cjs +0 -11
  72. package/dist/cjs/storage/localStorage.cjs +0 -37
  73. package/dist/cjs/storage/sessionStorage.cjs +0 -37
  74. package/dist/cjs/string/index.cjs +0 -358
  75. package/dist/cjs/url/index.cjs +0 -258
  76. package/dist/cjs/validate/index.cjs +0 -468
  77. package/dist/cjs/weapp/index.cjs +0 -142
  78. package/dist/es/ID-card/index.d.ts +0 -31
  79. package/dist/es/ID-card/index.mjs +0 -81
  80. package/dist/es/array/index.d.ts +0 -203
  81. package/dist/es/array/index.mjs +0 -441
  82. package/dist/es/clipboard/index.d.ts +0 -29
  83. package/dist/es/clipboard/index.mjs +0 -122
  84. package/dist/es/color/index.d.ts +0 -52
  85. package/dist/es/color/index.mjs +0 -183
  86. package/dist/es/constants/date.d.ts +0 -174
  87. package/dist/es/constants/date.mjs +0 -176
  88. package/dist/es/constants/id-card.d.ts +0 -43
  89. package/dist/es/constants/id-card.mjs +0 -50
  90. package/dist/es/constants/index.d.ts +0 -7
  91. package/dist/es/constants/keycode.d.ts +0 -103
  92. package/dist/es/constants/keycode.mjs +0 -115
  93. package/dist/es/constants/lang.d.ts +0 -4
  94. package/dist/es/constants/lang.mjs +0 -11
  95. package/dist/es/constants/math.d.ts +0 -4
  96. package/dist/es/constants/math.mjs +0 -11
  97. package/dist/es/constants/regexp.d.ts +0 -24
  98. package/dist/es/constants/regexp.mjs +0 -51
  99. package/dist/es/constants/sort.d.ts +0 -5
  100. package/dist/es/constants/sort.mjs +0 -13
  101. package/dist/es/cookie/index.d.ts +0 -29
  102. package/dist/es/cookie/index.mjs +0 -64
  103. package/dist/es/crypto/aes/aes.d.ts +0 -156
  104. package/dist/es/crypto/aes/aes.mjs +0 -478
  105. package/dist/es/crypto/aes/index.d.ts +0 -16
  106. package/dist/es/crypto/aes/index.mjs +0 -24
  107. package/dist/es/crypto/base32/base32.d.ts +0 -3
  108. package/dist/es/crypto/base32/base32.mjs +0 -353
  109. package/dist/es/crypto/base32/index.d.ts +0 -24
  110. package/dist/es/crypto/base32/index.mjs +0 -36
  111. package/dist/es/crypto/base64/base64.d.ts +0 -5
  112. package/dist/es/crypto/base64/base64.mjs +0 -342
  113. package/dist/es/crypto/base64/index.d.ts +0 -36
  114. package/dist/es/crypto/base64/index.mjs +0 -52
  115. package/dist/es/crypto/des/des.d.ts +0 -52
  116. package/dist/es/crypto/des/des.mjs +0 -255
  117. package/dist/es/crypto/des/index.d.ts +0 -14
  118. package/dist/es/crypto/des/index.mjs +0 -25
  119. package/dist/es/crypto/index.d.ts +0 -8
  120. package/dist/es/crypto/md5/index.d.ts +0 -13
  121. package/dist/es/crypto/md5/index.mjs +0 -21
  122. package/dist/es/crypto/md5/md5.d.ts +0 -144
  123. package/dist/es/crypto/md5/md5.mjs +0 -894
  124. package/dist/es/crypto/sha/index.d.ts +0 -4
  125. package/dist/es/crypto/sha/sha1/index.d.ts +0 -13
  126. package/dist/es/crypto/sha/sha1/index.mjs +0 -21
  127. package/dist/es/crypto/sha/sha1/sha1.d.ts +0 -2
  128. package/dist/es/crypto/sha/sha1/sha1.mjs +0 -526
  129. package/dist/es/crypto/sha/sha256/index.d.ts +0 -26
  130. package/dist/es/crypto/sha/sha256/index.mjs +0 -38
  131. package/dist/es/crypto/sha/sha256/sha256.d.ts +0 -4
  132. package/dist/es/crypto/sha/sha256/sha256.mjs +0 -590
  133. package/dist/es/crypto/sha/sha3/index.d.ts +0 -24
  134. package/dist/es/crypto/sha/sha3/index.mjs +0 -36
  135. package/dist/es/crypto/sha/sha3/sha3.d.ts +0 -4
  136. package/dist/es/crypto/sha/sha3/sha3.mjs +0 -619
  137. package/dist/es/crypto/sha/sha512/index.d.ts +0 -52
  138. package/dist/es/crypto/sha/sha512/index.mjs +0 -72
  139. package/dist/es/crypto/sha/sha512/sha512.d.ts +0 -8
  140. package/dist/es/crypto/sha/sha512/sha512.mjs +0 -941
  141. package/dist/es/crypto/sm/index.d.ts +0 -3
  142. package/dist/es/crypto/sm/lib/asn1.d.ts +0 -12
  143. package/dist/es/crypto/sm/lib/asn1.mjs +0 -146
  144. package/dist/es/crypto/sm/lib/ec.d.ts +0 -126
  145. package/dist/es/crypto/sm/lib/ec.mjs +0 -312
  146. package/dist/es/crypto/sm/lib/jsbn.d.ts +0 -198
  147. package/dist/es/crypto/sm/lib/jsbn.mjs +0 -1605
  148. package/dist/es/crypto/sm/lib/sm3.d.ts +0 -5
  149. package/dist/es/crypto/sm/lib/sm3.mjs +0 -155
  150. package/dist/es/crypto/sm/lib/utils.d.ts +0 -53
  151. package/dist/es/crypto/sm/lib/utils.mjs +0 -158
  152. package/dist/es/crypto/sm/sm2/index.d.ts +0 -71
  153. package/dist/es/crypto/sm/sm2/index.mjs +0 -101
  154. package/dist/es/crypto/sm/sm2/sm2.d.ts +0 -34
  155. package/dist/es/crypto/sm/sm2/sm2.mjs +0 -220
  156. package/dist/es/crypto/sm/sm3/index.d.ts +0 -7
  157. package/dist/es/crypto/sm/sm3/index.mjs +0 -13
  158. package/dist/es/crypto/sm/sm3/sm3.d.ts +0 -1
  159. package/dist/es/crypto/sm/sm3/sm3.mjs +0 -91
  160. package/dist/es/crypto/sm/sm4/index.d.ts +0 -16
  161. package/dist/es/crypto/sm/sm4/index.mjs +0 -24
  162. package/dist/es/crypto/sm/sm4/sm4.d.ts +0 -2
  163. package/dist/es/crypto/sm/sm4/sm4.mjs +0 -324
  164. package/dist/es/crypto/tea/index.d.ts +0 -14
  165. package/dist/es/crypto/tea/index.mjs +0 -22
  166. package/dist/es/crypto/tea/tea.d.ts +0 -69
  167. package/dist/es/crypto/tea/tea.mjs +0 -185
  168. package/dist/es/date/index.d.ts +0 -547
  169. package/dist/es/date/index.mjs +0 -1179
  170. package/dist/es/desensitized/index.d.ts +0 -38
  171. package/dist/es/desensitized/index.mjs +0 -69
  172. package/dist/es/device/index.d.ts +0 -67
  173. package/dist/es/device/index.mjs +0 -137
  174. package/dist/es/dom/index.d.ts +0 -57
  175. package/dist/es/dom/index.mjs +0 -119
  176. package/dist/es/file/index.d.ts +0 -93
  177. package/dist/es/file/index.mjs +0 -317
  178. package/dist/es/function/index.d.ts +0 -23
  179. package/dist/es/function/index.mjs +0 -65
  180. package/dist/es/keycode/index.d.ts +0 -12
  181. package/dist/es/keycode/index.mjs +0 -30
  182. package/dist/es/math/index.d.ts +0 -66
  183. package/dist/es/math/index.mjs +0 -268
  184. package/dist/es/number/index.d.ts +0 -14
  185. package/dist/es/number/index.mjs +0 -28
  186. package/dist/es/object/index.d.ts +0 -83
  187. package/dist/es/object/index.mjs +0 -259
  188. package/dist/es/pagination/index.d.ts +0 -34
  189. package/dist/es/pagination/index.mjs +0 -125
  190. package/dist/es/random/index.d.ts +0 -15
  191. package/dist/es/random/index.mjs +0 -21
  192. package/dist/es/regexp/index.d.ts +0 -63
  193. package/dist/es/regexp/index.mjs +0 -89
  194. package/dist/es/storage/index.d.ts +0 -7
  195. package/dist/es/storage/index.mjs +0 -9
  196. package/dist/es/storage/localStorage.d.ts +0 -21
  197. package/dist/es/storage/localStorage.mjs +0 -32
  198. package/dist/es/storage/sessionStorage.d.ts +0 -21
  199. package/dist/es/storage/sessionStorage.mjs +0 -32
  200. package/dist/es/string/index.d.ts +0 -121
  201. package/dist/es/string/index.mjs +0 -339
  202. package/dist/es/url/index.d.ts +0 -118
  203. package/dist/es/url/index.mjs +0 -240
  204. package/dist/es/validate/index.d.ts +0 -228
  205. package/dist/es/validate/index.mjs +0 -431
  206. package/dist/es/weapp/index.d.ts +0 -57
  207. package/dist/es/weapp/index.mjs +0 -131
  208. package/dist/lib/index.full.cjs.js +0 -14264
  209. package/dist/lib/index.full.cjs.min.js +0 -69
  210. package/dist/lib/index.full.cjs.min.js.map +0 -1
  211. package/dist/lib/index.full.esm.js +0 -13910
  212. package/dist/lib/index.full.esm.min.js +0 -64
  213. package/dist/lib/index.full.esm.min.js.map +0 -1
@@ -1,131 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * 获得分页起始数
5
- * @param {Object} pagination 分页参数
6
- * @returns {Array} 返回起始数
7
- */
8
- function getLimit(pagination = { page: 1, pageSize: 10, total: 0, totalPage: 0, pagerCount: 7 }) {
9
- return [pagination.pageSize * (pagination.page - 1), pagination.pageSize * pagination.page];
10
- }
11
- /**
12
- * 获得总条数
13
- * @param {Object} pagination 分页参数
14
- * @returns {Number} 返回总条数
15
- */
16
- function getTotalPage(pagination = { page: 1, pageSize: 10, total: 0, totalPage: 0, pagerCount: 7 }) {
17
- return Math.ceil((pagination.total || 0) / (pagination.pageSize || 0));
18
- }
19
- /**
20
- * 获得彩虹分页器
21
- * @param {Object} pagination 分页参数
22
- * @param {Function} callback 回调函数
23
- * @returns {Promise} 返回彩虹分页器数据
24
- */
25
- function getRainbowPager(pagination = {
26
- page: 1,
27
- pageSize: 10,
28
- total: 0,
29
- totalPage: 0,
30
- pagerCount: 7,
31
- }, callback) {
32
- return new Promise((resolve) => {
33
- // 分页参数
34
- let page = pagination.page || 1;
35
- let totalPage = pagination.totalPage > 0 ? pagination.totalPage : getTotalPage(pagination);
36
- let pagerCount = pagination.pagerCount || 7;
37
- // 计算参数
38
- let isEven = (pagerCount & 1) === 0;
39
- let left = pagerCount >> 1;
40
- let right = pagerCount >> 1;
41
- let pagerLength = pagerCount;
42
- // 计算生成的分页器数量
43
- if (isEven) {
44
- right++;
45
- }
46
- if (totalPage < pagerCount) {
47
- pagerLength = totalPage;
48
- }
49
- // 分页器数组
50
- let pager = new Array(pagerLength);
51
- // 生成分页器
52
- if (totalPage >= pagerCount) {
53
- if (page <= left) {
54
- for (let i = 0; i < pager.length; i++) {
55
- pager[i] = i + 1;
56
- }
57
- }
58
- else if (page > totalPage - right) {
59
- for (let i = 0; i < pager.length; i++) {
60
- pager[i] = i + totalPage - pagerCount + 1;
61
- }
62
- }
63
- else {
64
- for (let i = 0; i < pager.length; i++) {
65
- pager[i] = i + page - left + (isEven ? 1 : 0);
66
- }
67
- }
68
- }
69
- else {
70
- for (let i = 0; i < pager.length; i++) {
71
- pager[i] = i + 1;
72
- }
73
- }
74
- // 支持回调函数和Promise
75
- callback && callback(pager);
76
- resolve(pager);
77
- });
78
- }
79
- /**
80
- * 获得上一页
81
- * @param {Object} pagination 分页参数
82
- * @param {Function} callback 回调函数
83
- * @returns {Promise} 返回上一页
84
- */
85
- function getPrevPage(pagination = { page: 1, pageSize: 10, total: 0, totalPage: 0, pagerCount: 7 }, callback) {
86
- return new Promise((resolve) => {
87
- if (pagination.page > 1) {
88
- pagination.page--;
89
- }
90
- else {
91
- pagination.page = 1;
92
- }
93
- // 支持回调函数和Promise
94
- callback && callback(pagination.page);
95
- resolve(pagination.page);
96
- });
97
- }
98
- /**
99
- * 获得下一页
100
- * @description 最后一页会根据totalPage参数判断,如果不传此参数,则会根据参数中pageSize和total重新计算总页数
101
- * @param {Object} pagination 分页参数
102
- * @param {Function} callback 回调函数
103
- * @returns {Promise} 返回下一页
104
- */
105
- function getNextPage(pagination = { page: 1, pageSize: 10, total: 0, totalPage: 0, pagerCount: 7 }, callback) {
106
- return new Promise((resolve) => {
107
- // 获得总页数,如果没有传totalPage,则需要根据传的pageSize和total计算
108
- let totalPage = pagination.totalPage > 0 ? pagination.totalPage : getTotalPage(pagination);
109
- // 计算当前页大于0和小与0的情况
110
- if (pagination.page > 0) {
111
- if (pagination.page < totalPage) {
112
- pagination.page++;
113
- }
114
- else {
115
- pagination.page = totalPage;
116
- }
117
- }
118
- else {
119
- pagination.page = 1;
120
- }
121
- // 支持回调函数和Promise
122
- callback && callback(pagination.page);
123
- resolve(pagination.page);
124
- });
125
- }
126
-
127
- exports.getLimit = getLimit;
128
- exports.getNextPage = getNextPage;
129
- exports.getPrevPage = getPrevPage;
130
- exports.getRainbowPager = getRainbowPager;
131
- exports.getTotalPage = getTotalPage;
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * 生成指定大小的随机整数
5
- * @description n和m参数表示最小和最大范围值,默认0-9之间范围
6
- * @param {Number} min 随机数的最小值,默认 0
7
- * @param {Number} max 随机数的最大值,默认 9
8
- * @returns {Number} 返回指定大小的随机整数
9
- */
10
- function getRandom(min = 0, max = 9) {
11
- return Math.floor(Math.random() * (max - min + 1) + min);
12
- }
13
- /**
14
- * 生成固定位数的随机整数
15
- * @description 默认是1,代表生成0-9之间一位,如果是2,则生成10-99之间两位,以此类推
16
- * @param {Number} len 固定的位数
17
- * @returns {Number} 返回固定位数的随机数
18
- */
19
- function getRandomDigit(len = 1) {
20
- return Math.floor((Math.random() + Math.floor(Math.random() * 9 + 1)) * Math.pow(10, len - 1));
21
- }
22
-
23
- exports.getRandom = getRandom;
24
- exports.getRandomDigit = getRandomDigit;
@@ -1,100 +0,0 @@
1
- 'use strict';
2
-
3
- var regexp = require('../constants/regexp.cjs');
4
-
5
- /* 正则校验方法 */
6
- /**
7
- * 正则校验的方法
8
- * @description 类型为REGEXP对应的正则
9
- * @param {String|Number} value 校验的参数
10
- * @param {RegExp} regex 使用的REGEXP中的正则
11
- * @returns {Boolean} 返回校验的结果
12
- */
13
- function regexpTest(value, regex) {
14
- return new RegExp(regex).test(value);
15
- }
16
- /* 常用校验 */
17
- /**
18
- * 是中文
19
- * @param {String} value 校验的参数
20
- * @returns {Boolean} 返回校验的结果
21
- */
22
- function isChinese(value) {
23
- return regexpTest(value, regexp.REGEXP.CH);
24
- }
25
- /**
26
- * 是英文
27
- * @param {String} value 校验的参数
28
- * @returns {Boolean} 返回校验的结果
29
- */
30
- function isEnglish(value) {
31
- return regexpTest(value, regexp.REGEXP.EN);
32
- }
33
- /**
34
- * 是外链
35
- * @description 支持http,https,mail,tel电话
36
- * @param {String} value 校验的参数
37
- * @returns {Boolean} 返回校验的结果
38
- */
39
- function isExternal(value) {
40
- return regexpTest(value, regexp.REGEXP.EXTERNAL);
41
- }
42
- /**
43
- * 是小写字母
44
- * @param {String} value 校验的参数
45
- * @returns {Boolean} 返回校验的结果
46
- */
47
- function isLowerCase(value) {
48
- return regexpTest(value, regexp.REGEXP.LOWER_CASE);
49
- }
50
- /**
51
- * 是大写字母
52
- * @param {String} value 校验的参数
53
- * @returns {Boolean} 返回校验的结果
54
- */
55
- function isUpperCase(value) {
56
- return regexpTest(value, regexp.REGEXP.UPPER_CASE);
57
- }
58
- /**
59
- * 是11位手机号码
60
- * @param {String} value 校验的参数
61
- * @returns {Boolean} 返回校验的结果
62
- */
63
- function isMobile(value) {
64
- return regexpTest(value, regexp.REGEXP.MOBILE);
65
- }
66
- /**
67
- * 是邮箱
68
- * @param {String} value 校验的参数
69
- * @returns {Boolean} 返回校验的结果
70
- */
71
- function isEmail(value) {
72
- return regexpTest(value, regexp.REGEXP.EMAIL);
73
- }
74
- /**
75
- * 是身份证号码(15-18位)
76
- * @param {String} value 校验的参数
77
- * @returns {Boolean} 返回校验的结果
78
- */
79
- function isIdCard(value) {
80
- return regexpTest(value, regexp.REGEXP.ID_CARD);
81
- }
82
- /**
83
- * 是url链接
84
- * @param {String} value 校验的参数
85
- * @returns {Boolean} 返回校验的结果
86
- */
87
- function isUrl(value) {
88
- return regexpTest(value, regexp.REGEXP.URL);
89
- }
90
-
91
- exports.isChinese = isChinese;
92
- exports.isEmail = isEmail;
93
- exports.isEnglish = isEnglish;
94
- exports.isExternal = isExternal;
95
- exports.isIdCard = isIdCard;
96
- exports.isLowerCase = isLowerCase;
97
- exports.isMobile = isMobile;
98
- exports.isUpperCase = isUpperCase;
99
- exports.isUrl = isUrl;
100
- exports.regexpTest = regexpTest;
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * 浏览器是否支持 Storage
5
- * @returns {Boolean} 返回true和false
6
- */
7
- function isSupportStorage() {
8
- return !!(window.localStorage && window.sessionStorage);
9
- }
10
-
11
- exports.isSupportStorage = isSupportStorage;
@@ -1,37 +0,0 @@
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;
@@ -1,37 +0,0 @@
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) || "";
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;
@@ -1,358 +0,0 @@
1
- 'use strict';
2
-
3
- /* 字符串处理 */
4
- /**
5
- * 字符串中是否包含指定的元素
6
- * @param {String} value 包含的元素
7
- * @param {String} str 查找的字符串
8
- * @returns {Boolean} 返回true和false
9
- */
10
- function inString(value, str) {
11
- return str.includes(value);
12
- }
13
- /**
14
- * 去除字符串前后位置空格
15
- * @param {String} value 参数
16
- * @returns {String} 返回处理后的字符串
17
- */
18
- function trim(value) {
19
- return value.replace(/(^\s*)|(\s*$)/g, "");
20
- }
21
- /**
22
- * 去除字符串开始位置的空格
23
- * @param {String} value 参数
24
- * @returns {String} 返回处理后的字符串
25
- */
26
- function trimStart(value) {
27
- return value.replace(/(^\s*)/g, "");
28
- }
29
- /**
30
- * 去除字符串结束位置的空格
31
- * @param {String} value 参数
32
- * @returns {String} 返回处理后的字符串
33
- */
34
- function trimEnd(value) {
35
- return value.replace(/(\s*$)/g, "");
36
- }
37
- /**
38
- * 去除字符串中全部的空格
39
- * @param {String} value 参数
40
- * @returns {String} 返回处理后的字符串
41
- */
42
- function trimAll(value) {
43
- return value.replace(/\s+/g, "");
44
- }
45
- /**
46
- * 替换所有指定字符串为新的字符串
47
- * @param {String} value 参数
48
- * @param {String} oldSubstr 需要替换的字符串
49
- * @param {String} newSubstr 替换后的字符串
50
- * @returns {String} 返回处理后的字符串
51
- */
52
- function replaceAll(value, oldSubstr, newSubstr) {
53
- return value.replace(new RegExp(oldSubstr, "gm"), newSubstr);
54
- }
55
- /* 字符串转换 */
56
- /**
57
- * 字符串转大写
58
- * @param {String} value 参数
59
- * @returns {String} 返回处理后的字符串
60
- */
61
- function toUpperCase(value) {
62
- return String(value).toLocaleUpperCase();
63
- }
64
- /**
65
- * 字符串转小写
66
- * @param {String} value 参数
67
- * @returns {String} 返回处理后的字符串
68
- */
69
- function toLowerCase(value) {
70
- String(value).toLocaleLowerCase();
71
- }
72
- /**
73
- * 转为 snake_case 下划线命名
74
- * @description 支持 驼峰命名,短横命名,帕斯卡命名
75
- * @param {String} value 参数
76
- * @returns {String} 返回处理后的字符串
77
- */
78
- function toSnakeCase(value) {
79
- // 驼峰
80
- if (/^[a-z]$/.test(value.charAt(0)) && !(value.indexOf("-") > 0 || value.indexOf("_") > 0)) {
81
- return value.replace(/([A-Z])/g, "_$1").toLowerCase();
82
- }
83
- // 短横
84
- if (value.indexOf("-") > 0) {
85
- return value.replace(/-/g, "_").toLowerCase();
86
- }
87
- // 帕斯卡
88
- if (/^[A-Z]$/.test(value.charAt(0)) && !(value.indexOf("-") > 0 || value.indexOf("_") > 0)) {
89
- value = value.charAt(0).toLowerCase() + value.slice(1);
90
- return value.replace(/([A-Z])/g, "_$1").toLowerCase();
91
- }
92
- }
93
- /**
94
- * 转为 kebab-case 短横命名
95
- * @description 支持 下划线,驼峰命名,帕斯卡命名
96
- * @param {String} value 参数
97
- * @returns {String} 返回处理后的字符串
98
- */
99
- function toKebabCase(value) {
100
- // 下划线
101
- if (value.indexOf("_") > 0) {
102
- return value.replace(/_/g, "-").toLowerCase();
103
- }
104
- // 驼峰
105
- if (/^[a-z]$/.test(value.charAt(0)) && !(value.indexOf("-") > 0 || value.indexOf("_") > 0)) {
106
- return value.replace(/([A-Z])/g, "-$1").toLowerCase();
107
- }
108
- // 帕斯卡
109
- if (/^[A-Z]$/.test(value.charAt(0)) && !(value.indexOf("-") > 0 || value.indexOf("_") > 0)) {
110
- let newStr = value.charAt(0).toLowerCase() + value.slice(1);
111
- return newStr.replace(/([A-Z])/g, "-$1").toLowerCase();
112
- }
113
- }
114
- /**
115
- * 转为 camelCase 驼峰命名
116
- * @description 支持 下划线命名,短横命名,帕斯卡命名
117
- * @param {String} value 参数
118
- * @returns {String} 返回处理后的字符串
119
- */
120
- function toCamelCase(value) {
121
- // 下划线
122
- if (value.indexOf("_") > 0) {
123
- return value.replace(/\_(\w)/g, function (all, letter) {
124
- return letter.toUpperCase();
125
- });
126
- }
127
- // 短横
128
- else if (value.indexOf("-") > 0) {
129
- return value.replace(/\-(\w)/g, function (all, letter) {
130
- return letter.toUpperCase();
131
- });
132
- }
133
- // 帕斯卡
134
- else if (/^[A-Z]$/.test(value.charAt(0)) && !(value.indexOf("-") > 0 || value.indexOf("_") > 0)) {
135
- return value.charAt(0).toLowerCase() + value.slice(1);
136
- }
137
- // 返回自身
138
- else {
139
- return value;
140
- }
141
- }
142
- /**
143
- * 转为 PascalCase 帕斯卡命名
144
- * @description 支持 下划线命名,短横命名,驼峰命名
145
- * @param {String} value 参数
146
- * @returns {String} 返回处理后的字符串
147
- */
148
- function toPascalCase(value) {
149
- // 下划线
150
- if (value.indexOf("_") > 0) {
151
- let newStr = value.replace(/\_(\w)/g, function (all, letter) {
152
- return letter.toUpperCase();
153
- });
154
- return newStr.charAt(0).toUpperCase() + newStr.slice(1);
155
- }
156
- // 短横
157
- else if (value.indexOf("-") > 0) {
158
- let newStr = value.replace(/\-(\w)/g, function (all, letter) {
159
- return letter.toUpperCase();
160
- });
161
- return newStr.charAt(0).toUpperCase() + newStr.slice(1);
162
- }
163
- // 驼峰
164
- else if (/^[a-z]$/.test(value.charAt(0)) && !(value.indexOf("-") > 0 || value.indexOf("_") > 0)) {
165
- return value.charAt(0).toUpperCase() + value.slice(1);
166
- }
167
- // 返回自身
168
- else {
169
- return value;
170
- }
171
- }
172
- /* 字符串格式化 */
173
- /**
174
- * 数字前补齐0达到指定位数
175
- * @description 相当于原生的 padStart(2,'0')
176
- * @param {Number|String} value 补零的数字
177
- * @param {Number} maxLength 补齐0后的最大长度,默认2位
178
- * @returns {String} 返回补0后指定位数的字符串
179
- */
180
- function zeroStart(value, maxLength = 2) {
181
- let len = value.toString().length;
182
- while (len < maxLength) {
183
- value = "0" + value;
184
- len++;
185
- }
186
- return value;
187
- }
188
- /**
189
- * 数字后补齐0达到指定位数
190
- * @description 相当于原生的 padEnd(2,'0')
191
- * @param {Number|String} value 补零的数字
192
- * @param {Number} maxLength 补齐0后的最大长度,默认2位
193
- * @returns {String} 返回补0后指定位数的字符串
194
- */
195
- function zeroEnd(value, maxLength = 2) {
196
- let len = value.toString().length;
197
- while (len < maxLength) {
198
- value = value + "0";
199
- len++;
200
- }
201
- return value;
202
- }
203
- /**
204
- * 格式化为标题样式
205
- * @param {String} value 字符串值
206
- * @returns {String} 返回格式化后的标题样式
207
- */
208
- function formatTitle(value) {
209
- if (!value)
210
- return "";
211
- return value
212
- .split(/(?=[A-Z])|[\.\-\s_]/)
213
- .map((s) => s.trim())
214
- .filter((s) => !!s)
215
- .map((s) => toPascalCase(s.toLowerCase()))
216
- .join(" ");
217
- }
218
- /**
219
- * 格式化字符串模版
220
- * @param {String} value 字符串值
221
- * @param {Object} data 模版数据
222
- * @returns {String} 返回格式化后的模版字符串
223
- */
224
- function formatTemplate(value, data) {
225
- if (!value)
226
- return "";
227
- return Array.from(value.matchAll(/\{\{(.+?)\}\}/g)).reduce((acc, match) => {
228
- return acc.replace(match[0], data[match[1]]);
229
- }, value);
230
- }
231
- /**
232
- * 格式化千分位数字
233
- * @description 支持任意数据传参,如果非数字则不会格式化,并返回原数据
234
- * @param {Number|String} num 数字
235
- * @returns {String} 返回格式化后的千分位数字
236
- */
237
- function formatThousand(num) {
238
- if (!parseFloat(num))
239
- return num;
240
- num = String(num);
241
- let regex = num.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
242
- return num.replace(regex, "$1,");
243
- }
244
- /**
245
- * 格式化人民币金额大写
246
- * @param {Number|String} money 金额
247
- * @returns {String} 返回金额大写
248
- */
249
- function formatRmbChinese(money) {
250
- // 汉字的数字
251
- let cnNums = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
252
- // 基本单位
253
- let cnIntRadiance = ["", "拾", "佰", "仟"];
254
- // 对应整数部分扩展单位
255
- let cnIntUnits = ["", "万", "亿", "兆"];
256
- // 对应小数部分单位
257
- let cnDecUnits = ["角", "分", "毫", "厘"];
258
- // 整数金额时后面跟的字符
259
- let cnInteger = "整";
260
- // 整型完以后的单位
261
- let cnIntLast = "元";
262
- // 最大处理的数字
263
- let maxNum = Number("999999999999999.9999");
264
- // 金额整数部分
265
- let integerNum;
266
- // 金额小数部分
267
- let decimalNum;
268
- // 输出的中文金额字符串
269
- let chineseStr = "";
270
- // 分离金额后用的数组,预定义
271
- let parts;
272
- if (money === "") {
273
- // 不能用==
274
- return "";
275
- }
276
- money = parseFloat(money);
277
- if (money >= maxNum) {
278
- // 超出最大处理数字,抛出异常
279
- throw new Error("Calculated number overflow!");
280
- }
281
- if (money === 0) {
282
- chineseStr = cnNums[0] + cnIntLast + cnInteger;
283
- return chineseStr;
284
- }
285
- // 转换为字符串
286
- money = money.toString();
287
- if (money.indexOf(".") === -1) {
288
- integerNum = money;
289
- decimalNum = "";
290
- }
291
- else {
292
- parts = money.split(".");
293
- integerNum = parts[0];
294
- decimalNum = parts[1].substr(0, 4);
295
- }
296
- // 获取整型部分转换
297
- if (parseInt(integerNum, 10) > 0) {
298
- let zeroCount = 0;
299
- let IntLen = integerNum.length;
300
- for (let i = 0; i < IntLen; i++) {
301
- let n = integerNum.substr(i, 1);
302
- let p = IntLen - i - 1;
303
- let q = p / 4;
304
- let m = p % 4;
305
- if (n === "0") {
306
- zeroCount++;
307
- }
308
- else {
309
- if (zeroCount > 0) {
310
- chineseStr += cnNums[0];
311
- }
312
- // 归零
313
- zeroCount = 0;
314
- chineseStr += cnNums[parseInt(n)] + cnIntRadiance[m];
315
- }
316
- if (m === 0 && zeroCount < 4) {
317
- chineseStr += cnIntUnits[q];
318
- }
319
- }
320
- chineseStr += cnIntLast;
321
- }
322
- // 小数部分
323
- if (decimalNum !== "") {
324
- let decLen = decimalNum.length;
325
- for (let i = 0; i < decLen; i++) {
326
- let n = decimalNum.substr(i, 1);
327
- if (n !== "0") {
328
- chineseStr += cnNums[Number(n)] + cnDecUnits[i];
329
- }
330
- }
331
- }
332
- if (chineseStr === "") {
333
- chineseStr += cnNums[0] + cnIntLast + cnInteger;
334
- }
335
- else if (decimalNum === "") {
336
- chineseStr += cnInteger;
337
- }
338
- return chineseStr;
339
- }
340
-
341
- exports.formatRmbChinese = formatRmbChinese;
342
- exports.formatTemplate = formatTemplate;
343
- exports.formatThousand = formatThousand;
344
- exports.formatTitle = formatTitle;
345
- exports.inString = inString;
346
- exports.replaceAll = replaceAll;
347
- exports.toCamelCase = toCamelCase;
348
- exports.toKebabCase = toKebabCase;
349
- exports.toLowerCase = toLowerCase;
350
- exports.toPascalCase = toPascalCase;
351
- exports.toSnakeCase = toSnakeCase;
352
- exports.toUpperCase = toUpperCase;
353
- exports.trim = trim;
354
- exports.trimAll = trimAll;
355
- exports.trimEnd = trimEnd;
356
- exports.trimStart = trimStart;
357
- exports.zeroEnd = zeroEnd;
358
- exports.zeroStart = zeroStart;