@daysnap/utils 0.0.55 → 0.0.57

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 (60) hide show
  1. package/docs/modules.md +268 -84
  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 +8 -1
  11. package/es/index.js +8 -1
  12. package/es/isEmptyObject.d.ts +2 -2
  13. package/es/isEmptyObject.js +3 -3
  14. package/es/isIE.d.ts +6 -0
  15. package/es/isIE.js +27 -0
  16. package/es/isWeChat.d.ts +9 -0
  17. package/es/isWeChat.js +13 -0
  18. package/es/isWeChatMiniProgram.d.ts +5 -0
  19. package/es/isWeChatMiniProgram.js +8 -0
  20. package/es/parseQuery.js +8 -2
  21. package/es/scrollToTop.d.ts +4 -0
  22. package/es/scrollToTop.js +10 -0
  23. package/es/stringifyQuery.d.ts +1 -1
  24. package/es/stringifyQuery.js +1 -1
  25. package/es/toCDB.d.ts +4 -0
  26. package/es/toCDB.js +19 -0
  27. package/es/toDBC.d.ts +4 -0
  28. package/es/toDBC.js +19 -0
  29. package/lib/filterIdCard.d.ts +1 -0
  30. package/lib/filterIdCard.js +1 -0
  31. package/lib/formatDateStr.d.ts +1 -0
  32. package/lib/formatDateStr.js +1 -0
  33. package/lib/getRandom.d.ts +6 -0
  34. package/lib/getRandom.js +15 -0
  35. package/lib/getRandomNumber.d.ts +5 -0
  36. package/lib/getRandomNumber.js +12 -0
  37. package/lib/index.d.ts +8 -1
  38. package/lib/index.js +8 -1
  39. package/lib/isEmptyObject.d.ts +2 -2
  40. package/lib/isEmptyObject.js +3 -3
  41. package/lib/isIE.d.ts +6 -0
  42. package/lib/isIE.js +31 -0
  43. package/lib/isWeChat.d.ts +9 -0
  44. package/lib/isWeChat.js +18 -0
  45. package/lib/isWeChatMiniProgram.d.ts +5 -0
  46. package/lib/isWeChatMiniProgram.js +12 -0
  47. package/lib/parseQuery.js +8 -2
  48. package/lib/scrollToTop.d.ts +4 -0
  49. package/lib/scrollToTop.js +14 -0
  50. package/lib/stringifyQuery.d.ts +1 -1
  51. package/lib/stringifyQuery.js +1 -1
  52. package/lib/toCDB.d.ts +4 -0
  53. package/lib/toCDB.js +23 -0
  54. package/lib/toDBC.d.ts +4 -0
  55. package/lib/toDBC.js +23 -0
  56. package/package.json +1 -1
  57. package/es/isWeixin.d.ts +0 -4
  58. package/es/isWeixin.js +0 -6
  59. package/lib/isWeixin.d.ts +0 -4
  60. package/lib/isWeixin.js +0 -10
@@ -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.55",
3
+ "version": "0.0.57",
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;