@daysnap/utils 0.0.56 → 0.0.58

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 (68) hide show
  1. package/docs/modules.md +313 -90
  2. package/es/filterIdCard.d.ts +1 -0
  3. package/es/filterIdCard.js +1 -0
  4. package/es/formatDateStr.d.ts +1 -0
  5. package/es/formatDateStr.js +1 -0
  6. package/es/getRandom.d.ts +6 -0
  7. package/es/getRandom.js +11 -0
  8. package/es/getRandomNumber.d.ts +5 -0
  9. package/es/getRandomNumber.js +8 -0
  10. package/es/index.d.ts +10 -1
  11. package/es/index.js +10 -1
  12. package/es/isAmount.d.ts +11 -0
  13. package/es/isAmount.js +13 -0
  14. package/es/isChinese.d.ts +4 -0
  15. package/es/isChinese.js +6 -0
  16. package/es/isEmptyObject.d.ts +2 -2
  17. package/es/isEmptyObject.js +3 -3
  18. package/es/isIE.d.ts +6 -0
  19. package/es/isIE.js +27 -0
  20. package/es/isWeChat.d.ts +9 -0
  21. package/es/isWeChat.js +13 -0
  22. package/es/isWeChatMiniProgram.d.ts +5 -0
  23. package/es/isWeChatMiniProgram.js +8 -0
  24. package/es/parseQuery.js +1 -1
  25. package/es/scrollToTop.d.ts +4 -0
  26. package/es/scrollToTop.js +10 -0
  27. package/es/stringifyQuery.d.ts +1 -1
  28. package/es/stringifyQuery.js +1 -1
  29. package/es/toCDB.d.ts +4 -0
  30. package/es/toCDB.js +19 -0
  31. package/es/toDBC.d.ts +4 -0
  32. package/es/toDBC.js +19 -0
  33. package/lib/filterIdCard.d.ts +1 -0
  34. package/lib/filterIdCard.js +1 -0
  35. package/lib/formatDateStr.d.ts +1 -0
  36. package/lib/formatDateStr.js +1 -0
  37. package/lib/getRandom.d.ts +6 -0
  38. package/lib/getRandom.js +15 -0
  39. package/lib/getRandomNumber.d.ts +5 -0
  40. package/lib/getRandomNumber.js +12 -0
  41. package/lib/index.d.ts +10 -1
  42. package/lib/index.js +10 -1
  43. package/lib/isAmount.d.ts +11 -0
  44. package/lib/isAmount.js +17 -0
  45. package/lib/isChinese.d.ts +4 -0
  46. package/lib/isChinese.js +10 -0
  47. package/lib/isEmptyObject.d.ts +2 -2
  48. package/lib/isEmptyObject.js +3 -3
  49. package/lib/isIE.d.ts +6 -0
  50. package/lib/isIE.js +31 -0
  51. package/lib/isWeChat.d.ts +9 -0
  52. package/lib/isWeChat.js +18 -0
  53. package/lib/isWeChatMiniProgram.d.ts +5 -0
  54. package/lib/isWeChatMiniProgram.js +12 -0
  55. package/lib/parseQuery.js +1 -1
  56. package/lib/scrollToTop.d.ts +4 -0
  57. package/lib/scrollToTop.js +14 -0
  58. package/lib/stringifyQuery.d.ts +1 -1
  59. package/lib/stringifyQuery.js +1 -1
  60. package/lib/toCDB.d.ts +4 -0
  61. package/lib/toCDB.js +23 -0
  62. package/lib/toDBC.d.ts +4 -0
  63. package/lib/toDBC.js +23 -0
  64. package/package.json +1 -1
  65. package/es/isWeixin.d.ts +0 -4
  66. package/es/isWeixin.js +0 -6
  67. package/lib/isWeixin.d.ts +0 -4
  68. package/lib/isWeixin.js +0 -10
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isEmptyObject = void 0;
4
4
  /**
5
5
  * 判断是否是空对象
6
- * @param v 对象
6
+ * @param val 对象
7
7
  */
