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