@daysnap/utils 0.0.40 → 0.0.42

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 (174) hide show
  1. package/README.md +21 -4
  2. package/docs/README.md +20 -4
  3. package/docs/modules.md +228 -93
  4. package/es/base64ToBlob.js +11 -17
  5. package/es/blobToBase64.js +10 -10
  6. package/es/canvasToBlob.js +4 -6
  7. package/es/clone.d.ts +4 -6
  8. package/es/clone.js +18 -8
  9. package/es/cloneSimple.d.ts +7 -0
  10. package/es/cloneSimple.js +9 -0
  11. package/es/compareVersion.js +27 -40
  12. package/es/compressImage.js +11 -13
  13. package/es/createHexColorByHash.js +59 -56
  14. package/es/debounce.d.ts +5 -0
  15. package/es/debounce.js +14 -0
  16. package/es/downloadFile.js +7 -7
  17. package/es/each.js +11 -10
  18. package/es/filterBankCardNo.js +4 -2
  19. package/es/filterCRLF.js +2 -2
  20. package/es/filterEmoji.js +13 -6
  21. package/es/filterIdCard.js +2 -2
  22. package/es/filterName.js +12 -12
  23. package/es/filterPhone.js +3 -4
  24. package/es/formatAmount.js +18 -19
  25. package/es/formatDate.js +28 -29
  26. package/es/getBlobByUrl.js +17 -18
  27. package/es/getDayMillisecond.js +3 -4
  28. package/es/getImageInfo.js +9 -9
  29. package/es/getRandomColor.js +2 -2
  30. package/es/getVideoInfo.js +11 -11
  31. package/es/inBrowser.js +2 -2
  32. package/es/index.d.ts +4 -0
  33. package/es/index.js +5 -1
  34. package/es/isAndroid.js +2 -2
  35. package/es/isArray.js +2 -2
  36. package/es/isBoolean.js +2 -2
  37. package/es/isEmail.js +2 -2
  38. package/es/isEmpty.js +2 -2
  39. package/es/isEmptyObject.js +2 -2
  40. package/es/isError.js +2 -2
  41. package/es/isFunction.js +2 -2
  42. package/es/isIOS.js +2 -2
  43. package/es/isIdCard.js +2 -2
  44. package/es/isJSONString.js +8 -7
  45. package/es/isLan.js +29 -28
  46. package/es/isLicenseCode.js +2 -2
  47. package/es/isMobile.js +7 -6
  48. package/es/isNull.js +2 -2
  49. package/es/isNumber.js +2 -2
  50. package/es/isObject.js +2 -2
  51. package/es/isPhone.js +2 -2
  52. package/es/isPromise.js +2 -2
  53. package/es/isRegExp.js +2 -2
  54. package/es/isString.js +2 -2
  55. package/es/isURL.d.ts +4 -0
  56. package/es/isURL.js +6 -0
  57. package/es/isUndefined.js +2 -2
  58. package/es/isWeixin.js +2 -2
  59. package/es/isWindow.js +2 -2
  60. package/es/loadResource.d.ts +1 -1
  61. package/es/loadResource.js +27 -23
  62. package/es/omit.js +7 -9
  63. package/es/padding.js +5 -5
  64. package/es/parseDate.js +7 -7
  65. package/es/parseError.js +15 -16
  66. package/es/parseObject.d.ts +2 -1
  67. package/es/parseObject.js +9 -8
  68. package/es/parsePath.js +7 -7
  69. package/es/parseQuery.d.ts +1 -1
  70. package/es/parseQuery.js +13 -24
  71. package/es/pick.js +7 -8
  72. package/es/replaceCrlf.js +2 -2
  73. package/es/reserve.js +2 -2
  74. package/es/round.js +38 -39
  75. package/es/sleep.d.ts +4 -2
  76. package/es/sleep.js +8 -7
  77. package/es/storage/factory.d.ts +2 -2
  78. package/es/storage/factory.js +44 -54
  79. package/es/storage/index.d.ts +4 -4
  80. package/es/storage/index.js +10 -10
  81. package/es/stringTrim.d.ts +3 -1
  82. package/es/stringTrim.js +17 -19
  83. package/es/stringifyQuery.d.ts +1 -1
  84. package/es/stringifyQuery.js +11 -8
  85. package/es/throttle.d.ts +5 -0
  86. package/es/throttle.js +17 -0
  87. package/es/typeOf.d.ts +1 -1
  88. package/es/typeOf.js +2 -2
  89. package/lib/base64ToBlob.js +14 -23
  90. package/lib/blobToBase64.js +13 -15
  91. package/lib/canvasToBlob.js +7 -11
  92. package/lib/clone.d.ts +4 -6
  93. package/lib/clone.js +21 -13
  94. package/lib/cloneSimple.d.ts +7 -0
  95. package/lib/cloneSimple.js +13 -0
  96. package/lib/compareVersion.js +30 -46
  97. package/lib/compressImage.js +15 -19
  98. package/lib/createHexColorByHash.js +60 -60
  99. package/lib/debounce.d.ts +5 -0
  100. package/lib/debounce.js +18 -0
  101. package/lib/downloadFile.js +10 -12
  102. package/lib/each.js +14 -15
  103. package/lib/filterBankCardNo.js +7 -7
  104. package/lib/filterCRLF.js +5 -7
  105. package/lib/filterEmoji.js +16 -11
  106. package/lib/filterIdCard.js +5 -7
  107. package/lib/filterName.js +15 -17
  108. package/lib/filterPhone.js +6 -9
  109. package/lib/formatAmount.js +21 -24
  110. package/lib/formatDate.js +32 -35
  111. package/lib/getBlobByUrl.js +20 -23
  112. package/lib/getDayMillisecond.js +6 -9
  113. package/lib/getImageInfo.js +12 -14
  114. package/lib/getRandomColor.js +5 -7
  115. package/lib/getVideoInfo.js +14 -16
  116. package/lib/inBrowser.js +5 -7
  117. package/lib/index.d.ts +4 -0
  118. package/lib/index.js +84 -708
  119. package/lib/isAndroid.js +5 -7
  120. package/lib/isArray.js +5 -7
  121. package/lib/isBoolean.js +5 -7
  122. package/lib/isEmail.js +5 -7
  123. package/lib/isEmpty.js +7 -9
  124. package/lib/isEmptyObject.js +5 -7
  125. package/lib/isError.js +5 -7
  126. package/lib/isFunction.js +5 -7
  127. package/lib/isIOS.js +5 -7
  128. package/lib/isIdCard.js +5 -7
  129. package/lib/isJSONString.js +12 -13
  130. package/lib/isLan.js +32 -33
  131. package/lib/isLicenseCode.js +5 -7
  132. package/lib/isMobile.js +10 -11
  133. package/lib/isNull.js +5 -7
  134. package/lib/isNumber.js +5 -7
  135. package/lib/isObject.js +5 -7
  136. package/lib/isPhone.js +5 -7
  137. package/lib/isPromise.js +5 -7
  138. package/lib/isRegExp.js +5 -7
  139. package/lib/isString.js +5 -7
  140. package/lib/isURL.d.ts +4 -0
  141. package/lib/isURL.js +10 -0
  142. package/lib/isUndefined.js +5 -7
  143. package/lib/isWeixin.js +5 -7
  144. package/lib/isWindow.js +5 -7
  145. package/lib/loadResource.d.ts +1 -1
  146. package/lib/loadResource.js +31 -29
  147. package/lib/omit.js +10 -15
  148. package/lib/padding.js +8 -10
  149. package/lib/parseDate.js +10 -12
  150. package/lib/parseError.js +21 -24
  151. package/lib/parseObject.d.ts +2 -1
  152. package/lib/parseObject.js +12 -13
  153. package/lib/parsePath.js +10 -12
  154. package/lib/parseQuery.d.ts +1 -1
  155. package/lib/parseQuery.js +17 -31
  156. package/lib/pick.js +10 -13
  157. package/lib/replaceCrlf.js +5 -7
  158. package/lib/reserve.js +6 -8
  159. package/lib/round.js +41 -44
  160. package/lib/sleep.d.ts +4 -2
  161. package/lib/sleep.js +11 -12
  162. package/lib/storage/factory.d.ts +2 -2
  163. package/lib/storage/factory.js +47 -60
  164. package/lib/storage/index.d.ts +4 -4
  165. package/lib/storage/index.js +12 -17
  166. package/lib/stringTrim.d.ts +3 -1
  167. package/lib/stringTrim.js +20 -24
  168. package/lib/stringifyQuery.d.ts +1 -1
  169. package/lib/stringifyQuery.js +15 -14
  170. package/lib/throttle.d.ts +5 -0
  171. package/lib/throttle.js +21 -0
  172. package/lib/typeOf.d.ts +1 -1
  173. package/lib/typeOf.js +5 -7
  174. package/package.json +15 -17