8
- function isEmptyObject(v) {
9
- return !Object.keys(v).length;
8
+ function isEmptyObject(val) {
9
+ return !Object.keys(val).length;
10
10
  }
11
11
  exports.isEmptyObject = isEmptyObject;
package/lib/isIE.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 判断浏览器是否是 ie
3
+ * 如果是 ie 则会返回对应 ie 版本
4
+ * 如果不是则返回false
5
+ */
6
+ export declare function isIE(): false | number;
package/lib/isIE.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isIE = void 0;
4
+ /**
5
+ * 判断浏览器是否是 ie
6
+ * 如果是 ie 则会返回对应 ie 版本
7
+ * 如果不是则返回false
8
+ */
9
+ function isIE() {
10
+ const ua = window.navigator.userAgent;
11
+ const msie = ua.indexOf('MSIE ');
12
+ if (msie > 0) {
13
+ // IE 10 or older => return version number
14
+ return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
15
+ }
16
+ const trident = ua.indexOf('Trident/');
17
+ if (trident > 0) {
18
+ // IE 11 => return version number
19
+ const rv = ua.indexOf('rv:');
20
+ return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
21
+ }
22
+ // https://learn.microsoft.com/zh-cn/microsoft-edge/web-platform/user-agent-guidance
23
+ // https://learn.microsoft.com/zh-cn/microsoft-edge/web-platform/user-agent-guidance#microsoft-edge-legacy
24
+ const edge = ua.indexOf('Edge/');
25
+ if (edge > 0) {
26
+ // Edge (IE 12+) => return version number
27
+ return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
28
+ }
29
+ return false;
30
+ }
31
+ exports.isIE = isIE;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 判断是否是微信浏览器
3
+ */
4
+ export declare function isWeChat(): boolean;
5
+ /**
6
+ * 判断是否是微信浏览器
7
+ * @deprecated 请使用 isWeChat 方法
8
+ */
9
+ export declare function isWeixin(): boolean;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWeixin = exports.isWeChat = void 0;
4
+ /**
5
+ * 判断是否是微信浏览器
6
+ */
7
+ function isWeChat() {
8
+ return /MicroMessenger/gi.test(window.navigator.userAgent);
9
+ }
10
+ exports.isWeChat = isWeChat;
11
+ /**
12
+ * 判断是否是微信浏览器
13
+ * @deprecated 请使用 isWeChat 方法
14
+ */
15
+ function isWeixin() {
16
+ return isWeChat();
17
+ }
18
+ exports.isWeixin = isWeixin;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 判断是否是微信小程序web-view环境
3
+ * https://developers.weixin.qq.com/miniprogram/dev/component/web-view.html
4
+ */
5
+ export declare function isWeChatMiniProgram(): boolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWeChatMiniProgram = void 0;
4
+ /**
5
+ * 判断是否是微信小程序web-view环境
6
+ * https://developers.weixin.qq.com/miniprogram/dev/component/web-view.html
7
+ */
8
+ function isWeChatMiniProgram() {
9
+ // 从微信7.0.0开始,可以通过判断userAgent中包含miniProgram字样来判断小程序web-view环境。
10
+ return window.navigator.userAgent.toLocaleLowerCase().includes('miniprogram');
11
+ }
12
+ exports.isWeChatMiniProgram = isWeChatMiniProgram;
package/lib/parseQuery.js CHANGED
@@ -13,7 +13,7 @@ function parseQuery(v, k) {
13
13
  searchStr = window.location.search;
14
14
  }
15
15
  else {
16
- const url = new URL(v !== null && v !== void 0 ? v : '');
16
+ const url = new URL(v);
17
17
  searchStr = url.search;
18
18
  }
19
19
  const query = new URLSearchParams(decodeURIComponent(searchStr));
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 滚动到页面顶部
3
+ */
4
+ export declare function scrollToTop(): void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scrollToTop = void 0;
4
+ /**
5
+ * 滚动到页面顶部
6
+ */
7
+ function scrollToTop() {
8
+ const height = document.documentElement.scrollTop || document.body.scrollTop;
9
+ if (height > 0) {
10
+ window.requestAnimationFrame(scrollToTop);
11
+ window.scrollTo(0, height - height / 8);
12
+ }
13
+ }
14
+ exports.scrollToTop = scrollToTop;
@@ -1,4 +1,4 @@
1
1
  /**
2
- * 说明
2
+ * 对象转 URLSearchParams
3
3
  */
4
4
  export declare function stringifyQuery(v: Record<string, any>): string;
@@ -4,7 +4,7 @@ exports.stringifyQuery = void 0;
4
4
  const isEmptyObject_1 = require("./isEmptyObject");
5
5
  const isString_1 = require("./isString");
6
6
  /**
7
- * 说明
7
+ * 对象转 URLSearchParams
8
8
  */
9
9
  function stringifyQuery(v) {
10
10
  if ((0, isEmptyObject_1.isEmptyObject)(v)) {
package/lib/toCDB.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 全角转换为半角
3
+ */
4
+ export declare function toCDB(str: string): string;
package/lib/toCDB.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toCDB = void 0;
4
+ /**
5
+ * 全角转换为半角
6
+ */
7
+ function toCDB(str) {
8
+ let result = '';
9
+ for (let i = 0; i < str.length; i++) {
10
+ const code = str.charCodeAt(i);
11
+ if (code >= 65281 && code <= 65374) {
12
+ result += String.fromCharCode(str.charCodeAt(i) - 65248);
13
+ }
14
+ else if (code == 12288) {
15
+ result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
16
+ }
17
+ else {
18
+ result += str.charAt(i);
19
+ }
20
+ }
21
+ return result;
22
+ }
23
+ exports.toCDB = toCDB;
package/lib/toDBC.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 半角转换为全角
3
+ */
4
+ export declare function toDBC(str: string): string;
package/lib/toDBC.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDBC = void 0;
4
+ /**
5
+ * 半角转换为全角
6
+ */
7
+ function toDBC(str) {
8
+ let result = '';
9
+ for (let i = 0; i < str.length; i++) {
10
+ const code = str.charCodeAt(i);
11
+ if (code >= 33 && code <= 126) {
12
+ result += String.fromCharCode(str.charCodeAt(i) + 65248);
13
+ }
14
+ else if (code == 32) {
15
+ result += String.fromCharCode(str.charCodeAt(i) + 12288 - 32);
16
+ }
17
+ else {
18
+ result += str.charAt(i);
19
+ }
20
+ }
21
+ return result;
22
+ }
23
+ exports.toDBC = toDBC;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daysnap/utils",
3
- "version": "0.0.56",
3
+ "version": "0.0.58",
4
4
  "description": "通用的工具库",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
package/es/isWeixin.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * 是否是微信环境
3
- */
4
- export declare function isWeixin(): boolean;
package/es/isWeixin.js DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * 是否是微信环境
3
- */
4
- export function isWeixin() {
5
- return /MicroMessenger/gi.test(navigator.userAgent);
6
- }
package/lib/isWeixin.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * 是否是微信环境
3
- */
4
- export declare function isWeixin(): boolean;
package/lib/isWeixin.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isWeixin = void 0;
4
- /**
5
- * 是否是微信环境
6
- */
7
- function isWeixin() {
8
- return /MicroMessenger/gi.test(navigator.userAgent);
9
- }
10
- exports.isWeixin = isWeixin;