@ivujs/i-utils 2.1.4 → 2.1.6
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/dist/cjs/clipboard/index.cjs +3 -3
- package/dist/cjs/device/index.cjs +12 -12
- package/dist/cjs/file/index.cjs +9 -8
- package/dist/cjs/storage/localStorage.cjs +4 -4
- package/dist/cjs/storage/sessionStorage.cjs +4 -4
- package/dist/cjs/validate/index.cjs +1 -6
- package/dist/es/clipboard/index.mjs +3 -3
- package/dist/es/device/index.mjs +12 -12
- package/dist/es/file/index.mjs +9 -8
- package/dist/es/storage/localStorage.mjs +4 -4
- package/dist/es/storage/sessionStorage.mjs +4 -4
- package/dist/es/validate/index.mjs +1 -6
- package/dist/lib/index.full.umd.js +34 -38
- package/dist/lib/index.full.umd.min.js +2 -2
- package/dist/lib/index.full.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @ivujs/i-utils v2.1.
|
|
2
|
+
* @ivujs/i-utils v2.1.6
|
|
3
3
|
* Copyright 2021-2026, <gao911222@163.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -904,12 +904,7 @@
|
|
|
904
904
|
* @returns {boolean} 返回结果
|
|
905
905
|
*/
|
|
906
906
|
function isNaN(value) {
|
|
907
|
-
return (value == null ||
|
|
908
|
-
typeof value === "boolean" || // 布尔值视为非数字
|
|
909
|
-
Array.isArray(value) || // 数组视为非数字
|
|
910
|
-
value === "" || // 空字符串视为非数字
|
|
911
|
-
window.isNaN(Number(value)) // 原生isNaN判断(转数字后是否为NaN)
|
|
912
|
-
);
|
|
907
|
+
return (value == null || typeof value === "boolean" || Array.isArray(value) || value === "" || Number.isNaN(Number(value)));
|
|
913
908
|
}
|
|
914
909
|
/**
|
|
915
910
|
* 判断是数字
|
|
@@ -4122,15 +4117,16 @@
|
|
|
4122
4117
|
function urlToFile(url) {
|
|
4123
4118
|
return new Promise((resolve, reject) => {
|
|
4124
4119
|
try {
|
|
4125
|
-
window
|
|
4126
|
-
|
|
4127
|
-
res.
|
|
4128
|
-
|
|
4129
|
-
|
|
4120
|
+
window &&
|
|
4121
|
+
window.fetch(url).then((res) => {
|
|
4122
|
+
if (res.status === 200) {
|
|
4123
|
+
res.blob().then((blob) => {
|
|
4124
|
+
blobToFile(blob).then((file) => {
|
|
4125
|
+
resolve(file);
|
|
4126
|
+
});
|
|
4130
4127
|
});
|
|
4131
|
-
}
|
|
4132
|
-
}
|
|
4133
|
-
});
|
|
4128
|
+
}
|
|
4129
|
+
});
|
|
4134
4130
|
}
|
|
4135
4131
|
catch (err) {
|
|
4136
4132
|
console.error(err);
|
|
@@ -7614,7 +7610,7 @@
|
|
|
7614
7610
|
* @returns {string} 返回数据
|
|
7615
7611
|
*/
|
|
7616
7612
|
function getLocalStorage(key) {
|
|
7617
|
-
return window.localStorage.getItem(key) || undefined;
|
|
7613
|
+
return (window && window.localStorage.getItem(key)) || undefined;
|
|
7618
7614
|
}
|
|
7619
7615
|
/**
|
|
7620
7616
|
* 设置localStorage缓存数据
|
|
@@ -7622,20 +7618,20 @@
|
|
|
7622
7618
|
* @param {string} value value值
|
|
7623
7619
|
*/
|
|
7624
7620
|
function setLocalStorage(key, value) {
|
|
7625
|
-
window.localStorage.setItem(key, value);
|
|
7621
|
+
window && window.localStorage.setItem(key, value);
|
|
7626
7622
|
}
|
|
7627
7623
|
/**
|
|
7628
7624
|
* 通过key从localStorage缓存中删除数据
|
|
7629
7625
|
* @param {string} key key值
|
|
7630
7626
|
*/
|
|
7631
7627
|
function removeLocalStorage(key) {
|
|
7632
|
-
window.localStorage.removeItem(key);
|
|
7628
|
+
window && window.localStorage.removeItem(key);
|
|
7633
7629
|
}
|
|
7634
7630
|
/**
|
|
7635
7631
|
* 清空localStorage缓存中所有数据
|
|
7636
7632
|
*/
|
|
7637
7633
|
function clearLocalStorage() {
|
|
7638
|
-
window.localStorage.clear();
|
|
7634
|
+
window && window.localStorage.clear();
|
|
7639
7635
|
}
|
|
7640
7636
|
|
|
7641
7637
|
/* sessionStorage存储 */
|
|
@@ -7645,7 +7641,7 @@
|
|
|
7645
7641
|
* @returns {string} 返回数据
|
|
7646
7642
|
*/
|
|
7647
7643
|
function getSessionStorage(key) {
|
|
7648
|
-
return window.sessionStorage.getItem(key) || undefined;
|
|
7644
|
+
return (window && window.sessionStorage.getItem(key)) || undefined;
|
|
7649
7645
|
}
|
|
7650
7646
|
/**
|
|
7651
7647
|
* 设置sessionStorage缓存数据
|
|
@@ -7653,20 +7649,20 @@
|
|
|
7653
7649
|
* @param {string} value value值
|
|
7654
7650
|
*/
|
|
7655
7651
|
function setSessionStorage(key, value) {
|
|
7656
|
-
window.sessionStorage.setItem(key, value);
|
|
7652
|
+
window && window.sessionStorage.setItem(key, value);
|
|
7657
7653
|
}
|
|
7658
7654
|
/**
|
|
7659
7655
|
* 通过key从sessionStorage缓存中删除数据
|
|
7660
7656
|
* @param {string} key key值
|
|
7661
7657
|
*/
|
|
7662
7658
|
function removeSessionStorage(key) {
|
|
7663
|
-
window.sessionStorage.removeItem(key);
|
|
7659
|
+
window && window.sessionStorage.removeItem(key);
|
|
7664
7660
|
}
|
|
7665
7661
|
/**
|
|
7666
7662
|
* 清空sessionStorage缓存中所有数据
|
|
7667
7663
|
*/
|
|
7668
7664
|
function clearSessionStorage() {
|
|
7669
|
-
window.sessionStorage.clear();
|
|
7665
|
+
window && window.sessionStorage.clear();
|
|
7670
7666
|
}
|
|
7671
7667
|
|
|
7672
7668
|
/**
|
|
@@ -7811,7 +7807,7 @@
|
|
|
7811
7807
|
* @returns {Object} 返回浏览器信息
|
|
7812
7808
|
*/
|
|
7813
7809
|
function getBrowserInfo() {
|
|
7814
|
-
const ua = window.navigator.userAgent.toLowerCase();
|
|
7810
|
+
const ua = window && window.navigator.userAgent.toLowerCase();
|
|
7815
7811
|
// ie
|
|
7816
7812
|
const ie = ua.match(/rv:([\d.]+)\) like gecko/) || ua.match(/msie ([\d\.]+)/);
|
|
7817
7813
|
// edge
|
|
@@ -7854,7 +7850,7 @@
|
|
|
7854
7850
|
* @returns {boolean} 返回true和false
|
|
7855
7851
|
*/
|
|
7856
7852
|
function isPhone() {
|
|
7857
|
-
const ua = window.navigator.userAgent;
|
|
7853
|
+
const ua = window && window.navigator.userAgent;
|
|
7858
7854
|
return /Android|webOS|iPhone|iPod|BlackBerry|Windows Phone|IEMobile/i.test(ua);
|
|
7859
7855
|
}
|
|
7860
7856
|
/* 操作系统类型 */
|
|
@@ -7863,7 +7859,7 @@
|
|
|
7863
7859
|
* @returns {boolean} 返回true和false
|
|
7864
7860
|
*/
|
|
7865
7861
|
function isAndroid() {
|
|
7866
|
-
const ua = window.navigator.userAgent;
|
|
7862
|
+
const ua = window && window.navigator.userAgent;
|
|
7867
7863
|
return /Android|BlackBerry/i.test(ua);
|
|
7868
7864
|
}
|
|
7869
7865
|
/**
|
|
@@ -7871,7 +7867,7 @@
|
|
|
7871
7867
|
* @returns {boolean} 返回true和false
|
|
7872
7868
|
*/
|
|
7873
7869
|
function isIos() {
|
|
7874
|
-
const ua = window.navigator.userAgent;
|
|
7870
|
+
const ua = window && window.navigator.userAgent;
|
|
7875
7871
|
return /iPhone|iPad|iPod|iOS/i.test(ua);
|
|
7876
7872
|
}
|
|
7877
7873
|
/**
|
|
@@ -7879,7 +7875,7 @@
|
|
|
7879
7875
|
* @returns {boolean} 返回true和false
|
|
7880
7876
|
*/
|
|
7881
7877
|
function isWindowsPhone() {
|
|
7882
|
-
const ua = window.navigator.userAgent;
|
|
7878
|
+
const ua = window && window.navigator.userAgent;
|
|
7883
7879
|
return /Windows Phone/i.test(ua);
|
|
7884
7880
|
}
|
|
7885
7881
|
/**
|
|
@@ -7887,7 +7883,7 @@
|
|
|
7887
7883
|
* @returns {boolean} 返回true和false
|
|
7888
7884
|
*/
|
|
7889
7885
|
function isWindows() {
|
|
7890
|
-
const ua = window.navigator.userAgent;
|
|
7886
|
+
const ua = window && window.navigator.userAgent;
|
|
7891
7887
|
return /win/i.test(ua);
|
|
7892
7888
|
}
|
|
7893
7889
|
/**
|
|
@@ -7895,7 +7891,7 @@
|
|
|
7895
7891
|
* @returns {boolean} 返回true和false
|
|
7896
7892
|
*/
|
|
7897
7893
|
function isLinux() {
|
|
7898
|
-
const ua = window.navigator.userAgent;
|
|
7894
|
+
const ua = window && window.navigator.userAgent;
|
|
7899
7895
|
return /linux/i.test(ua);
|
|
7900
7896
|
}
|
|
7901
7897
|
/**
|
|
@@ -7903,7 +7899,7 @@
|
|
|
7903
7899
|
* @returns {boolean} 返回true和false
|
|
7904
7900
|
*/
|
|
7905
7901
|
function isMac() {
|
|
7906
|
-
const ua = window.navigator.userAgent;
|
|
7902
|
+
const ua = window && window.navigator.userAgent;
|
|
7907
7903
|
return /mac/i.test(ua);
|
|
7908
7904
|
}
|
|
7909
7905
|
/* 苹果设备类型 */
|
|
@@ -7912,7 +7908,7 @@
|
|
|
7912
7908
|
*@returns {boolean} 返回true和false
|
|
7913
7909
|
*/
|
|
7914
7910
|
function isIphone() {
|
|
7915
|
-
const ua = window.navigator.userAgent;
|
|
7911
|
+
const ua = window && window.navigator.userAgent;
|
|
7916
7912
|
return /iPhone/i.test(ua);
|
|
7917
7913
|
}
|
|
7918
7914
|
/**
|
|
@@ -7920,7 +7916,7 @@
|
|
|
7920
7916
|
*@return {boolean} 返回true和false
|
|
7921
7917
|
*/
|
|
7922
7918
|
function isIpad() {
|
|
7923
|
-
const ua = window.navigator.userAgent;
|
|
7919
|
+
const ua = window && window.navigator.userAgent;
|
|
7924
7920
|
return /iPod/i.test(ua);
|
|
7925
7921
|
}
|
|
7926
7922
|
/* 手机浏览器类型 */
|
|
@@ -7929,7 +7925,7 @@
|
|
|
7929
7925
|
* @returns {boolean} 返回true和false
|
|
7930
7926
|
*/
|
|
7931
7927
|
function isWeixin() {
|
|
7932
|
-
const ua = window.navigator.userAgent;
|
|
7928
|
+
const ua = window && window.navigator.userAgent;
|
|
7933
7929
|
return /MicroMessenger/i.test(ua);
|
|
7934
7930
|
}
|
|
7935
7931
|
/**
|
|
@@ -7937,7 +7933,7 @@
|
|
|
7937
7933
|
* @returns {boolean} 返回true和false
|
|
7938
7934
|
*/
|
|
7939
7935
|
function isQQ() {
|
|
7940
|
-
const ua = window.navigator.userAgent;
|
|
7936
|
+
const ua = window && window.navigator.userAgent;
|
|
7941
7937
|
return /QQ/i.test(ua);
|
|
7942
7938
|
}
|
|
7943
7939
|
|
|
@@ -7983,7 +7979,7 @@
|
|
|
7983
7979
|
*/
|
|
7984
7980
|
function getClipboardText() {
|
|
7985
7981
|
return new Promise((resolve, reject) => {
|
|
7986
|
-
if (window.navigator
|
|
7982
|
+
if (window && window.navigator) {
|
|
7987
7983
|
window.navigator.clipboard
|
|
7988
7984
|
.readText()
|
|
7989
7985
|
.then((text) => {
|
|
@@ -8007,7 +8003,7 @@
|
|
|
8007
8003
|
function setClipboard(data) {
|
|
8008
8004
|
return new Promise((resolve, reject) => {
|
|
8009
8005
|
// 现代浏览器
|
|
8010
|
-
if (window.navigator
|
|
8006
|
+
if (window && window.navigator) {
|
|
8011
8007
|
let clipboardItem = null;
|
|
8012
8008
|
// 是文本类型
|
|
8013
8009
|
if (typeof data === "string") {
|
|
@@ -8040,7 +8036,7 @@
|
|
|
8040
8036
|
function setClipboardText(text) {
|
|
8041
8037
|
return new Promise((resolve, reject) => {
|
|
8042
8038
|
// 现代浏览器
|
|
8043
|
-
if (window.navigator
|
|
8039
|
+
if (window && window.navigator) {
|
|
8044
8040
|
window.navigator.clipboard.writeText(text).then((success) => {
|
|
8045
8041
|
resolve(true);
|
|
8046
8042
|
}, (failed) => {
|