@@ -2,21 +2,20 @@
2
2
  * 根据在线 url 返回 blob
3
3
  */
4
4
  export function getBlobByUrl(url) {
5
- return new Promise(function (resolve, reject) {
6
- var xhr = new XMLHttpRequest();
7
- xhr.open('GET', url, true);
8
- xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
9
- xhr.responseType = 'blob';
10
- xhr.onload = function () {
11
- var status = xhr.status,
12
- response = xhr.response,
13
- statusText = xhr.statusText;
14
- if (status >= 200 && status < 300) {
15
- resolve(response);
16
- } else {
17
- reject(new Error("".concat(statusText, "[").concat(status, "]")));
18
- }
19
- };
20
- xhr.send();
21
- });
22
- }
5
+ return new Promise((resolve, reject) => {
6
+ const xhr = new XMLHttpRequest();
7
+ xhr.open('GET', url, true);
8
+ xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
9
+ xhr.responseType = 'blob';
10
+ xhr.onload = () => {
11
+ const { status, response, statusText } = xhr;
12
+ if (status >= 200 && status < 300) {
13
+ resolve(response);
14
+ }
15
+ else {
16
+ reject(new Error(`${statusText}[${status}]`));
17
+ }
18
+ };
19
+ xhr.send();
20
+ });
21
+ }
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * 获取多少天的毫秒数 默认获取1天的
3
3
  */
