@daysnap/utils 0.0.41 → 0.0.43
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/README.md +24 -4
- package/docs/README.md +20 -4
- package/docs/modules.md +228 -93
- package/es/base64ToBlob.js +11 -17
- package/es/blobToBase64.js +10 -10
- package/es/canvasToBlob.js +4 -6
- package/es/clone.d.ts +4 -6
- package/es/clone.js +18 -8
- package/es/cloneSimple.d.ts +7 -0
- package/es/cloneSimple.js +9 -0
- package/es/compareVersion.js +27 -40
- package/es/compressImage.js +11 -13
- package/es/createHexColorByHash.js +59 -56
- package/es/debounce.d.ts +5 -0
- package/es/debounce.js +14 -0
- package/es/downloadFile.js +7 -7
- package/es/each.js +11 -10
- package/es/filterBankCardNo.js +4 -2
- package/es/filterCRLF.js +2 -2
- package/es/filterEmoji.js +13 -6
- package/es/filterIdCard.js +2 -2
- package/es/filterName.js +12 -12
- package/es/filterPhone.js +3 -4
- package/es/formatAmount.js +18 -20
- package/es/formatDate.js +28 -29
- package/es/getBlobByUrl.js +17 -18
- package/es/getDayMillisecond.js +3 -4
- package/es/getImageInfo.js +9 -9
- package/es/getRandomColor.js +2 -2
- package/es/getVideoInfo.js +11 -11
- package/es/inBrowser.js +2 -2
- package/es/index.d.ts +4 -0
- package/es/index.js +5 -1
- package/es/isAndroid.js +2 -2
- package/es/isArray.js +2 -2
- package/es/isBoolean.js +2 -2
- package/es/isEmail.js +2 -2
- package/es/isEmpty.js +2 -2
- package/es/isEmptyObject.js +2 -2
- package/es/isError.js +2 -2
- package/es/isFunction.js +2 -2
- package/es/isIOS.js +2 -2
- package/es/isIdCard.js +2 -2
- package/es/isJSONString.js +8 -7
- package/es/isLan.js +29 -28
- package/es/isLicenseCode.js +2 -2
- package/es/isMobile.js +7 -6
- package/es/isNull.js +2 -2
- package/es/isNumber.js +2 -2
- package/es/isObject.js +2 -2
- package/es/isPhone.js +2 -2
- package/es/isPromise.js +2 -2
- package/es/isRegExp.js +2 -2
- package/es/isString.js +2 -2
- package/es/isURL.d.ts +4 -0
- package/es/isURL.js +6 -0
- package/es/isUndefined.js +2 -2
- package/es/isWeixin.js +2 -2
- package/es/isWindow.js +2 -2
- package/es/loadResource.d.ts +1 -1
- package/es/loadResource.js +27 -23
- package/es/omit.js +7 -9
- package/es/padding.js +5 -5
- package/es/parseDate.js +7 -7
- package/es/parseError.js +15 -16
- package/es/parseObject.d.ts +2 -1
- package/es/parseObject.js +9 -8
- package/es/parsePath.js +7 -7
- package/es/parseQuery.d.ts +1 -1
- package/es/parseQuery.js +13 -24
- package/es/pick.js +7 -8
- package/es/replaceCrlf.js +2 -2
- package/es/reserve.js +2 -2
- package/es/round.js +38 -39
- package/es/sleep.d.ts +4 -2
- package/es/sleep.js +8 -7
- package/es/storage/factory.d.ts +2 -2
- package/es/storage/factory.js +44 -54
- package/es/storage/index.d.ts +4 -4
- package/es/storage/index.js +10 -10
- package/es/stringTrim.d.ts +3 -1
- package/es/stringTrim.js +17 -19
- package/es/stringifyQuery.d.ts +1 -1
- package/es/stringifyQuery.js +11 -8
- package/es/throttle.d.ts +5 -0
- package/es/throttle.js +17 -0
- package/es/typeOf.d.ts +1 -1
- package/es/typeOf.js +2 -2
- package/lib/base64ToBlob.js +14 -23
- package/lib/blobToBase64.js +13 -15
- package/lib/canvasToBlob.js +7 -11
- package/lib/clone.d.ts +4 -6
- package/lib/clone.js +21 -13
- package/lib/cloneSimple.d.ts +7 -0
- package/lib/cloneSimple.js +13 -0
- package/lib/compareVersion.js +30 -46
- package/lib/compressImage.js +15 -19
- package/lib/createHexColorByHash.js +60 -60
- package/lib/debounce.d.ts +5 -0
- package/lib/debounce.js +18 -0
- package/lib/downloadFile.js +10 -12
- package/lib/each.js +14 -15
- package/lib/filterBankCardNo.js +7 -7
- package/lib/filterCRLF.js +5 -7
- package/lib/filterEmoji.js +16 -11
- package/lib/filterIdCard.js +5 -7
- package/lib/filterName.js +15 -17
- package/lib/filterPhone.js +6 -9
- package/lib/formatAmount.js +21 -25
- package/lib/formatDate.js +32 -35
- package/lib/getBlobByUrl.js +20 -23
- package/lib/getDayMillisecond.js +6 -9
- package/lib/getImageInfo.js +12 -14
- package/lib/getRandomColor.js +5 -7
- package/lib/getVideoInfo.js +14 -16
- package/lib/inBrowser.js +5 -7
- package/lib/index.d.ts +4 -0
- package/lib/index.js +84 -708
- package/lib/isAndroid.js +5 -7
- package/lib/isArray.js +5 -7
- package/lib/isBoolean.js +5 -7
- package/lib/isEmail.js +5 -7
- package/lib/isEmpty.js +7 -9
- package/lib/isEmptyObject.js +5 -7
- package/lib/isError.js +5 -7
- package/lib/isFunction.js +5 -7
- package/lib/isIOS.js +5 -7
- package/lib/isIdCard.js +5 -7
- package/lib/isJSONString.js +12 -13
- package/lib/isLan.js +32 -33
- package/lib/isLicenseCode.js +5 -7
- package/lib/isMobile.js +10 -11
- package/lib/isNull.js +5 -7
- package/lib/isNumber.js +5 -7
- package/lib/isObject.js +5 -7
- package/lib/isPhone.js +5 -7
- package/lib/isPromise.js +5 -7
- package/lib/isRegExp.js +5 -7
- package/lib/isString.js +5 -7
- package/lib/isURL.d.ts +4 -0
- package/lib/isURL.js +10 -0
- package/lib/isUndefined.js +5 -7
- package/lib/isWeixin.js +5 -7
- package/lib/isWindow.js +5 -7
- package/lib/loadResource.d.ts +1 -1
- package/lib/loadResource.js +31 -29
- package/lib/omit.js +10 -15
- package/lib/padding.js +8 -10
- package/lib/parseDate.js +10 -12
- package/lib/parseError.js +21 -24
- package/lib/parseObject.d.ts +2 -1
- package/lib/parseObject.js +12 -13
- package/lib/parsePath.js +10 -12
- package/lib/parseQuery.d.ts +1 -1
- package/lib/parseQuery.js +17 -31
- package/lib/pick.js +10 -13
- package/lib/replaceCrlf.js +5 -7
- package/lib/reserve.js +6 -8
- package/lib/round.js +41 -44
- package/lib/sleep.d.ts +4 -2
- package/lib/sleep.js +11 -12
- package/lib/storage/factory.d.ts +2 -2
- package/lib/storage/factory.js +47 -60
- package/lib/storage/index.d.ts +4 -4
- package/lib/storage/index.js +12 -17
- package/lib/stringTrim.d.ts +3 -1
- package/lib/stringTrim.js +20 -24
- package/lib/stringifyQuery.d.ts +1 -1
- package/lib/stringifyQuery.js +15 -14
- package/lib/throttle.d.ts +5 -0
- package/lib/throttle.js +21 -0
- package/lib/typeOf.d.ts +1 -1
- package/lib/typeOf.js +5 -7
- package/package.json +23 -18
package/es/parseObject.d.ts
CHANGED
package/es/parseObject.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 返回对象
|
|
3
|
+
* parseObject('a.b.c', 1) => { a: { b: { c: 1 } } }
|
|
3
4
|
*/
|
|
4
5
|
export function parseObject(path, value) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
6
|
+
const result = {};
|
|
7
|
+
const segments = path ? path.split('.') : [];
|
|
8
|
+
segments.reduce((res, key, index, arr) => {
|
|
9
|
+
res[key] = index === arr.length - 1 ? value : {};
|
|
10
|
+
return res[key];
|
|
11
|
+
}, result);
|
|
12
|
+
return result;
|
|
13
|
+
}
|
package/es/parsePath.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* 根据路径解析值
|
|
3
3
|
*/
|
|
4
4
|
export function parsePath(obj, path) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
5
|
+
const segments = path ? path.split('.') : [];
|
|
6
|
+
segments.forEach((key) => {
|
|
7
|
+
// eslint-disable-next-line no-param-reassign
|
|
8
|
+
obj = obj[key];
|
|
9
|
+
});
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
package/es/parseQuery.d.ts
CHANGED
package/es/parseQuery.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
1
|
import { isJSONString } from './isJSONString';
|
|
4
2
|
/**
|
|
5
3
|
* 解析url参数
|
|
@@ -7,26 +5,17 @@ import { isJSONString } from './isJSONString';
|
|
|
7
5
|
* @param k 键名
|
|
8
6
|
*/
|
|
9
7
|
export function parseQuery(v, k) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
17
|
-
var _iterator = _createForOfIteratorHelper(query.entries()),
|
|
18
|
-
_step;
|
|
19
|
-
try {
|
|
20
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
21
|
-
var _step$value = _slicedToArray(_step.value, 2),
|
|
22
|
-
key = _step$value[0],
|
|
23
|
-
value = _step$value[1];
|
|
24
|
-
res[key] = isJSONString(value) ? JSON.parse(value) : value;
|
|
8
|
+
const url = new URL(v !== null && v !== void 0 ? v : '');
|
|
9
|
+
const searchStr = v ? url.search : window.location.search;
|
|
10
|
+
const query = new URLSearchParams(decodeURIComponent(searchStr));
|
|
11
|
+
// 单个直接返回
|
|
12
|
+
if (k) {
|
|
13
|
+
return query.get(k);
|
|
25
14
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
15
|
+
const res = {};
|
|
16
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
17
|
+
for (const [key, value] of query.entries()) {
|
|
18
|
+
res[key] = isJSONString(value) ? JSON.parse(value) : value;
|
|
19
|
+
}
|
|
20
|
+
return res;
|
|
21
|
+
}
|
package/es/pick.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 挑选对象里的某些属性,新对象返回
|
|
3
3
|
*/
|
|
4
|
-
export function pick(obj) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
4
|
+
export function pick(obj, fields = []) {
|
|
5
|
+
const clone = {};
|
|
6
|
+
fields.forEach((key) => {
|
|
7
|
+
clone[key] = obj[key];
|
|
8
|
+
});
|
|
9
|
+
return clone;
|
|
10
|
+
}
|
package/es/replaceCrlf.js
CHANGED
package/es/reserve.js
CHANGED
package/es/round.js
CHANGED
|
@@ -4,45 +4,44 @@
|
|
|
4
4
|
* @param fractionDigits 需要保留的小数点位数
|
|
5
5
|
*/
|
|
6
6
|
export function round(val, fractionDigits) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return number.toString();
|
|
11
|
-
}
|
|
12
|
-
if (typeof fractionDigits === 'undefined' || fractionDigits === 0) {
|
|
13
|
-
return Math.round(number).toString();
|
|
14
|
-
}
|
|
15
|
-
var result = number.toString();
|
|
16
|
-
var arr = result.split('.');
|
|
17
|
-
// 整数的情况
|
|
18
|
-
if (arr.length < 2) {
|
|
19
|
-
result += '.';
|
|
20
|
-
for (var i = 0; i < fractionDigits; i += 1) {
|
|
21
|
-
result += '0';
|
|
7
|
+
const number = val;
|
|
8
|
+
if (number >= Math.pow(10, 21)) {
|
|
9
|
+
return number.toString();
|
|
22
10
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
if (typeof fractionDigits === 'undefined' || fractionDigits === 0) {
|
|
12
|
+
return Math.round(number).toString();
|
|
13
|
+
}
|
|
14
|
+
let result = number.toString();
|
|
15
|
+
const arr = result.split('.');
|
|
16
|
+
// 整数的情况
|
|
17
|
+
if (arr.length < 2) {
|
|
18
|
+
result += '.';
|
|
19
|
+
for (let i = 0; i < fractionDigits; i += 1) {
|
|
20
|
+
result += '0';
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
const integer = arr[0];
|
|
25
|
+
const decimal = arr[1];
|
|
26
|
+
if (decimal.length === fractionDigits) {
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
if (decimal.length < fractionDigits) {
|
|
30
|
+
for (let i = 0; i < fractionDigits - decimal.length; i += 1) {
|
|
31
|
+
result += '0';
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
result = `${integer}.${decimal.substr(0, fractionDigits)}`;
|
|
36
|
+
let last = decimal.substr(fractionDigits, 1);
|
|
37
|
+
if (/^\d(9){5,}[0-9]$/.test(decimal.substr(fractionDigits))) {
|
|
38
|
+
last = (+last + 1).toString();
|
|
39
|
+
}
|
|
40
|
+
// 四舍五入,转换为整数再处理,避免浮点数精度的损失
|
|
41
|
+
if (parseInt(last, 10) >= 5) {
|
|
42
|
+
const x = Math.pow(10, fractionDigits);
|
|
43
|
+
result = (Math.round(parseFloat(result) * x) + 1) / x;
|
|
44
|
+
result = round(result, fractionDigits);
|
|
33
45
|
}
|
|
34
46
|
return result;
|
|
35
|
-
|
|
36
|
-
result = "".concat(integer, ".").concat(decimal.substr(0, fractionDigits));
|
|
37
|
-
var last = decimal.substr(fractionDigits, 1);
|
|
38
|
-
if (/^\d(9){5,}[0-9]$/.test(decimal.substr(fractionDigits))) {
|
|
39
|
-
last = (+last + 1).toString();
|
|
40
|
-
}
|
|
41
|
-
// 四舍五入,转换为整数再处理,避免浮点数精度的损失
|
|
42
|
-
if (parseInt(last, 10) >= 5) {
|
|
43
|
-
var x = Math.pow(10, fractionDigits);
|
|
44
|
-
result = (Math.round(parseFloat(result) * x) + 1) / x;
|
|
45
|
-
result = round(result, fractionDigits);
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
47
|
+
}
|
package/es/sleep.d.ts
CHANGED
package/es/sleep.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 休眠方法
|
|
3
|
+
* @param ms 休眠时长 毫秒
|
|
4
|
+
* @param isSuccess 默认执行成功
|
|
3
5
|
*/
|
|
4
|
-
export function sleep(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
6
|
+
export function sleep(ms, isSuccess = true) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
setTimeout(isSuccess ? resolve : reject, ms);
|
|
9
|
+
});
|
|
10
|
+
}
|
package/es/storage/factory.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export declare function factory(type: 'sessionStorage' | 'localStorage'): {
|
|
2
2
|
setItem: <T = any>(key: string, val: T) => T;
|
|
3
|
-
getItem: <T_1 = any>(key: string, defaultVal?: Partial<T_1>) => T_1;
|
|
3
|
+
getItem: <T_1 = any>(key: string, defaultVal?: Partial<T_1> | null) => T_1;
|
|
4
4
|
removeItem: (key: string) => void;
|
|
5
5
|
updateItem: <T_2 = any>(key: string, val: Partial<T_2>) => T_2;
|
|
6
6
|
clear: () => void;
|
|
7
7
|
generate: <T_3 = any>(key: string) => {
|
|
8
8
|
setItem: (val: T_3) => T_3;
|
|
9
|
-
getItem: (defaultVal?: Partial<T_3>) => T_3;
|
|
9
|
+
getItem: (defaultVal?: Partial<T_3> | undefined) => T_3;
|
|
10
10
|
removeItem: () => void;
|
|
11
11
|
updateItem: (val: Partial<T_3>) => T_3;
|
|
12
12
|
};
|
package/es/storage/factory.js
CHANGED
|
@@ -1,57 +1,47 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
1
|
export function factory(type) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
const fn = window[type];
|
|
3
|
+
// 设置
|
|
4
|
+
const setItem = (key, val) => {
|
|
5
|
+
fn.setItem(key, JSON.stringify(val));
|
|
6
|
+
return val;
|
|
7
|
+
};
|
|
8
|
+
// 获取
|
|
9
|
+
const getItem = (key, defaultVal = null) => {
|
|
10
|
+
const val = fn.getItem(key);
|
|
11
|
+
// 如果为 null 取默认值
|
|
12
|
+
if (val === null) {
|
|
13
|
+
return defaultVal;
|
|
14
|
+
}
|
|
15
|
+
return JSON.parse(val);
|
|
16
|
+
};
|
|
17
|
+
// 删除
|
|
18
|
+
const removeItem = (key) => {
|
|
19
|
+
fn.removeItem(key);
|
|
20
|
+
};
|
|
21
|
+
// 更新
|
|
22
|
+
const updateItem = (key, val) => {
|
|
23
|
+
const prev = getItem(key);
|
|
24
|
+
return setItem(key, Object.assign(Object.assign({}, prev), val));
|
|
25
|
+
};
|
|
26
|
+
// 清除
|
|
27
|
+
const clear = () => {
|
|
28
|
+
fn.clear();
|
|
29
|
+
};
|
|
30
|
+
// 生成
|
|
31
|
+
const generate = (key) => {
|
|
32
|
+
return {
|
|
33
|
+
setItem: (val) => setItem(key, val),
|
|
34
|
+
getItem: (defaultVal) => getItem(key, defaultVal),
|
|
35
|
+
removeItem: () => removeItem(key),
|
|
36
|
+
updateItem: (val) => updateItem(key, val),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
34
39
|
return {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
removeItem: function removeItem() {
|
|
42
|
-
return _removeItem(key);
|
|
43
|
-
},
|
|
44
|
-
updateItem: function updateItem(val) {
|
|
45
|
-
return _updateItem(key, val);
|
|
46
|
-
}
|
|
40
|
+
setItem,
|
|
41
|
+
getItem,
|
|
42
|
+
removeItem,
|
|
43
|
+
updateItem,
|
|
44
|
+
clear,
|
|
45
|
+
generate,
|
|
47
46
|
};
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
setItem: _setItem,
|
|
51
|
-
getItem: _getItem,
|
|
52
|
-
removeItem: _removeItem,
|
|
53
|
-
updateItem: _updateItem,
|
|
54
|
-
clear: clear,
|
|
55
|
-
generate: generate
|
|
56
|
-
};
|
|
57
|
-
}
|
|
47
|
+
}
|
package/es/storage/index.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
export declare const getCache: () => {
|
|
2
2
|
setItem: <T = any>(key: string, val: T) => T;
|
|
3
|
-
getItem: <T_1 = any>(key: string, defaultVal?: Partial<T_1>) => T_1;
|
|
3
|
+
getItem: <T_1 = any>(key: string, defaultVal?: Partial<T_1> | null) => T_1;
|
|
4
4
|
removeItem: (key: string) => void;
|
|
5
5
|
updateItem: <T_2 = any>(key: string, val: Partial<T_2>) => T_2;
|
|
6
6
|
clear: () => void;
|
|
7
7
|
generate: <T_3 = any>(key: string) => {
|
|
8
8
|
setItem: (val: T_3) => T_3;
|
|
9
|
-
getItem: (defaultVal?: Partial<T_3>) => T_3;
|
|
9
|
+
getItem: (defaultVal?: Partial<T_3> | undefined) => T_3;
|
|
10
10
|
removeItem: () => void;
|
|
11
11
|
updateItem: (val: Partial<T_3>) => T_3;
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
export declare const getLocal: () => {
|
|
15
15
|
setItem: <T = any>(key: string, val: T) => T;
|
|
16
|
-
getItem: <T_1 = any>(key: string, defaultVal?: Partial<T_1>) => T_1;
|
|
16
|
+
getItem: <T_1 = any>(key: string, defaultVal?: Partial<T_1> | null) => T_1;
|
|
17
17
|
removeItem: (key: string) => void;
|
|
18
18
|
updateItem: <T_2 = any>(key: string, val: Partial<T_2>) => T_2;
|
|
19
19
|
clear: () => void;
|
|
20
20
|
generate: <T_3 = any>(key: string) => {
|
|
21
21
|
setItem: (val: T_3) => T_3;
|
|
22
|
-
getItem: (defaultVal?: Partial<T_3>) => T_3;
|
|
22
|
+
getItem: (defaultVal?: Partial<T_3> | undefined) => T_3;
|
|
23
23
|
removeItem: () => void;
|
|
24
24
|
updateItem: (val: Partial<T_3>) => T_3;
|
|
25
25
|
};
|
package/es/storage/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { factory } from './factory';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
const getStorage = (type) => {
|
|
3
|
+
let instance = null;
|
|
4
|
+
return () => {
|
|
5
|
+
if (!instance) {
|
|
6
|
+
instance = factory(type);
|
|
7
|
+
}
|
|
8
|
+
return instance;
|
|
9
|
+
};
|
|
10
10
|
};
|
|
11
|
-
export
|
|
12
|
-
export
|
|
11
|
+
export const getCache = getStorage('sessionStorage');
|
|
12
|
+
export const getLocal = getStorage('localStorage');
|
package/es/stringTrim.d.ts
CHANGED
package/es/stringTrim.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
2
|
+
* 去除字符串空格
|
|
3
|
+
* @param str 字符串值
|
|
4
|
+
* @param type 方式 1-所有空格,2-前后空格,3-前空格,4-后空格
|
|
3
5
|
*/
|
|
4
|
-
export function stringTrim(str, type) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
default:
|
|
19
|
-
return str;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
6
|
+
export function stringTrim(str, type = 1) {
|
|
7
|
+
switch (type) {
|
|
8
|
+
case 1:
|
|
9
|
+
return str.replace(/\s+/g, '');
|
|
10
|
+
case 2:
|
|
11
|
+
return str.replace(/(^\s*)|(\s*$)/g, '');
|
|
12
|
+
case 3:
|
|
13
|
+
return str.replace(/(^\s*)/g, '');
|
|
14
|
+
case 4:
|
|
15
|
+
return str.replace(/(\s*$)/g, '');
|
|
16
|
+
default:
|
|
17
|
+
return str;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/es/stringifyQuery.d.ts
CHANGED
package/es/stringifyQuery.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { isEmptyObject } from './isEmptyObject';
|
|
2
|
+
import { isString } from './isString';
|
|
2
3
|
/**
|
|
3
4
|
* 说明
|
|
4
5
|
*/
|
|
5
6
|
export function stringifyQuery(v) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
7
|
+
if (isEmptyObject(v)) {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
const query = new URLSearchParams();
|
|
11
|
+
Object.keys(v).forEach((key) => {
|
|
12
|
+
const value = isString(v[key]) ? v[key] : JSON.stringify(v[key]);
|
|
13
|
+
query.append(key, value);
|
|
14
|
+
});
|
|
15
|
+
return query.toString();
|
|
16
|
+
}
|
package/es/throttle.d.ts
ADDED
package/es/throttle.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 节流函数
|
|
3
|
+
* 减少事件执行次数,有规律的执行
|
|
4
|
+
*/
|
|
5
|
+
export function throttle(fn, ms) {
|
|
6
|
+
let timer = null;
|
|
7
|
+
// eslint-disable-next-line func-names
|
|
8
|
+
return function (...args) {
|
|
9
|
+
if (timer) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
timer = setTimeout(() => {
|
|
13
|
+
fn.apply(this, args);
|
|
14
|
+
timer = null;
|
|
15
|
+
}, ms);
|
|
16
|
+
};
|
|
17
|
+
}
|
package/es/typeOf.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param val 待判断数据
|
|
4
4
|
* @returns 'undefined'|'null'|'boolean'|'string'|'number'|'object'|'array'|'function'|'symbol'|'map'|'weakmap'|'bigint'|'regexp'|'date'
|
|
5
5
|
*/
|
|
6
|
-
export declare function typeOf
|
|
6
|
+
export declare function typeOf(val: unknown): string;
|
package/es/typeOf.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* @returns 'undefined'|'null'|'boolean'|'string'|'number'|'object'|'array'|'function'|'symbol'|'map'|'weakmap'|'bigint'|'regexp'|'date'
|
|
5
5
|
*/
|
|
6
6
|
export function typeOf(val) {
|
|
7
|
-
|
|
8
|
-
}
|
|
7
|
+
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
|
|
8
|
+
}
|
package/lib/base64ToBlob.js
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.base64ToBlob = base64ToBlob;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.base64ToBlob = void 0;
|
|
9
4
|
/**
|
|
10
5
|
* base64 转 blob
|
|
11
6
|
* @param base64 base64字符串
|
|
12
7
|
* @param contentType 文件类型
|
|
13
8
|
*/
|
|
14
9
|
function base64ToBlob(base64, contentType) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return new Blob([u8arr], {
|
|
28
|
-
type: type
|
|
29
|
-
});
|
|
30
|
-
}
|
|
10
|
+
var _a;
|
|
11
|
+
const [prefix, rest] = base64.split(',');
|
|
12
|
+
const type = contentType !== null && contentType !== void 0 ? contentType : (_a = prefix.match(/:(.*?);/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
13
|
+
const data = window.atob(rest);
|
|
14
|
+
let len = data.length;
|
|
15
|
+
const u8arr = new Uint8Array(len);
|
|
16
|
+
while (len--) {
|
|
17
|
+
u8arr[len] = data.charCodeAt(len);
|
|
18
|
+
}
|
|
19
|
+
return new Blob([u8arr], { type });
|
|
20
|
+
}
|
|
21
|
+
exports.base64ToBlob = base64ToBlob;
|
package/lib/blobToBase64.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.blobToBase64 = blobToBase64;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.blobToBase64 = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* blob 转 base64
|
|
9
6
|
*/
|
|
10
7
|
function blobToBase64(blob) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const fileReader = new FileReader();
|
|
10
|
+
fileReader.onload = (res) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
resolve((_b = (_a = res.target) === null || _a === void 0 ? void 0 : _a.result) !== null && _b !== void 0 ? _b : '');
|
|
13
|
+
};
|
|
14
|
+
fileReader.onerror = reject;
|
|
15
|
+
fileReader.readAsDataURL(blob);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.blobToBase64 = blobToBase64;
|