@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.
- package/docs/modules.md +313 -90
- package/es/filterIdCard.d.ts +1 -0
- package/es/filterIdCard.js +1 -0
- package/es/formatDateStr.d.ts +1 -0
- package/es/formatDateStr.js +1 -0
- package/es/getRandom.d.ts +6 -0
- package/es/getRandom.js +11 -0
- package/es/getRandomNumber.d.ts +5 -0
- package/es/getRandomNumber.js +8 -0
- package/es/index.d.ts +10 -1
- package/es/index.js +10 -1
- package/es/isAmount.d.ts +11 -0
- package/es/isAmount.js +13 -0
- package/es/isChinese.d.ts +4 -0
- package/es/isChinese.js +6 -0
- package/es/isEmptyObject.d.ts +2 -2
- package/es/isEmptyObject.js +3 -3
- package/es/isIE.d.ts +6 -0
- package/es/isIE.js +27 -0
- package/es/isWeChat.d.ts +9 -0
- package/es/isWeChat.js +13 -0
- package/es/isWeChatMiniProgram.d.ts +5 -0
- package/es/isWeChatMiniProgram.js +8 -0
- package/es/parseQuery.js +1 -1
- package/es/scrollToTop.d.ts +4 -0
- package/es/scrollToTop.js +10 -0
- package/es/stringifyQuery.d.ts +1 -1
- package/es/stringifyQuery.js +1 -1
- package/es/toCDB.d.ts +4 -0
- package/es/toCDB.js +19 -0
- package/es/toDBC.d.ts +4 -0
- package/es/toDBC.js +19 -0
- package/lib/filterIdCard.d.ts +1 -0
- package/lib/filterIdCard.js +1 -0
- package/lib/formatDateStr.d.ts +1 -0
- package/lib/formatDateStr.js +1 -0
- package/lib/getRandom.d.ts +6 -0
- package/lib/getRandom.js +15 -0
- package/lib/getRandomNumber.d.ts +5 -0
- package/lib/getRandomNumber.js +12 -0
- package/lib/index.d.ts +10 -1
- package/lib/index.js +10 -1
- package/lib/isAmount.d.ts +11 -0
- package/lib/isAmount.js +17 -0
- package/lib/isChinese.d.ts +4 -0
- package/lib/isChinese.js +10 -0
- package/lib/isEmptyObject.d.ts +2 -2
- package/lib/isEmptyObject.js +3 -3
- package/lib/isIE.d.ts +6 -0
- package/lib/isIE.js +31 -0
- package/lib/isWeChat.d.ts +9 -0
- package/lib/isWeChat.js +18 -0
- package/lib/isWeChatMiniProgram.d.ts +5 -0
- package/lib/isWeChatMiniProgram.js +12 -0
- package/lib/parseQuery.js +1 -1
- package/lib/scrollToTop.d.ts +4 -0
- package/lib/scrollToTop.js +14 -0
- package/lib/stringifyQuery.d.ts +1 -1
- package/lib/stringifyQuery.js +1 -1
- package/lib/toCDB.d.ts +4 -0
- package/lib/toCDB.js +23 -0
- package/lib/toDBC.d.ts +4 -0
- package/lib/toDBC.js +23 -0
- package/package.json +1 -1
- package/es/isWeixin.d.ts +0 -4
- package/es/isWeixin.js +0 -6
- package/lib/isWeixin.d.ts +0 -4
- package/lib/isWeixin.js +0 -10
package/lib/isEmptyObject.js
CHANGED
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isEmptyObject = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 判断是否是空对象
|
|
6
|
-
* @param
|
|
6
|
+
* @param val 对象
|
|
7
7
|
*/
|
|
8
|
-
function isEmptyObject(
|
|
9
|
-
return !Object.keys(
|
|
8
|
+
function isEmptyObject(val) {
|
|
9
|
+
return !Object.keys(val).length;
|
|
10
10
|
}
|
|
11
11
|
exports.isEmptyObject = isEmptyObject;
|
package/lib/isIE.d.ts
ADDED
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;
|
package/lib/isWeChat.js
ADDED
|
@@ -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,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
|
|
16
|
+
const url = new URL(v);
|
|
17
17
|
searchStr = url.search;
|
|
18
18
|
}
|
|
19
19
|
const query = new URLSearchParams(decodeURIComponent(searchStr));
|
|
@@ -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;
|
package/lib/stringifyQuery.d.ts
CHANGED
package/lib/stringifyQuery.js
CHANGED
package/lib/toCDB.d.ts
ADDED
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
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
package/es/isWeixin.d.ts
DELETED
package/es/isWeixin.js
DELETED
package/lib/isWeixin.d.ts
DELETED
package/lib/isWeixin.js
DELETED