4
- export function getDayMillisecond() {
5
- var day = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
6
- return day * 24 * 60 * 60 * 1000;
7
- }
4
+ export function getDayMillisecond(day = 1) {
5
+ return day * 24 * 60 * 60 * 1000;
6
+ }
@@ -2,12 +2,12 @@
2
2
  * 获取图片信息
3
3
  */
4
4
  export function getImageInfo(src) {
5
- return new Promise(function (resolve, reject) {
6
- var image = new Image();
7
- image.onload = function () {
8
- resolve(image);
9
- };
10
- image.onerror = reject;
11
- image.src = src;
12
- });
13
- }
5
+ return new Promise((resolve, reject) => {
6
+ const image = new Image();
7
+ image.onload = () => {
8
+ resolve(image);
9
+ };
10
+ image.onerror = reject;
11
+ image.src = src;
12
+ });
13
+ }
@@ -2,5 +2,5 @@
2
2
  * 随机颜色
3
3
  */
4
4
  export function getRandomColor() {
5
- return "#".concat(Math.floor(Math.random() * 0xffffff).toString(16));
6
- }
5
+ return `#${Math.floor(Math.random() * 0xffffff).toString(16)}`;
6
+ }
@@ -2,14 +2,14 @@
2
2
  * 获取 video 信息
3
3
  */
4
4
  export function getVideoInfo(src) {
5
- return new Promise(function (resolve, reject) {
6
- var video = document.createElement('video');
7
- video.preload = 'metadata';
8
- video.muted = true;
9
- video.onerror = reject;
10
- video.onloadedmetadata = function () {
11
- resolve(video);
12
- };
13
- video.src = src;
14
- });
15
- }
5
+ return new Promise((resolve, reject) => {
6
+ const video = document.createElement('video');
7
+ video.preload = 'metadata';
8
+ video.muted = true;
9
+ video.onerror = reject;
10
+ video.onloadedmetadata = () => {
11
+ resolve(video);
12
+ };
13
+ video.src = src;
14
+ });
15
+ }
package/es/inBrowser.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 判断是否是浏览器环境
3
3
  */
4
4
  export function inBrowser() {
5
- return typeof window !== 'undefined';
6
- }
5
+ return typeof window !== 'undefined';
6
+ }
package/es/index.d.ts CHANGED
@@ -2,9 +2,11 @@ export * from './base64ToBlob';
2
2
  export * from './blobToBase64';
