@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.
Files changed (199) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -0
  3. package/dist/base64ToBlob.d.ts +4 -0
  4. package/dist/blobToBase64.d.ts +4 -0
  5. package/dist/compareVersion.d.ts +7 -0
  6. package/dist/compressImage.d.ts +4 -0
  7. package/dist/createHexColorByHash.d.ts +4 -0
  8. package/dist/downloadFile.d.ts +6 -0
  9. package/dist/filterBankCardNo.d.ts +4 -0
  10. package/dist/filterEmoji.d.ts +4 -0
  11. package/dist/filterIdCard.d.ts +4 -0
  12. package/dist/filterName.d.ts +4 -0
  13. package/dist/filterPhone.d.ts +6 -0
  14. package/dist/formatAmount.d.ts +4 -0
  15. package/dist/formatDate.d.ts +4 -0
  16. package/dist/getBlobByUrl.d.ts +4 -0
  17. package/dist/getImageInfo.d.ts +4 -0
  18. package/dist/getVideoInfo.d.ts +4 -0
  19. package/dist/index.d.ts +38 -0
  20. package/dist/index.js +604 -0
  21. package/dist/isAndroid.d.ts +4 -0
  22. package/dist/isEmail.d.ts +4 -0
  23. package/dist/isEmpty.d.ts +4 -0
  24. package/dist/isFunction.d.ts +4 -0
  25. package/dist/isIOS.d.ts +4 -0
  26. package/dist/isIdCard.d.ts +4 -0
  27. package/dist/isMobile.d.ts +4 -0
  28. package/dist/isNull.d.ts +4 -0
  29. package/dist/isObject.d.ts +4 -0
  30. package/dist/isPhone.d.ts +4 -0
  31. package/dist/isPromise.d.ts +4 -0
  32. package/dist/isRegExp.d.ts +4 -0
  33. package/dist/isString.d.ts +4 -0
  34. package/dist/isUndefined.d.ts +4 -0
  35. package/dist/omit.d.ts +4 -0
  36. package/dist/parseError.d.ts +4 -0
  37. package/dist/parsePath.d.ts +4 -0
  38. package/dist/pick.d.ts +4 -0
  39. package/dist/replaceCrlf.d.ts +4 -0
  40. package/dist/reserve.d.ts +7 -0
  41. package/dist/storage/factory.d.ts +13 -0
  42. package/dist/storage/index.d.ts +26 -0
  43. package/es/base64ToBlob.d.ts +4 -0
  44. package/es/base64ToBlob.js +55 -0
  45. package/es/blobToBase64.d.ts +4 -0
  46. package/es/blobToBase64.js +20 -0
  47. package/es/compareVersion.d.ts +7 -0
  48. package/es/compareVersion.js +58 -0
  49. package/es/compressImage.d.ts +4 -0
  50. package/es/compressImage.js +20 -0
  51. package/es/createHexColorByHash.d.ts +4 -0
  52. package/es/createHexColorByHash.js +72 -0
  53. package/es/downloadFile.d.ts +6 -0
  54. package/es/downloadFile.js +20 -0
  55. package/es/filterBankCardNo.d.ts +4 -0
  56. package/es/filterBankCardNo.js +11 -0
  57. package/es/filterEmoji.d.ts +4 -0
  58. package/es/filterEmoji.js +17 -0
  59. package/es/filterIdCard.d.ts +4 -0
  60. package/es/filterIdCard.js +8 -0
  61. package/es/filterName.d.ts +4 -0
  62. package/es/filterName.js +23 -0
  63. package/es/filterPhone.d.ts +6 -0
  64. package/es/filterPhone.js +11 -0
  65. package/es/formatAmount.d.ts +4 -0
  66. package/es/formatAmount.js +31 -0
  67. package/es/formatDate.d.ts +4 -0
  68. package/es/formatDate.js +44 -0
  69. package/es/getBlobByUrl.d.ts +4 -0
  70. package/es/getBlobByUrl.js +27 -0
  71. package/es/getImageInfo.d.ts +4 -0
  72. package/es/getImageInfo.js +18 -0
  73. package/es/getVideoInfo.d.ts +4 -0
  74. package/es/getVideoInfo.js +20 -0
  75. package/es/index.d.ts +38 -0
  76. package/es/index.js +39 -0
  77. package/es/isAndroid.d.ts +4 -0
  78. package/es/isAndroid.js +8 -0
  79. package/es/isEmail.d.ts +4 -0
  80. package/es/isEmail.js +8 -0
  81. package/es/isEmpty.d.ts +4 -0
  82. package/es/isEmpty.js +9 -0
  83. package/es/isFunction.d.ts +4 -0
  84. package/es/isFunction.js +6 -0
  85. package/es/isIOS.d.ts +4 -0
  86. package/es/isIOS.js +8 -0
  87. package/es/isIdCard.d.ts +4 -0
  88. package/es/isIdCard.js +8 -0
  89. package/es/isMobile.d.ts +4 -0
  90. package/es/isMobile.js +13 -0
  91. package/es/isNull.d.ts +4 -0
  92. package/es/isNull.js +6 -0
  93. package/es/isObject.d.ts +4 -0
  94. package/es/isObject.js +8 -0
  95. package/es/isPhone.d.ts +4 -0
  96. package/es/isPhone.js +8 -0
  97. package/es/isPromise.d.ts +4 -0
  98. package/es/isPromise.js +9 -0
  99. package/es/isRegExp.d.ts +4 -0
  100. package/es/isRegExp.js +10 -0
  101. package/es/isString.d.ts +4 -0
  102. package/es/isString.js +6 -0
  103. package/es/isUndefined.d.ts +4 -0
  104. package/es/isUndefined.js +6 -0
  105. package/es/omit.d.ts +4 -0
  106. package/es/omit.js +17 -0
  107. package/es/parseError.d.ts +4 -0
  108. package/es/parseError.js +28 -0
  109. package/es/parsePath.d.ts +4 -0
  110. package/es/parsePath.js +15 -0
  111. package/es/pick.d.ts +4 -0
  112. package/es/pick.js +14 -0
  113. package/es/replaceCrlf.d.ts +4 -0
  114. package/es/replaceCrlf.js +9 -0
  115. package/es/reserve.d.ts +7 -0
  116. package/es/reserve.js +11 -0
  117. package/es/storage/factory.d.ts +13 -0
  118. package/es/storage/factory.js +65 -0
  119. package/es/storage/index.d.ts +26 -0
  120. package/es/storage/index.js +3 -0
  121. package/lib/base64ToBlob.d.ts +4 -0
  122. package/lib/base64ToBlob.js +93 -0
  123. package/lib/blobToBase64.d.ts +4 -0
  124. package/lib/blobToBase64.js +28 -0
  125. package/lib/compareVersion.d.ts +7 -0
  126. package/lib/compareVersion.js +68 -0
  127. package/lib/compressImage.d.ts +4 -0
  128. package/lib/compressImage.js +27 -0
  129. package/lib/createHexColorByHash.d.ts +4 -0
  130. package/lib/createHexColorByHash.js +84 -0
  131. package/lib/downloadFile.d.ts +6 -0
  132. package/lib/downloadFile.js +32 -0
  133. package/lib/filterBankCardNo.d.ts +4 -0
  134. package/lib/filterBankCardNo.js +21 -0
  135. package/lib/filterEmoji.d.ts +4 -0
  136. package/lib/filterEmoji.js +28 -0
  137. package/lib/filterIdCard.d.ts +4 -0
  138. package/lib/filterIdCard.js +15 -0
  139. package/lib/filterName.d.ts +4 -0
  140. package/lib/filterName.js +31 -0
  141. package/lib/filterPhone.d.ts +6 -0
  142. package/lib/filterPhone.js +18 -0
  143. package/lib/formatAmount.d.ts +4 -0
  144. package/lib/formatAmount.js +42 -0
  145. package/lib/formatDate.d.ts +4 -0
  146. package/lib/formatDate.js +55 -0
  147. package/lib/getBlobByUrl.d.ts +4 -0
  148. package/lib/getBlobByUrl.js +36 -0
  149. package/lib/getImageInfo.d.ts +4 -0
  150. package/lib/getImageInfo.js +26 -0
  151. package/lib/getVideoInfo.d.ts +4 -0
  152. package/lib/getVideoInfo.js +28 -0
  153. package/lib/index.d.ts +38 -0
  154. package/lib/index.js +537 -0
  155. package/lib/isAndroid.d.ts +4 -0
  156. package/lib/isAndroid.js +15 -0
  157. package/lib/isEmail.d.ts +4 -0
  158. package/lib/isEmail.js +15 -0
  159. package/lib/isEmpty.d.ts +4 -0
  160. package/lib/isEmpty.js +17 -0
  161. package/lib/isFunction.d.ts +4 -0
  162. package/lib/isFunction.js +13 -0
  163. package/lib/isIOS.d.ts +4 -0
  164. package/lib/isIOS.js +15 -0
  165. package/lib/isIdCard.d.ts +4 -0
  166. package/lib/isIdCard.js +15 -0
  167. package/lib/isMobile.d.ts +4 -0
  168. package/lib/isMobile.js +20 -0
  169. package/lib/isNull.d.ts +4 -0
  170. package/lib/isNull.js +13 -0
  171. package/lib/isObject.d.ts +4 -0
  172. package/lib/isObject.js +15 -0
  173. package/lib/isPhone.d.ts +4 -0
  174. package/lib/isPhone.js +15 -0
  175. package/lib/isPromise.d.ts +4 -0
  176. package/lib/isPromise.js +17 -0
  177. package/lib/isRegExp.d.ts +4 -0
  178. package/lib/isRegExp.js +19 -0
  179. package/lib/isString.d.ts +4 -0
  180. package/lib/isString.js +13 -0
  181. package/lib/isUndefined.d.ts +4 -0
  182. package/lib/isUndefined.js +13 -0
  183. package/lib/omit.d.ts +4 -0
  184. package/lib/omit.js +26 -0
  185. package/lib/parseError.d.ts +4 -0
  186. package/lib/parseError.js +37 -0
  187. package/lib/parsePath.d.ts +4 -0
  188. package/lib/parsePath.js +23 -0
  189. package/lib/pick.d.ts +4 -0
  190. package/lib/pick.js +22 -0
  191. package/lib/replaceCrlf.d.ts +4 -0
  192. package/lib/replaceCrlf.js +17 -0
  193. package/lib/reserve.d.ts +7 -0
  194. package/lib/reserve.js +18 -0
  195. package/lib/storage/factory.d.ts +13 -0
  196. package/lib/storage/factory.js +75 -0
  197. package/lib/storage/index.d.ts +26 -0
  198. package/lib/storage/index.js +13 -0
  199. package/package.json +94 -0
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 校验设备是否是手机
3
+ */
4
+ export declare function isMobile(): boolean;
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 校验是否是 null
3
+ */
4
+ export declare function isNull(val: unknown): val is null;
package/lib/isNull.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isNull = isNull;
7
+
8
+ /**
9
+ * 校验是否是 null
10
+ */
11
+ function isNull(val) {
12
+ return val === null;
13
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 校验是否是对象
3
+ */
4
+ export declare function isObject(val: unknown): val is Record<string, any>;
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 校验是否是手机号码
3
+ */
4
+ export declare function isPhone(val: string): boolean;
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
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 校验是否是 promise
3
+ */
4
+ export declare function isPromise<T = any>(val: unknown): val is Promise<T>;
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 校验是否是正则表达式
3
+ */
4
+ export declare function isRegExp(val: unknown): val is RegExp;
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 校验是否是字符串
3
+ */
4
+ export declare function isString(val: unknown): val is string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isString = isString;
7
+
8
+ /**
9
+ * 校验是否是字符串
10
+ */
11
+ function isString(val) {
12
+ return typeof val === 'string';
13
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 校验是否是 undefined
3
+ */
4
+ export declare function isUndefined(val: unknown): val is undefined;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isUndefined = isUndefined;
7
+
8
+ /**
9
+ * 校验是否是 undefined
10
+ */
11
+ function isUndefined(val) {
12
+ return typeof val === 'undefined';
13
+ }
package/lib/omit.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 排除对象里的某些属性,返回剩下的对象,浅拷贝
3
+ */
4
+ export declare function omit<T extends object, K extends keyof T>(obj: T, fields?: K[]): Omit<T, K>;
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,4 @@
1
+ /**
2
+ * 解析格式化 error 获取对应的 message
3
+ */
4
+ export declare function parseError(val: any, keys?: string[]): string;
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 根据路径解析值
3
+ */
4
+ export declare function parsePath(obj: Record<string, any>, path: string): Record<string, any>;
@@ -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
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 挑选对象里的某些属性,新对象返回
3
+ */
4
+ export declare function pick<T extends object, K extends keyof T>(obj: T, fields?: K[]): Pick<T, K>;
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,4 @@
1
+ /**
2
+ * 替换字符串里面的回车换行
3
+ */
4
+ export declare function replaceCrlf(val: string, replaceVal: string): string;
@@ -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
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 值为 ''、undefined、null 则取默认值
3
+ * 解决:
4
+ * 0 || '--' => '--'
5
+ * reserve(0, '--') => 0
6
+ */
7
+ export declare function reserve(val: any, defaultVal?: any): any;
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
+ }