@daysnap/utils 0.0.1
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/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/base64ToBlob.d.ts +4 -0
- package/dist/blobToBase64.d.ts +4 -0
- package/dist/compareVersion.d.ts +7 -0
- package/dist/compressImage.d.ts +4 -0
- package/dist/createHexColorByHash.d.ts +4 -0
- package/dist/downloadFile.d.ts +6 -0
- package/dist/filterBankCardNo.d.ts +4 -0
- package/dist/filterEmoji.d.ts +4 -0
- package/dist/filterIdCard.d.ts +4 -0
- package/dist/filterName.d.ts +4 -0
- package/dist/filterPhone.d.ts +6 -0
- package/dist/formatAmount.d.ts +4 -0
- package/dist/formatDate.d.ts +4 -0
- package/dist/getBlobByUrl.d.ts +4 -0
- package/dist/getImageInfo.d.ts +4 -0
- package/dist/getVideoInfo.d.ts +4 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +604 -0
- package/dist/isAndroid.d.ts +4 -0
- package/dist/isEmail.d.ts +4 -0
- package/dist/isEmpty.d.ts +4 -0
- package/dist/isFunction.d.ts +4 -0
- package/dist/isIOS.d.ts +4 -0
- package/dist/isIdCard.d.ts +4 -0
- package/dist/isMobile.d.ts +4 -0
- package/dist/isNull.d.ts +4 -0
- package/dist/isObject.d.ts +4 -0
- package/dist/isPhone.d.ts +4 -0
- package/dist/isPromise.d.ts +4 -0
- package/dist/isRegExp.d.ts +4 -0
- package/dist/isString.d.ts +4 -0
- package/dist/isUndefined.d.ts +4 -0
- package/dist/omit.d.ts +4 -0
- package/dist/parseError.d.ts +4 -0
- package/dist/parsePath.d.ts +4 -0
- package/dist/pick.d.ts +4 -0
- package/dist/replaceCrlf.d.ts +4 -0
- package/dist/reserve.d.ts +7 -0
- package/dist/storage/factory.d.ts +13 -0
- package/dist/storage/index.d.ts +26 -0
- package/es/base64ToBlob.d.ts +4 -0
- package/es/base64ToBlob.js +55 -0
- package/es/blobToBase64.d.ts +4 -0
- package/es/blobToBase64.js +20 -0
- package/es/compareVersion.d.ts +7 -0
- package/es/compareVersion.js +58 -0
- package/es/compressImage.d.ts +4 -0
- package/es/compressImage.js +20 -0
- package/es/createHexColorByHash.d.ts +4 -0
- package/es/createHexColorByHash.js +72 -0
- package/es/downloadFile.d.ts +6 -0
- package/es/downloadFile.js +20 -0
- package/es/filterBankCardNo.d.ts +4 -0
- package/es/filterBankCardNo.js +11 -0
- package/es/filterEmoji.d.ts +4 -0
- package/es/filterEmoji.js +17 -0
- package/es/filterIdCard.d.ts +4 -0
- package/es/filterIdCard.js +8 -0
- package/es/filterName.d.ts +4 -0
- package/es/filterName.js +23 -0
- package/es/filterPhone.d.ts +6 -0
- package/es/filterPhone.js +11 -0
- package/es/formatAmount.d.ts +4 -0
- package/es/formatAmount.js +31 -0
- package/es/formatDate.d.ts +4 -0
- package/es/formatDate.js +44 -0
- package/es/getBlobByUrl.d.ts +4 -0
- package/es/getBlobByUrl.js +27 -0
- package/es/getImageInfo.d.ts +4 -0
- package/es/getImageInfo.js +18 -0
- package/es/getVideoInfo.d.ts +4 -0
- package/es/getVideoInfo.js +20 -0
- package/es/index.d.ts +38 -0
- package/es/index.js +39 -0
- package/es/isAndroid.d.ts +4 -0
- package/es/isAndroid.js +8 -0
- package/es/isEmail.d.ts +4 -0
- package/es/isEmail.js +8 -0
- package/es/isEmpty.d.ts +4 -0
- package/es/isEmpty.js +9 -0
- package/es/isFunction.d.ts +4 -0
- package/es/isFunction.js +6 -0
- package/es/isIOS.d.ts +4 -0
- package/es/isIOS.js +8 -0
- package/es/isIdCard.d.ts +4 -0
- package/es/isIdCard.js +8 -0
- package/es/isMobile.d.ts +4 -0
- package/es/isMobile.js +13 -0
- package/es/isNull.d.ts +4 -0
- package/es/isNull.js +6 -0
- package/es/isObject.d.ts +4 -0
- package/es/isObject.js +8 -0
- package/es/isPhone.d.ts +4 -0
- package/es/isPhone.js +8 -0
- package/es/isPromise.d.ts +4 -0
- package/es/isPromise.js +9 -0
- package/es/isRegExp.d.ts +4 -0
- package/es/isRegExp.js +10 -0
- package/es/isString.d.ts +4 -0
- package/es/isString.js +6 -0
- package/es/isUndefined.d.ts +4 -0
- package/es/isUndefined.js +6 -0
- package/es/omit.d.ts +4 -0
- package/es/omit.js +17 -0
- package/es/parseError.d.ts +4 -0
- package/es/parseError.js +28 -0
- package/es/parsePath.d.ts +4 -0
- package/es/parsePath.js +15 -0
- package/es/pick.d.ts +4 -0
- package/es/pick.js +14 -0
- package/es/replaceCrlf.d.ts +4 -0
- package/es/replaceCrlf.js +9 -0
- package/es/reserve.d.ts +7 -0
- package/es/reserve.js +11 -0
- package/es/storage/factory.d.ts +13 -0
- package/es/storage/factory.js +65 -0
- package/es/storage/index.d.ts +26 -0
- package/es/storage/index.js +3 -0
- package/lib/base64ToBlob.d.ts +4 -0
- package/lib/base64ToBlob.js +93 -0
- package/lib/blobToBase64.d.ts +4 -0
- package/lib/blobToBase64.js +28 -0
- package/lib/compareVersion.d.ts +7 -0
- package/lib/compareVersion.js +68 -0
- package/lib/compressImage.d.ts +4 -0
- package/lib/compressImage.js +27 -0
- package/lib/createHexColorByHash.d.ts +4 -0
- package/lib/createHexColorByHash.js +84 -0
- package/lib/downloadFile.d.ts +6 -0
- package/lib/downloadFile.js +32 -0
- package/lib/filterBankCardNo.d.ts +4 -0
- package/lib/filterBankCardNo.js +21 -0
- package/lib/filterEmoji.d.ts +4 -0
- package/lib/filterEmoji.js +28 -0
- package/lib/filterIdCard.d.ts +4 -0
- package/lib/filterIdCard.js +15 -0
- package/lib/filterName.d.ts +4 -0
- package/lib/filterName.js +31 -0
- package/lib/filterPhone.d.ts +6 -0
- package/lib/filterPhone.js +18 -0
- package/lib/formatAmount.d.ts +4 -0
- package/lib/formatAmount.js +42 -0
- package/lib/formatDate.d.ts +4 -0
- package/lib/formatDate.js +55 -0
- package/lib/getBlobByUrl.d.ts +4 -0
- package/lib/getBlobByUrl.js +36 -0
- package/lib/getImageInfo.d.ts +4 -0
- package/lib/getImageInfo.js +26 -0
- package/lib/getVideoInfo.d.ts +4 -0
- package/lib/getVideoInfo.js +28 -0
- package/lib/index.d.ts +38 -0
- package/lib/index.js +537 -0
- package/lib/isAndroid.d.ts +4 -0
- package/lib/isAndroid.js +15 -0
- package/lib/isEmail.d.ts +4 -0
- package/lib/isEmail.js +15 -0
- package/lib/isEmpty.d.ts +4 -0
- package/lib/isEmpty.js +17 -0
- package/lib/isFunction.d.ts +4 -0
- package/lib/isFunction.js +13 -0
- package/lib/isIOS.d.ts +4 -0
- package/lib/isIOS.js +15 -0
- package/lib/isIdCard.d.ts +4 -0
- package/lib/isIdCard.js +15 -0
- package/lib/isMobile.d.ts +4 -0
- package/lib/isMobile.js +20 -0
- package/lib/isNull.d.ts +4 -0
- package/lib/isNull.js +13 -0
- package/lib/isObject.d.ts +4 -0
- package/lib/isObject.js +15 -0
- package/lib/isPhone.d.ts +4 -0
- package/lib/isPhone.js +15 -0
- package/lib/isPromise.d.ts +4 -0
- package/lib/isPromise.js +17 -0
- package/lib/isRegExp.d.ts +4 -0
- package/lib/isRegExp.js +19 -0
- package/lib/isString.d.ts +4 -0
- package/lib/isString.js +13 -0
- package/lib/isUndefined.d.ts +4 -0
- package/lib/isUndefined.js +13 -0
- package/lib/omit.d.ts +4 -0
- package/lib/omit.js +26 -0
- package/lib/parseError.d.ts +4 -0
- package/lib/parseError.js +37 -0
- package/lib/parsePath.d.ts +4 -0
- package/lib/parsePath.js +23 -0
- package/lib/pick.d.ts +4 -0
- package/lib/pick.js +22 -0
- package/lib/replaceCrlf.d.ts +4 -0
- package/lib/replaceCrlf.js +17 -0
- package/lib/reserve.d.ts +7 -0
- package/lib/reserve.js +18 -0
- package/lib/storage/factory.d.ts +13 -0
- package/lib/storage/factory.js +75 -0
- package/lib/storage/index.d.ts +26 -0
- package/lib/storage/index.js +13 -0
- package/package.json +94 -0
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const version = "0.0.3";
|
|
2
|
+
export * from './base64ToBlob';
|
|
3
|
+
export * from './blobToBase64';
|
|
4
|
+
export * from './compareVersion';
|
|
5
|
+
export * from './compressImage';
|
|
6
|
+
export * from './createHexColorByHash';
|
|
7
|
+
export * from './downloadFile';
|
|
8
|
+
export * from './filterBankCardNo';
|
|
9
|
+
export * from './filterEmoji';
|
|
10
|
+
export * from './filterIdCard';
|
|
11
|
+
export * from './filterName';
|
|
12
|
+
export * from './filterPhone';
|
|
13
|
+
export * from './formatAmount';
|
|
14
|
+
export * from './formatDate';
|
|
15
|
+
export * from './getBlobByUrl';
|
|
16
|
+
export * from './getImageInfo';
|
|
17
|
+
export * from './getVideoInfo';
|
|
18
|
+
export * from './isAndroid';
|
|
19
|
+
export * from './isEmail';
|
|
20
|
+
export * from './isEmpty';
|
|
21
|
+
export * from './isFunction';
|
|
22
|
+
export * from './isIOS';
|
|
23
|
+
export * from './isIdCard';
|
|
24
|
+
export * from './isMobile';
|
|
25
|
+
export * from './isNull';
|
|
26
|
+
export * from './isObject';
|
|
27
|
+
export * from './isPhone';
|
|
28
|
+
export * from './isPromise';
|
|
29
|
+
export * from './isRegExp';
|
|
30
|
+
export * from './isString';
|
|
31
|
+
export * from './isUndefined';
|
|
32
|
+
export * from './omit';
|
|
33
|
+
export * from './parseError';
|
|
34
|
+
export * from './parsePath';
|
|
35
|
+
export * from './pick';
|
|
36
|
+
export * from './replaceCrlf';
|
|
37
|
+
export * from './reserve';
|
|
38
|
+
export * from './storage';
|
package/es/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* 本文件自动生成 './scripts/entry.js' */
|
|
2
|
+
export var version = '0.0.3';
|
|
3
|
+
export * from './base64ToBlob';
|
|
4
|
+
export * from './blobToBase64';
|
|
5
|
+
export * from './compareVersion';
|
|
6
|
+
export * from './compressImage';
|
|
7
|
+
export * from './createHexColorByHash';
|
|
8
|
+
export * from './downloadFile';
|
|
9
|
+
export * from './filterBankCardNo';
|
|
10
|
+
export * from './filterEmoji';
|
|
11
|
+
export * from './filterIdCard';
|
|
12
|
+
export * from './filterName';
|
|
13
|
+
export * from './filterPhone';
|
|
14
|
+
export * from './formatAmount';
|
|
15
|
+
export * from './formatDate';
|
|
16
|
+
export * from './getBlobByUrl';
|
|
17
|
+
export * from './getImageInfo';
|
|
18
|
+
export * from './getVideoInfo';
|
|
19
|
+
export * from './isAndroid';
|
|
20
|
+
export * from './isEmail';
|
|
21
|
+
export * from './isEmpty';
|
|
22
|
+
export * from './isFunction';
|
|
23
|
+
export * from './isIOS';
|
|
24
|
+
export * from './isIdCard';
|
|
25
|
+
export * from './isMobile';
|
|
26
|
+
export * from './isNull';
|
|
27
|
+
export * from './isObject';
|
|
28
|
+
export * from './isPhone';
|
|
29
|
+
export * from './isPromise';
|
|
30
|
+
export * from './isRegExp';
|
|
31
|
+
export * from './isString';
|
|
32
|
+
export * from './isUndefined';
|
|
33
|
+
export * from './omit';
|
|
34
|
+
export * from './parseError';
|
|
35
|
+
export * from './parsePath';
|
|
36
|
+
export * from './pick';
|
|
37
|
+
export * from './replaceCrlf';
|
|
38
|
+
export * from './reserve';
|
|
39
|
+
export * from './storage';
|
package/es/isAndroid.js
ADDED
package/es/isEmail.d.ts
ADDED
package/es/isEmail.js
ADDED
package/es/isEmpty.d.ts
ADDED
package/es/isEmpty.js
ADDED
package/es/isFunction.js
ADDED
package/es/isIOS.d.ts
ADDED
package/es/isIOS.js
ADDED
package/es/isIdCard.d.ts
ADDED
package/es/isIdCard.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 校验是否是身份证
|
|
5
|
+
*/
|
|
6
|
+
export function isIdCard(val) {
|
|
7
|
+
return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(val);
|
|
8
|
+
}
|
package/es/isMobile.d.ts
ADDED
package/es/isMobile.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 校验设备是否是手机
|
|
5
|
+
*/
|
|
6
|
+
export function isMobile() {
|
|
7
|
+
if (typeof navigator === 'undefined' || typeof window === 'undefined') {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
var agent = navigator.userAgent || navigator.vendor || window.opera;
|
|
12
|
+
return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent === null || agent === void 0 ? void 0 : agent.substr(0, 4));
|
|
13
|
+
}
|
package/es/isNull.d.ts
ADDED
package/es/isNull.js
ADDED
package/es/isObject.d.ts
ADDED
package/es/isObject.js
ADDED
package/es/isPhone.d.ts
ADDED
package/es/isPhone.js
ADDED
package/es/isPromise.js
ADDED
package/es/isRegExp.d.ts
ADDED
package/es/isRegExp.js
ADDED
package/es/isString.d.ts
ADDED
package/es/isString.js
ADDED
package/es/omit.d.ts
ADDED
package/es/omit.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import "core-js/modules/es.object.to-string.js";
|
|
3
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 排除对象里的某些属性,返回剩下的对象,浅拷贝
|
|
7
|
+
*/
|
|
8
|
+
export function omit(obj) {
|
|
9
|
+
var fields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
10
|
+
|
|
11
|
+
var clone = _objectSpread({}, obj);
|
|
12
|
+
|
|
13
|
+
fields.forEach(function (key) {
|
|
14
|
+
delete clone[key];
|
|
15
|
+
});
|
|
16
|
+
return clone;
|
|
17
|
+
}
|
package/es/parseError.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isEmpty } from './isEmpty';
|
|
2
|
+
import { isObject } from './isObject';
|
|
3
|
+
import { isUndefined } from './isUndefined';
|
|
4
|
+
/**
|
|
5
|
+
* 解析格式化 error 获取对应的 message
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function parseError(val) {
|
|
9
|
+
var keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['message', 'msg', 'errorMsg'];
|
|
10
|
+
|
|
11
|
+
if (isEmpty(val)) {
|
|
12
|
+
// null or '' or undefined
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (isObject(val)) {
|
|
17
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
|
18
|
+
var key = keys[i];
|
|
19
|
+
var v = val[key];
|
|
20
|
+
|
|
21
|
+
if (!isUndefined(v)) {
|
|
22
|
+
return v;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return JSON.stringify(val);
|
|
28
|
+
}
|
package/es/parsePath.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "core-js/modules/es.object.to-string.js";
|
|
2
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 根据路径解析值
|
|
6
|
+
*/
|
|
7
|
+
export function parsePath(obj, path) {
|
|
8
|
+
path.split('.').forEach(function (key) {
|
|
9
|
+
var _obj$key;
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line no-param-reassign
|
|
12
|
+
obj = (_obj$key = obj[key]) !== null && _obj$key !== void 0 ? _obj$key : '';
|
|
13
|
+
});
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
package/es/pick.d.ts
ADDED
package/es/pick.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "core-js/modules/es.object.to-string.js";
|
|
2
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 挑选对象里的某些属性,新对象返回
|
|
6
|
+
*/
|
|
7
|
+
export function pick(obj) {
|
|
8
|
+
var fields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
9
|
+
var clone = {};
|
|
10
|
+
fields.forEach(function (key) {
|
|
11
|
+
clone[key] = obj[key];
|
|
12
|
+
});
|
|
13
|
+
return clone;
|
|
14
|
+
}
|
package/es/reserve.d.ts
ADDED
package/es/reserve.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function factory(type: 'sessionStorage' | 'localStorage'): {
|
|
2
|
+
setItem: <T>(key: string, val: T) => T;
|
|
3
|
+
getItem: <T_1>(key: string, defaultVal?: Partial<T_1>) => any;
|
|
4
|
+
removeItem: (key: string) => void;
|
|
5
|
+
updateItem: <T_2>(key: string, val: Partial<T_2>) => T_2;
|
|
6
|
+
clear: () => void;
|
|
7
|
+
generate: <T_3>(key: string) => {
|
|
8
|
+
setItem: (val: T_3) => T_3;
|
|
9
|
+
getItem: (defaultVal?: Partial<T_3>) => any;
|
|
10
|
+
removeItem: () => void;
|
|
11
|
+
updateItem: (val: Partial<T_3>) => T_3;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
export function factory(type) {
|
|
3
|
+
var fn = window[type]; // 设置
|
|
4
|
+
|
|
5
|
+
var _setItem = function setItem(key, val) {
|
|
6
|
+
fn.setItem(key, JSON.stringify(val));
|
|
7
|
+
return val;
|
|
8
|
+
}; // 获取
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _getItem = function getItem(key) {
|
|
12
|
+
var defaultVal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
13
|
+
var val = fn.getItem(key); // 如果为 null 取默认值
|
|
14
|
+
|
|
15
|
+
if (val === null) {
|
|
16
|
+
return defaultVal;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return JSON.parse(val);
|
|
20
|
+
}; // 删除
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var _removeItem = function removeItem(key) {
|
|
24
|
+
fn.removeItem(key);
|
|
25
|
+
}; // 更新
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var _updateItem = function updateItem(key, val) {
|
|
29
|
+
var prev = _getItem(key);
|
|
30
|
+
|
|
31
|
+
return _setItem(key, _objectSpread(_objectSpread({}, prev), val));
|
|
32
|
+
}; // 清除
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
var clear = function clear() {
|
|
36
|
+
fn.clear();
|
|
37
|
+
}; // 生成
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
var generate = function generate(key) {
|
|
41
|
+
return {
|
|
42
|
+
setItem: function setItem(val) {
|
|
43
|
+
return _setItem(key, val);
|
|
44
|
+
},
|
|
45
|
+
getItem: function getItem(defaultVal) {
|
|
46
|
+
return _getItem(key, defaultVal);
|
|
47
|
+
},
|
|
48
|
+
removeItem: function removeItem() {
|
|
49
|
+
return _removeItem(key);
|
|
50
|
+
},
|
|
51
|
+
updateItem: function updateItem(val) {
|
|
52
|
+
return _updateItem(key, val);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
setItem: _setItem,
|
|
59
|
+
getItem: _getItem,
|
|
60
|
+
removeItem: _removeItem,
|
|
61
|
+
updateItem: _updateItem,
|
|
62
|
+
clear: clear,
|
|
63
|
+
generate: generate
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const cache: {
|
|
2
|
+
setItem: <T>(key: string, val: T) => T;
|
|
3
|
+
getItem: <T_1>(key: string, defaultVal?: Partial<T_1>) => any;
|
|
4
|
+
removeItem: (key: string) => void;
|
|
5
|
+
updateItem: <T_2>(key: string, val: Partial<T_2>) => T_2;
|
|
6
|
+
clear: () => void;
|
|
7
|
+
generate: <T_3>(key: string) => {
|
|
8
|
+
setItem: (val: T_3) => T_3;
|
|
9
|
+
getItem: (defaultVal?: Partial<T_3>) => any;
|
|
10
|
+
removeItem: () => void;
|
|
11
|
+
updateItem: (val: Partial<T_3>) => T_3;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const local: {
|
|
15
|
+
setItem: <T>(key: string, val: T) => T;
|
|
16
|
+
getItem: <T_1>(key: string, defaultVal?: Partial<T_1>) => any;
|
|
17
|
+
removeItem: (key: string) => void;
|
|
18
|
+
updateItem: <T_2>(key: string, val: Partial<T_2>) => T_2;
|
|
19
|
+
clear: () => void;
|
|
20
|
+
generate: <T_3>(key: string) => {
|
|
21
|
+
setItem: (val: T_3) => T_3;
|
|
22
|
+
getItem: (defaultVal?: Partial<T_3>) => any;
|
|
23
|
+
removeItem: () => void;
|
|
24
|
+
updateItem: (val: Partial<T_3>) => T_3;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.base64ToBlob = base64ToBlob;
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
11
|
+
|
|
12
|
+
require("core-js/modules/es.string.match.js");
|
|
13
|
+
|
|
14
|
+
require("core-js/modules/es.array.iterator.js");
|
|
15
|
+
|
|
16
|
+
require("core-js/modules/es.array-buffer.slice.js");
|
|
17
|
+
|
|
18
|
+
require("core-js/modules/es.object.to-string.js");
|
|
19
|
+
|
|
20
|
+
require("core-js/modules/es.typed-array.uint8-array.js");
|
|
21
|
+
|
|
22
|
+
require("core-js/modules/es.typed-array.copy-within.js");
|
|
23
|
+
|
|
24
|
+
require("core-js/modules/es.typed-array.every.js");
|
|
25
|
+
|
|
26
|
+
require("core-js/modules/es.typed-array.fill.js");
|
|
27
|
+
|
|
28
|
+
require("core-js/modules/es.typed-array.filter.js");
|
|
29
|
+
|
|
30
|
+
require("core-js/modules/es.typed-array.find.js");
|
|
31
|
+
|
|
32
|
+
require("core-js/modules/es.typed-array.find-index.js");
|
|
33
|
+
|
|
34
|
+
require("core-js/modules/es.typed-array.for-each.js");
|
|
35
|
+
|
|
36
|
+
require("core-js/modules/es.typed-array.includes.js");
|
|
37
|
+
|
|
38
|
+
require("core-js/modules/es.typed-array.index-of.js");
|
|
39
|
+
|
|
40
|
+
require("core-js/modules/es.typed-array.iterator.js");
|
|
41
|
+
|
|
42
|
+
require("core-js/modules/es.typed-array.join.js");
|
|
43
|
+
|
|
44
|
+
require("core-js/modules/es.typed-array.last-index-of.js");
|
|
45
|
+
|
|
46
|
+
require("core-js/modules/es.typed-array.map.js");
|
|
47
|
+
|
|
48
|
+
require("core-js/modules/es.typed-array.reduce.js");
|
|
49
|
+
|
|
50
|
+
require("core-js/modules/es.typed-array.reduce-right.js");
|
|
51
|
+
|
|
52
|
+
require("core-js/modules/es.typed-array.reverse.js");
|
|
53
|
+
|
|
54
|
+
require("core-js/modules/es.typed-array.set.js");
|
|
55
|
+
|
|
56
|
+
require("core-js/modules/es.typed-array.slice.js");
|
|
57
|
+
|
|
58
|
+
require("core-js/modules/es.typed-array.some.js");
|
|
59
|
+
|
|
60
|
+
require("core-js/modules/es.typed-array.sort.js");
|
|
61
|
+
|
|
62
|
+
require("core-js/modules/es.typed-array.subarray.js");
|
|
63
|
+
|
|
64
|
+
require("core-js/modules/es.typed-array.to-locale-string.js");
|
|
65
|
+
|
|
66
|
+
require("core-js/modules/es.typed-array.to-string.js");
|
|
67
|
+
|
|
68
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* base64 转 blob
|
|
72
|
+
*/
|
|
73
|
+
function base64ToBlob(base64, contentType) {
|
|
74
|
+
var _prefix$match;
|
|
75
|
+
|
|
76
|
+
var _base64$split = base64.split(','),
|
|
77
|
+
_base64$split2 = (0, _slicedToArray2.default)(_base64$split, 2),
|
|
78
|
+
prefix = _base64$split2[0],
|
|
79
|
+
rest = _base64$split2[1];
|
|
80
|
+
|
|
81
|
+
var type = contentType !== null && contentType !== void 0 ? contentType : (_prefix$match = prefix.match(/:(.*?);/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[1];
|
|
82
|
+
var data = window.atob(rest);
|
|
83
|
+
var len = data.length;
|
|
84
|
+
var u8arr = new Uint8Array(len);
|
|
85
|
+
|
|
86
|
+
while (len--) {
|
|
87
|
+
u8arr[len] = data.charCodeAt(len);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return new Blob([u8arr], {
|
|
91
|
+
type: type
|
|
92
|
+
});
|
|
93
|
+
}
|