3
3
  export * from './canvasToBlob';
4
4
  export * from './clone';
5
+ export * from './cloneSimple';
5
6
  export * from './compareVersion';
6
7
  export * from './compressImage';
7
8
  export * from './createHexColorByHash';
9
+ export * from './debounce';
8
10
  export * from './downloadFile';
9
11
  export * from './each';
10
12
  export * from './filterBankCardNo';
@@ -42,6 +44,7 @@ export * from './isPhone';
42
44
  export * from './isPromise';
43
45
  export * from './isRegExp';
44
46
  export * from './isString';
47
+ export * from './isURL';
45
48
  export * from './isUndefined';
46
49
  export * from './isWeixin';
47
50
  export * from './isWindow';
@@ -61,4 +64,5 @@ export * from './sleep';
61
64
  export * from './storage';
62
65
  export * from './stringTrim';
63
66
  export * from './stringifyQuery';
67
+ export * from './throttle';
64
68
  export * from './typeOf';
package/es/index.js CHANGED
@@ -3,9 +3,11 @@ export * from './base64ToBlob';
3
3
  export * from './blobToBase64';
4
4
  export * from './canvasToBlob';
5
5
  export * from './clone';
6
+ export * from './cloneSimple';
6
7
  export * from './compareVersion';
7
8
  export * from './compressImage';
8
9
  export * from './createHexColorByHash';
10
+ export * from './debounce';
9
11
  export * from './downloadFile';
10
12
  export * from './each';
11
13
  export * from './filterBankCardNo';
@@ -43,6 +45,7 @@ export * from './isPhone';
43
45
  export * from './isPromise';
44
46
  export * from './isRegExp';
45
47
  export * from './isString';
48
+ export * from './isURL';
46
49
  export * from './isUndefined';
47
50
  export * from './isWeixin';
48
51
  export * from './isWindow';
@@ -62,4 +65,5 @@ export * from './sleep';
62
65
  export * from './storage';
63
66
  export * from './stringTrim';
64
67
  export * from './stringifyQuery';
65
- export * from './typeOf';
68
+ export * from './throttle';
69
+ export * from './typeOf';
package/es/isAndroid.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是安卓
3
3
  */
4
4
  export function isAndroid() {
5
- return /android/.test(navigator.userAgent.toLowerCase());
6
- }
5
+ return /android/.test(navigator.userAgent.toLowerCase());
6
+ }
package/es/isArray.js CHANGED
@@ -4,5 +4,5 @@
4
4
  * @returns 是否
5
5
  */
6
6
  export function isArray(val) {
7
- return Array.isArray(val);
8
- }
7
+ return Array.isArray(val);
8
+ }
package/es/isBoolean.js CHANGED
@@ -3,5 +3,5 @@
3
3
  * @param val 需要判断的值
4
4
  */
5
5
  export function isBoolean(val) {
6
- return typeof val === 'boolean';
7
- }
6
+ return typeof val === 'boolean';
7
+ }
package/es/isEmail.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是邮箱
3
3
  */
4
4
  export function isEmail(val) {
5
- return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(val);
6
- }
5
+ return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(val);
6
+ }
package/es/isEmpty.js CHANGED
@@ -4,5 +4,5 @@ import { isUndefined } from './isUndefined';
4
4
  * 校验是否为空 ''、undefined、null
5
5
  */
6
6
  export function isEmpty(val) {
7
- return val === '' || isNull(val) || isUndefined(val);
8
- }
7
+ return val === '' || isNull(val) || isUndefined(val);
8
+ }
@@ -3,5 +3,5 @@
3
3
  * @param v 对象
4
4
  */
5
5
  export function isEmptyObject(v) {
6
- return !Object.keys(v).length;
7
- }
6
+ return !Object.keys(v).length;
7
+ }
package/es/isError.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是 error
3
3
  */
4
4
  export function isError(val) {
5
- return val instanceof Error;
6
- }
5
+ return val instanceof Error;
6
+ }
package/es/isFunction.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是函数
3
3
  */
4
4
  export function isFunction(val) {
5
- return typeof val === 'function';
6
- }
5
+ return typeof val === 'function';
6
+ }
package/es/isIOS.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是ios
3
3
  */
