@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/lib/isIdCard.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isIdCard = isIdCard;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 校验是否是身份证
|
|
12
|
+
*/
|
|
13
|
+
function isIdCard(val) {
|
|
14
|
+
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);
|
|
15
|
+
}
|
package/lib/isMobile.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isMobile = isMobile;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 校验设备是否是手机
|
|
12
|
+
*/
|
|
13
|
+
function isMobile() {
|
|
14
|
+
if (typeof navigator === 'undefined' || typeof window === 'undefined') {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var agent = navigator.userAgent || navigator.vendor || window.opera;
|
|
19
|
+
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));
|
|
20
|
+
}
|
package/lib/isNull.d.ts
ADDED
package/lib/isNull.js
ADDED
package/lib/isObject.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isObject = isObject;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.object.to-string.js");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 校验是否是对象
|
|
12
|
+
*/
|
|
13
|
+
function isObject(val) {
|
|
14
|
+
return Object.prototype.toString.call(val) === '[object Object]';
|
|
15
|
+
}
|
package/lib/isPhone.d.ts
ADDED
package/lib/isPhone.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isPhone = isPhone;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 校验是否是手机号码
|
|
12
|
+
*/
|
|
13
|
+
function isPhone(val) {
|
|
14
|
+
return /^1\d{10}$/.test(val);
|
|
15
|
+
}
|
package/lib/isPromise.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isPromise = isPromise;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.object.to-string.js");
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/es.promise.js");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 校验是否是 promise
|
|
14
|
+
*/
|
|
15
|
+
function isPromise(val) {
|
|
16
|
+
return val instanceof Promise || !!val.then || !!val.catch;
|
|
17
|
+
}
|
package/lib/isRegExp.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isRegExp = isRegExp;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.regexp.constructor.js");
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
11
|
+
|
|
12
|
+
require("core-js/modules/es.regexp.to-string.js");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 校验是否是正则表达式
|
|
16
|
+
*/
|
|
17
|
+
function isRegExp(val) {
|
|
18
|
+
return val instanceof RegExp;
|
|
19
|
+
}
|
package/lib/isString.js
ADDED
package/lib/omit.d.ts
ADDED
package/lib/omit.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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.omit = omit;
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/es.object.to-string.js");
|
|
11
|
+
|
|
12
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
13
|
+
|
|
14
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 排除对象里的某些属性,返回剩下的对象,浅拷贝
|
|
18
|
+
*/
|
|
19
|
+
function omit(obj) {
|
|
20
|
+
var fields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
21
|
+
var clone = (0, _objectSpread2.default)({}, obj);
|
|
22
|
+
fields.forEach(function (key) {
|
|
23
|
+
delete clone[key];
|
|
24
|
+
});
|
|
25
|
+
return clone;
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseError = parseError;
|
|
7
|
+
|
|
8
|
+
var _isEmpty = require("./isEmpty");
|
|
9
|
+
|
|
10
|
+
var _isObject = require("./isObject");
|
|
11
|
+
|
|
12
|
+
var _isUndefined = require("./isUndefined");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 解析格式化 error 获取对应的 message
|
|
16
|
+
*/
|
|
17
|
+
function parseError(val) {
|
|
18
|
+
var keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['message', 'msg', 'errorMsg'];
|
|
19
|
+
|
|
20
|
+
if ((0, _isEmpty.isEmpty)(val)) {
|
|
21
|
+
// null or '' or undefined
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if ((0, _isObject.isObject)(val)) {
|
|
26
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
|
27
|
+
var key = keys[i];
|
|
28
|
+
var v = val[key];
|
|
29
|
+
|
|
30
|
+
if (!(0, _isUndefined.isUndefined)(v)) {
|
|
31
|
+
return v;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return JSON.stringify(val);
|
|
37
|
+
}
|
package/lib/parsePath.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parsePath = parsePath;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.object.to-string.js");
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 根据路径解析值
|
|
14
|
+
*/
|
|
15
|
+
function parsePath(obj, path) {
|
|
16
|
+
path.split('.').forEach(function (key) {
|
|
17
|
+
var _obj$key;
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line no-param-reassign
|
|
20
|
+
obj = (_obj$key = obj[key]) !== null && _obj$key !== void 0 ? _obj$key : '';
|
|
21
|
+
});
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
package/lib/pick.d.ts
ADDED
package/lib/pick.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.pick = pick;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.object.to-string.js");
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 挑选对象里的某些属性,新对象返回
|
|
14
|
+
*/
|
|
15
|
+
function pick(obj) {
|
|
16
|
+
var fields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
17
|
+
var clone = {};
|
|
18
|
+
fields.forEach(function (key) {
|
|
19
|
+
clone[key] = obj[key];
|
|
20
|
+
});
|
|
21
|
+
return clone;
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.replaceCrlf = replaceCrlf;
|
|
7
|
+
|
|
8
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
9
|
+
|
|
10
|
+
require("core-js/modules/es.string.replace.js");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 替换字符串里面的回车换行
|
|
14
|
+
*/
|
|
15
|
+
function replaceCrlf(val, replaceVal) {
|
|
16
|
+
return val ? val.replace(/\\r|\\n/gi, replaceVal) : '';
|
|
17
|
+
}
|
package/lib/reserve.d.ts
ADDED
package/lib/reserve.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.reserve = reserve;
|
|
7
|
+
|
|
8
|
+
var _isEmpty = require("./isEmpty");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 值为 ''、undefined、null 则取默认值
|
|
12
|
+
* 解决:
|
|
13
|
+
* 0 || '--' => '--'
|
|
14
|
+
* reserve(0, '--') => 0
|
|
15
|
+
*/
|
|
16
|
+
function reserve(val, defaultVal) {
|
|
17
|
+
return (0, _isEmpty.isEmpty)(val) ? defaultVal : val;
|
|
18
|
+
}
|
|
@@ -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,75 @@
|
|
|
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.factory = factory;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
function factory(type) {
|
|
13
|
+
var fn = window[type]; // 设置
|
|
14
|
+
|
|
15
|
+
var _setItem = function setItem(key, val) {
|
|
16
|
+
fn.setItem(key, JSON.stringify(val));
|
|
17
|
+
return val;
|
|
18
|
+
}; // 获取
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var _getItem = function getItem(key) {
|
|
22
|
+
var defaultVal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
23
|
+
var val = fn.getItem(key); // 如果为 null 取默认值
|
|
24
|
+
|
|
25
|
+
if (val === null) {
|
|
26
|
+
return defaultVal;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return JSON.parse(val);
|
|
30
|
+
}; // 删除
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
var _removeItem = function removeItem(key) {
|
|
34
|
+
fn.removeItem(key);
|
|
35
|
+
}; // 更新
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
var _updateItem = function updateItem(key, val) {
|
|
39
|
+
var prev = _getItem(key);
|
|
40
|
+
|
|
41
|
+
return _setItem(key, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, prev), val));
|
|
42
|
+
}; // 清除
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
var clear = function clear() {
|
|
46
|
+
fn.clear();
|
|
47
|
+
}; // 生成
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
var generate = function generate(key) {
|
|
51
|
+
return {
|
|
52
|
+
setItem: function setItem(val) {
|
|
53
|
+
return _setItem(key, val);
|
|
54
|
+
},
|
|
55
|
+
getItem: function getItem(defaultVal) {
|
|
56
|
+
return _getItem(key, defaultVal);
|
|
57
|
+
},
|
|
58
|
+
removeItem: function removeItem() {
|
|
59
|
+
return _removeItem(key);
|
|
60
|
+
},
|
|
61
|
+
updateItem: function updateItem(val) {
|
|
62
|
+
return _updateItem(key, val);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
setItem: _setItem,
|
|
69
|
+
getItem: _getItem,
|
|
70
|
+
removeItem: _removeItem,
|
|
71
|
+
updateItem: _updateItem,
|
|
72
|
+
clear: clear,
|
|
73
|
+
generate: generate
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -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,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.local = exports.cache = void 0;
|
|
7
|
+
|
|
8
|
+
var _factory = require("./factory");
|
|
9
|
+
|
|
10
|
+
var cache = (0, _factory.factory)('sessionStorage');
|
|
11
|
+
exports.cache = cache;
|
|
12
|
+
var local = (0, _factory.factory)('localStorage');
|
|
13
|
+
exports.local = local;
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@daysnap/utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "通用的工具库",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"module": "es/index.js",
|
|
7
|
+
"typings": "lib/index.d.ts",
|
|
8
|
+
"browser": "dist/index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"docs": "typedoc --tsconfig ./tsconfig.json",
|
|
11
|
+
"rollup": "rollup -c",
|
|
12
|
+
"ts-node": "npx ts-node --project ./tsconfig.json ./src/filename.ts",
|
|
13
|
+
"gen": "plop --plopfile ./scripts/gen.js --force",
|
|
14
|
+
"del": "plop --plopfile ./scripts/del.js --force",
|
|
15
|
+
"entry": "plop --plopfile ./scripts/entry.js --force",
|
|
16
|
+
"build": "dsc build",
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"coverage": "jest --coverage",
|
|
19
|
+
"publish": "npm run build && dsc publish",
|
|
20
|
+
"husky": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' >> ~/.huskyrc",
|
|
21
|
+
"lint": "eslint 'src/**/*.{js,ts}' --fix",
|
|
22
|
+
"prepare": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' >> ~/.huskyrc"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/daysnap/utils.git"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"daysnap",
|
|
30
|
+
"utils",
|
|
31
|
+
"tool"
|
|
32
|
+
],
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"lib",
|
|
36
|
+
"es"
|
|
37
|
+
],
|
|
38
|
+
"author": "woshiajuana <979703986@qq.com>",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/daysnap/utils/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/daysnap/utils#readme",
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@babel/core": "^7.19.3",
|
|
46
|
+
"@babel/plugin-transform-runtime": "^7.19.1",
|
|
47
|
+
"@babel/preset-env": "^7.19.4",
|
|
48
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
49
|
+
"@commitlint/cli": "^16.2.1",
|
|
50
|
+
"@commitlint/config-conventional": "^16.2.1",
|
|
51
|
+
"@rollup/plugin-babel": "^6.0.0",
|
|
52
|
+
"@rollup/plugin-commonjs": "^23.0.0",
|
|
53
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
54
|
+
"@rollup/plugin-typescript": "^9.0.1",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
|
56
|
+
"@typescript-eslint/parser": "^5.40.0",
|
|
57
|
+
"commitizen": "^4.2.4",
|
|
58
|
+
"eslint": "^8.25.0",
|
|
59
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
60
|
+
"eslint-config-prettier": "^8.5.0",
|
|
61
|
+
"eslint-plugin-import": "^2.26.0",
|
|
62
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
63
|
+
"husky": "^7.0.4",
|
|
64
|
+
"lint-staged": "^13.0.3",
|
|
65
|
+
"node-dir": "^0.1.17",
|
|
66
|
+
"plop": "^3.1.1",
|
|
67
|
+
"prettier": "^2.7.1",
|
|
68
|
+
"rimraf": "^3.0.2",
|
|
69
|
+
"rollup": "^2.67.0",
|
|
70
|
+
"rollup-plugin-babel": "^4.4.0",
|
|
71
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
72
|
+
"ts-node": "^10.9.1",
|
|
73
|
+
"typedoc": "^0.23.17",
|
|
74
|
+
"typescript": "^4.8.4"
|
|
75
|
+
},
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public",
|
|
78
|
+
"registry": "https://registry.npmjs.org/"
|
|
79
|
+
},
|
|
80
|
+
"gitHooks": {
|
|
81
|
+
"pre-commit": "lint-staged"
|
|
82
|
+
},
|
|
83
|
+
"lint-staged": {
|
|
84
|
+
"*.{js,ts}": "eslint --fix"
|
|
85
|
+
},
|
|
86
|
+
"dependencies": {
|
|
87
|
+
"@babel/runtime": "^7.19.4",
|
|
88
|
+
"core-js": "^3.25.5"
|
|
89
|
+
},
|
|
90
|
+
"browserslist": [
|
|
91
|
+
"> 1%",
|
|
92
|
+
"last 2 versions"
|
|
93
|
+
]
|
|
94
|
+
}
|