@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
package/lib/formatDate.js CHANGED
@@ -1,40 +1,37 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.formatDate = formatDate;
7
- var _isString = require("./isString");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatDate = void 0;
4
+ const isString_1 = require("./isString");
8
5
  /**
9
6
  * 格式化日期
10
7
  */
11
- function formatDate(val) {
12
- var fmt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd hh:mm:ss';
13
- var v = val;
14
- if ((0, _isString.isString)(v)) {
15
- // fix iOS new Date() 不支持 2020-01-01 格式,需转换为 2020/01/01
16
- v = v.replace(/-/g, '/');
17
- }
18
- var date = new Date(v);
19
- var o = {
20
- 'M+': date.getMonth() + 1,
21
- 'd+': date.getDate(),
22
- 'h+': date.getHours(),
23
- 'm+': date.getMinutes(),
24
- 's+': date.getSeconds(),
25
- 'q+': Math.floor((date.getMonth() + 3) / 3),
26
- S: date.getMilliseconds()
27
- };
28
- if (/(y+)/.test(fmt)) {
29
- // eslint-disable-next-line no-param-reassign
30
- fmt = fmt.replace(RegExp.$1, "".concat(date.getFullYear()).substr(4 - RegExp.$1.length));
31
- }
32
- // eslint-disable-next-line no-restricted-syntax
33
- for (var k in o) {
34
- if (new RegExp("(".concat(k, ")")).test(fmt)) {
35
- // eslint-disable-next-line no-param-reassign
36
- fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : "00".concat(o[k]).substr("".concat(o[k]).length));
8
+ function formatDate(val, fmt = 'yyyy-MM-dd hh:mm:ss') {
9
+ let v = val;
10
+ if ((0, isString_1.isString)(v)) {
11
+ // fix iOS new Date() 不支持 2020-01-01 格式,需转换为 2020/01/01
12
+ v = v.replace(/-/g, '/');
13
+ }
14
+ const date = new Date(v);
15
+ const o = {
16
+ 'M+': date.getMonth() + 1,
17
+ 'd+': date.getDate(),
18
+ 'h+': date.getHours(),
19
+ 'm+': date.getMinutes(),
20
+ 's+': date.getSeconds(),
21
+ 'q+': Math.floor((date.getMonth() + 3) / 3),
22
+ S: date.getMilliseconds(),
23
+ };
24
+ if (/(y+)/.test(fmt)) {
25
+ // eslint-disable-next-line no-param-reassign
26
+ fmt = fmt.replace(RegExp.$1, `${date.getFullYear()}`.substr(4 - RegExp.$1.length));
37
27
  }
38
- }
39
- return fmt;
40
- }
28
+ // eslint-disable-next-line no-restricted-syntax
29
+ for (const k in o) {
30
+ if (new RegExp(`(${k})`).test(fmt)) {
31
+ // eslint-disable-next-line no-param-reassign
32
+ fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : `00${o[k]}`.substr(`${o[k]}`.length));
33
+ }
34
+ }
35
+ return fmt;
36
+ }
37
+ exports.formatDate = formatDate;
@@ -1,28 +1,25 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getBlobByUrl = getBlobByUrl;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBlobByUrl = void 0;
7
4
  /**
8
5
  * 根据在线 url 返回 blob
9
6
  */
10
7
  function getBlobByUrl(url) {
11
- return new Promise(function (resolve, reject) {
12
- var xhr = new XMLHttpRequest();
13
- xhr.open('GET', url, true);
14
- xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
15
- xhr.responseType = 'blob';
16
- xhr.onload = function () {
17
- var status = xhr.status,
18
- response = xhr.response,
19
- statusText = xhr.statusText;
20
- if (status >= 200 && status < 300) {
21
- resolve(response);
22
- } else {
23
- reject(new Error("".concat(statusText, "[").concat(status, "]")));
24
- }
25
- };
26
- xhr.send();
27
- });
28
- }
8
+ return new Promise((resolve, reject) => {
9
+ const xhr = new XMLHttpRequest();
10
+ xhr.open('GET', url, true);
11
+ xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
12
+ xhr.responseType = 'blob';
13
+ xhr.onload = () => {
14
+ const { status, response, statusText } = xhr;
15
+ if (status >= 200 && status < 300) {
16
+ resolve(response);
17
+ }
18
+ else {
19
+ reject(new Error(`${statusText}[${status}]`));
20
+ }
21
+ };
22
+ xhr.send();
23
+ });
24
+ }
25
+ exports.getBlobByUrl = getBlobByUrl;
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getDayMillisecond = getDayMillisecond;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDayMillisecond = void 0;
7
4
  /**
8
5
  * 获取多少天的毫秒数 默认获取1天的
9
6
  */
10
- function getDayMillisecond() {
11
- var day = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
12
- return day * 24 * 60 * 60 * 1000;
13
- }
7
+ function getDayMillisecond(day = 1) {
8
+ return day * 24 * 60 * 60 * 1000;
9
+ }
10
+ exports.getDayMillisecond = getDayMillisecond;
@@ -1,19 +1,17 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getImageInfo = getImageInfo;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getImageInfo = void 0;
7
4
  /**
8
5
  * 获取图片信息
9
6
  */
10
7
  function getImageInfo(src) {
11
- return new Promise(function (resolve, reject) {
12
- var image = new Image();
13
- image.onload = function () {
14
- resolve(image);
15
- };
16
- image.onerror = reject;
17
- image.src = src;
18
- });
19
- }
8
+ return new Promise((resolve, reject) => {
9
+ const image = new Image();
10
+ image.onload = () => {
11
+ resolve(image);
12
+ };
13
+ image.onerror = reject;
14
+ image.src = src;
15
+ });
16
+ }
17
+ exports.getImageInfo = getImageInfo;
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getRandomColor = getRandomColor;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRandomColor = void 0;
7
4
  /**
8
5
  * 随机颜色
9
6
  */
10
7
  function getRandomColor() {
11
- return "#".concat(Math.floor(Math.random() * 0xffffff).toString(16));
12
- }
8
+ return `#${Math.floor(Math.random() * 0xffffff).toString(16)}`;
9
+ }
10
+ exports.getRandomColor = getRandomColor;
@@ -1,21 +1,19 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getVideoInfo = getVideoInfo;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVideoInfo = void 0;
7
4
  /**
8
5
  * 获取 video 信息
9
6
  */
10
7
  function getVideoInfo(src) {
11
- return new Promise(function (resolve, reject) {
12
- var video = document.createElement('video');
13
- video.preload = 'metadata';
14
- video.muted = true;
15
- video.onerror = reject;
16
- video.onloadedmetadata = function () {
17
- resolve(video);
18
- };
19
- video.src = src;
20
- });
21
- }
8
+ return new Promise((resolve, reject) => {
9
+ const video = document.createElement('video');
10
+ video.preload = 'metadata';
11
+ video.muted = true;
12
+ video.onerror = reject;
13
+ video.onloadedmetadata = () => {
14
+ resolve(video);
15
+ };
16
+ video.src = src;
17
+ });
18
+ }
19
+ exports.getVideoInfo = getVideoInfo;
package/lib/inBrowser.js CHANGED
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.inBrowser = inBrowser;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inBrowser = void 0;
7
4
  /**
8
5
  * 判断是否是浏览器环境
9
6
  */
10
7
  function inBrowser() {
11
- return typeof window !== 'undefined';
12
- }
8
+ return typeof window !== 'undefined';
9
+ }
10
+ exports.inBrowser = inBrowser;
package/lib/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';