4
4
  export function isIOS() {
5
- return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
6
- }
5
+ return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
6
+ }
package/es/isIdCard.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是身份证
3
3
  */
4
4
  export function isIdCard(val) {
5
- return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(val);
6
- }
5
+ return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(val);
6
+ }
@@ -4,10 +4,11 @@ import { isObject } from './isObject';
4
4
  * @param v
5
5
  */
6
6
  export function isJSONString(v) {
7
- try {
8
- var obj = JSON.parse(v);
9
- return isObject(obj);
10
- } catch (_unused) {
11
- return false;
12
- }
13
- }
7
+ try {
8
+ const obj = JSON.parse(v);
9
+ return isObject(obj);
10
+ }
11
+ catch (_a) {
12
+ return false;
13
+ }
14
+ }
package/es/isLan.js CHANGED
@@ -3,33 +3,34 @@
3
3
  * @param ip ipv4 地址
4
4
  */
5
5
  export function isLan(ip) {
6
- // eslint-disable-next-line no-param-reassign
7
- ip = ip.toLocaleLowerCase();
8
- if (ip === 'localhost') {
9
- return true;
10
- }
11
- if (ip === '') {
12
- return false;
13
- }
14
- var v = 0;
15
- var aNum = ip.split('.');
16
- if (aNum.length !== 4) {
17
- return false;
18
- }
19
- // eslint-disable-next-line no-bitwise
20
- v += parseInt(aNum[0], 10) << 24;
21
- // eslint-disable-next-line no-bitwise
22
- v += parseInt(aNum[1], 10) << 16;
23
- // eslint-disable-next-line no-bitwise
24
- v += parseInt(aNum[2], 10) << 8;
25
- // eslint-disable-next-line no-bitwise
26
- v += parseInt(aNum[3], 10) << 0;
27
- // eslint-disable-next-line no-bitwise
28
- v = v >> 16 & 0xffff;
29
- return (
6
+ // eslint-disable-next-line no-param-reassign
7
+ ip = ip.toLocaleLowerCase();
8
+ if (ip === 'localhost') {
9
+ return true;
10
+ }
11
+ if (ip === '') {
12
+ return false;
13
+ }
14
+ let v = 0;
15
+ const aNum = ip.split('.');
16
+ if (aNum.length !== 4) {
17
+ return false;
18
+ }
30
19
  // eslint-disable-next-line no-bitwise
31
- v >> 8 === 0x7f ||
20
+ v += parseInt(aNum[0], 10) << 24;
21
+ // eslint-disable-next-line no-bitwise
22
+ v += parseInt(aNum[1], 10) << 16;
23
+ // eslint-disable-next-line no-bitwise
24
+ v += parseInt(aNum[2], 10) << 8;
32
25
  // eslint-disable-next-line no-bitwise
33
- v >> 8 === 0xa || v === 0xc0a8 || v >= 0xac10 && v <= 0xac1f
34
- );
35
- }
26
+ v += parseInt(aNum[3], 10) << 0;
27
+ // eslint-disable-next-line no-bitwise
28
+ v = (v >> 16) & 0xffff;
29
+ return (
30
+ // eslint-disable-next-line no-bitwise
31
+ v >> 8 === 0x7f ||
32
+ // eslint-disable-next-line no-bitwise
33
+ v >> 8 === 0xa ||
34
+ v === 0xc0a8 ||
35
+ (v >= 0xac10 && v <= 0xac1f));
36
+ }
@@ -3,5 +3,5 @@
3
3
  * @param v 车牌号
4
4
  */
5
5
  export function isLicenseCode(v) {
6
- return /(^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4,5}[A-Z0-9挂学警港澳]{1}$)/.test(v);
7
- }
6
+ return /(^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4,5}[A-Z0-9挂学警港澳]{1}$)/.test(v);
7
+ }
package/es/isMobile.js CHANGED
@@ -2,9 +2,10 @@
2
2
  * 校验设备是否是手机
3
3
  */
4
4
  export function isMobile() {
5
- if (typeof navigator === 'undefined' || typeof window === 'undefined') {
6
- return false;
7
- }
8
- var agent = navigator.userAgent || navigator.vendor || window.opera;
9
- return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent === null || agent === void 0 ? void 0 : agent.substr(0, 4));
10
- }
5
+ if (typeof navigator === 'undefined' || typeof window === 'undefined') {
6
+ return false;
7
+ }
8
+ const agent = navigator.userAgent || navigator.vendor || window.opera;
9
+ return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(agent) ||
10
+ /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent === null || agent === void 0 ? void 0 : agent.substr(0, 4)));
11
+ }
package/es/isNull.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是 null
3
3
  */
4
4
  export function isNull(val) {
5
- return val === null;
6
- }
5
+ return val === null;
6
+ }
package/es/isNumber.js CHANGED
@@ -3,5 +3,5 @@
3
3
  * @param val 需要判断的值
4
4
  */
5
5
  export function isNumber(val) {
6
- return /^\d$/.test(val);
7
- }
6
+ return /^\d$/.test(val);
7
+ }
package/es/isObject.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是对象
3
3
  */
4
4
  export function isObject(val) {
5
- return Object.prototype.toString.call(val) === '[object Object]';
6
- }
5
+ return Object.prototype.toString.call(val) === '[object Object]';
6
+ }
package/es/isPhone.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是手机号码
3
3
  */
4
4
  export function isPhone(val) {
5
- return /^1\d{10}$/.test(val);
6
- }
5
+ return /^1\d{10}$/.test(val);
6
+ }
package/es/isPromise.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是 promise
3
3
  */
4
4
  export function isPromise(val) {
5
- return val instanceof Promise || !!val.then || !!val["catch"];
6
- }
5
+ return val instanceof Promise || !!val.then || !!val.catch;
6
+ }
package/es/isRegExp.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是正则表达式
3
3
  */
4
4
  export function isRegExp(val) {
5
- return val instanceof RegExp;
6
- }
5
+ return val instanceof RegExp;
6
+ }
package/es/isString.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是字符串
3
3
  */
4
4
  export function isString(val) {
5
- return typeof val === 'string';
6
- }
5
+ return typeof val === 'string';
6
+ }
package/es/isURL.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 判断是否是 url
3
+ */
4
+ export declare function isURL(val: unknown): boolean;
package/es/isURL.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 判断是否是 url
3
+ */
4
+ export function isURL(val) {
5
+ return /^(http)|(\.*\/)/.test(`${val}`);
6
+ }
package/es/isUndefined.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 校验是否是 undefined
3
3
  */
4
4
  export function isUndefined(val) {
5
- return typeof val === 'undefined';
6
- }
5
+ return typeof val === 'undefined';
6
+ }
package/es/isWeixin.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * 是否是微信环境
3
3
  */
4
4
  export function isWeixin() {
5
- return /MicroMessenger/gi.test(navigator.userAgent);
6
- }
5
+ return /MicroMessenger/gi.test(navigator.userAgent);
6
+ }
package/es/isWindow.js CHANGED
@@ -3,5 +3,5 @@
3
3
  * @param val 需要判断的值
4
4
  */
5
5
  export function isWindow(val) {
6
- return val === window;
7
- }
6
+ return val === window;
7
+ }
@@ -4,4 +4,4 @@
4
4
  * @param type 类型
5
5
  * @param callback 回调函数
6
6
  */
7
- export declare function loadResource(res: string, type: 'js' | 'css' | 'style', callback?: any): void;
7
+ export declare function loadResource(res: string, type: 'js' | 'css' | 'style', callback?: () => void): void;
@@ -6,26 +6,30 @@ import { isFunction } from './isFunction';
6
6
  * @param callback 回调函数
7
7
  */
8
8
  export function loadResource(res, type, callback) {
9
- var ref;
10
- if (type === 'js') {
11
- // 外部js
12
- ref = document.createElement('js');
13
- ref.setAttribute('type', 'text/javascript');
14
- ref.setAttribute('src', res);
15
- } else if (type === 'css') {
16
- // 外部css
17
- ref = document.createElement('link');
18
- ref.setAttribute('rel', 'stylesheet');
19
- ref.setAttribute('type', 'text/css');
20
- ref.setAttribute('href', res);
21
- } else if (type === 'style') {
22
- ref = document.createElement('style');
23
- ref.innerHTML = res;
24
- }
25
- if (ref) {
26
- document.querySelector('head').appendChild(ref);
27
- ref.onload = function () {
28
- if (isFunction(callback)) callback();
29
- };
30
- }
31
- }
9
+ var _a;
10
+ let ref = null;
11
+ if (type === 'js') {
12
+ // 外部js
13
+ ref = document.createElement('js');
14
+ ref.setAttribute('type', 'text/javascript');
15
+ ref.setAttribute('src', res);
16
+ }
17
+ else if (type === 'css') {
18
+ // 外部css
19
+ ref = document.createElement('link');
20
+ ref.setAttribute('rel', 'stylesheet');
21
+ ref.setAttribute('type', 'text/css');
22
+ ref.setAttribute('href', res);
23
+ }
24
+ else if (type === 'style') {
25
+ ref = document.createElement('style');
26
+ ref.innerHTML = res;
27
+ }
28
+ if (ref) {
29
+ (_a = document.querySelector('head')) === null || _a === void 0 ? void 0 : _a.appendChild(ref);
30
+ ref.onload = () => {
31
+ if (isFunction(callback))
32
+ callback();
33
+ };
34
+ }
35
+ }
package/es/omit.js CHANGED
@@ -1,12 +1,10 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
1
  /**
3
2
  * 排除对象里的某些属性,返回剩下的对象,浅拷贝
4
3
  */
5
- export function omit(obj) {
6
- var fields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
7
- var clone = _objectSpread({}, obj);
8
- fields.forEach(function (key) {
9
- delete clone[key];
10
- });
11
- return clone;
12
- }
4
+ export function omit(obj, fields = []) {
5
+ const clone = Object.assign({}, obj);
6
+ fields.forEach((key) => {
7
+ delete clone[key];
8
+ });
9
+ return clone;
10
+ }
package/es/padding.js CHANGED
@@ -4,8 +4,8 @@
4
4
  * @param before 前空格个数
5
5
  * @param after 后空格个数
6
6
  */
7
- export function padding(message) {
8
- var before = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
9
- var after = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
10
- return "".concat(new Array(before).fill(' ').join('')).concat(message).concat(new Array(after).fill(' ').join(''));
11
- }
7
+ export function padding(message, before = 1, after = 1) {
8
+ return `${new Array(before).fill(' ').join('')}${message}${new Array(after)
9
+ .fill(' ')
10
+ .join('')}`;
11
+ }
package/es/parseDate.js CHANGED
@@ -2,10 +2,10 @@
2
2
  * 解析成Date
3
3
  */
4
4
  export function parseDate(v) {
5
- if (typeof v === 'string') {
6
- // fix ios 格式日期错误
7
- // eslint-disable-next-line no-param-reassign
8
- v = v.replace(/-/g, '/');
9
- }
10
- return new Date(v);
11
- }
5
+ if (typeof v === 'string') {
6
+ // fix ios 格式日期错误
7
+ // eslint-disable-next-line no-param-reassign
8
+ v = v.replace(/-/g, '/');
9
+ }
10
+ return new Date(v);
11
+ }
package/es/parseError.js CHANGED
@@ -4,20 +4,19 @@ import { isUndefined } from './isUndefined';
4
4
  /**
5
5
  * 解析格式化 error 获取对应的 message
6
6
  */
7
- export function parseError(val) {
8
- var keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['message', 'msg', 'errorMsg'];
9
- if (isEmpty(val)) {
10
- // null or '' or undefined
11
- return '';
12
- }
13
- if (isObject(val)) {
14
- for (var i = 0, len = keys.length; i < len; i++) {
15
- var key = keys[i];
16
- var v = val[key];
17
- if (!isUndefined(v)) {
18
- return v;
19
- }
7
+ export function parseError(val, keys = ['message', 'msg', 'errorMsg']) {
8
+ if (isEmpty(val)) {
9
+ // null or '' or undefined
10
+ return '';
20
11
  }
21
- }
22
- return JSON.stringify(val);
23
- }
12
+ if (isObject(val)) {
13
+ for (let i = 0, len = keys.length; i < len; i++) {
14
+ const key = keys[i];
15
+ const v = val[key];
16
+ if (!isUndefined(v)) {
17
+ return v;
18
+ }
19
+ }
20
+ }
21
+ return JSON.stringify(val);
22
+ }