@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.
Files changed (174) hide show
  1. package/README.md +24 -4
  2. package/docs/README.md +20 -4
  3. package/docs/modules.md +228 -93
  4. package/es/base64ToBlob.js +11 -17
  5. package/es/blobToBase64.js +10 -10
  6. package/es/canvasToBlob.js +4 -6
  7. package/es/clone.d.ts +4 -6
  8. package/es/clone.js +18 -8
  9. package/es/cloneSimple.d.ts +7 -0
  10. package/es/cloneSimple.js +9 -0
  11. package/es/compareVersion.js +27 -40
  12. package/es/compressImage.js +11 -13
  13. package/es/createHexColorByHash.js +59 -56
  14. package/es/debounce.d.ts +5 -0
  15. package/es/debounce.js +14 -0
  16. package/es/downloadFile.js +7 -7
  17. package/es/each.js +11 -10
  18. package/es/filterBankCardNo.js +4 -2
  19. package/es/filterCRLF.js +2 -2
  20. package/es/filterEmoji.js +13 -6
  21. package/es/filterIdCard.js +2 -2
  22. package/es/filterName.js +12 -12
  23. package/es/filterPhone.js +3 -4
  24. package/es/formatAmount.js +18 -20
  25. package/es/formatDate.js +28 -29
  26. package/es/getBlobByUrl.js +17 -18
  27. package/es/getDayMillisecond.js +3 -4
  28. package/es/getImageInfo.js +9 -9
  29. package/es/getRandomColor.js +2 -2
  30. package/es/getVideoInfo.js +11 -11
  31. package/es/inBrowser.js +2 -2
  32. package/es/index.d.ts +4 -0
  33. package/es/index.js +5 -1
  34. package/es/isAndroid.js +2 -2
  35. package/es/isArray.js +2 -2
  36. package/es/isBoolean.js +2 -2
  37. package/es/isEmail.js +2 -2
  38. package/es/isEmpty.js +2 -2
  39. package/es/isEmptyObject.js +2 -2
  40. package/es/isError.js +2 -2
  41. package/es/isFunction.js +2 -2
  42. package/es/isIOS.js +2 -2
  43. package/es/isIdCard.js +2 -2
  44. package/es/isJSONString.js +8 -7
  45. package/es/isLan.js +29 -28
  46. package/es/isLicenseCode.js +2 -2
  47. package/es/isMobile.js +7 -6
  48. package/es/isNull.js +2 -2
  49. package/es/isNumber.js +2 -2
  50. package/es/isObject.js +2 -2
  51. package/es/isPhone.js +2 -2
  52. package/es/isPromise.js +2 -2
  53. package/es/isRegExp.js +2 -2
  54. package/es/isString.js +2 -2
  55. package/es/isURL.d.ts +4 -0
  56. package/es/isURL.js +6 -0
  57. package/es/isUndefined.js +2 -2
  58. package/es/isWeixin.js +2 -2
  59. package/es/isWindow.js +2 -2
  60. package/es/loadResource.d.ts +1 -1
  61. package/es/loadResource.js +27 -23
  62. package/es/omit.js +7 -9
  63. package/es/padding.js +5 -5
  64. package/es/parseDate.js +7 -7
  65. package/es/parseError.js +15 -16
  66. package/es/parseObject.d.ts +2 -1
  67. package/es/parseObject.js +9 -8
  68. package/es/parsePath.js +7 -7
  69. package/es/parseQuery.d.ts +1 -1
  70. package/es/parseQuery.js +13 -24
  71. package/es/pick.js +7 -8
  72. package/es/replaceCrlf.js +2 -2
  73. package/es/reserve.js +2 -2
  74. package/es/round.js +38 -39
  75. package/es/sleep.d.ts +4 -2
  76. package/es/sleep.js +8 -7
  77. package/es/storage/factory.d.ts +2 -2
  78. package/es/storage/factory.js +44 -54
  79. package/es/storage/index.d.ts +4 -4
  80. package/es/storage/index.js +10 -10
  81. package/es/stringTrim.d.ts +3 -1
  82. package/es/stringTrim.js +17 -19
  83. package/es/stringifyQuery.d.ts +1 -1
  84. package/es/stringifyQuery.js +11 -8
  85. package/es/throttle.d.ts +5 -0
  86. package/es/throttle.js +17 -0
  87. package/es/typeOf.d.ts +1 -1
  88. package/es/typeOf.js +2 -2
  89. package/lib/base64ToBlob.js +14 -23
  90. package/lib/blobToBase64.js +13 -15
  91. package/lib/canvasToBlob.js +7 -11
  92. package/lib/clone.d.ts +4 -6
  93. package/lib/clone.js +21 -13
  94. package/lib/cloneSimple.d.ts +7 -0
  95. package/lib/cloneSimple.js +13 -0
  96. package/lib/compareVersion.js +30 -46
  97. package/lib/compressImage.js +15 -19
  98. package/lib/createHexColorByHash.js +60 -60
  99. package/lib/debounce.d.ts +5 -0
  100. package/lib/debounce.js +18 -0
  101. package/lib/downloadFile.js +10 -12
  102. package/lib/each.js +14 -15
  103. package/lib/filterBankCardNo.js +7 -7
  104. package/lib/filterCRLF.js +5 -7
  105. package/lib/filterEmoji.js +16 -11
  106. package/lib/filterIdCard.js +5 -7
  107. package/lib/filterName.js +15 -17
  108. package/lib/filterPhone.js +6 -9
  109. package/lib/formatAmount.js +21 -25
  110. package/lib/formatDate.js +32 -35
  111. package/lib/getBlobByUrl.js +20 -23
  112. package/lib/getDayMillisecond.js +6 -9
  113. package/lib/getImageInfo.js +12 -14
  114. package/lib/getRandomColor.js +5 -7
  115. package/lib/getVideoInfo.js +14 -16
  116. package/lib/inBrowser.js +5 -7
  117. package/lib/index.d.ts +4 -0
  118. package/lib/index.js +84 -708
  119. package/lib/isAndroid.js +5 -7
  120. package/lib/isArray.js +5 -7
  121. package/lib/isBoolean.js +5 -7
  122. package/lib/isEmail.js +5 -7
  123. package/lib/isEmpty.js +7 -9
  124. package/lib/isEmptyObject.js +5 -7
  125. package/lib/isError.js +5 -7
  126. package/lib/isFunction.js +5 -7
  127. package/lib/isIOS.js +5 -7
  128. package/lib/isIdCard.js +5 -7
  129. package/lib/isJSONString.js +12 -13
  130. package/lib/isLan.js +32 -33
  131. package/lib/isLicenseCode.js +5 -7
  132. package/lib/isMobile.js +10 -11
  133. package/lib/isNull.js +5 -7
  134. package/lib/isNumber.js +5 -7
  135. package/lib/isObject.js +5 -7
  136. package/lib/isPhone.js +5 -7
  137. package/lib/isPromise.js +5 -7
  138. package/lib/isRegExp.js +5 -7
  139. package/lib/isString.js +5 -7
  140. package/lib/isURL.d.ts +4 -0
  141. package/lib/isURL.js +10 -0
  142. package/lib/isUndefined.js +5 -7
  143. package/lib/isWeixin.js +5 -7
  144. package/lib/isWindow.js +5 -7
  145. package/lib/loadResource.d.ts +1 -1
  146. package/lib/loadResource.js +31 -29
  147. package/lib/omit.js +10 -15
  148. package/lib/padding.js +8 -10
  149. package/lib/parseDate.js +10 -12
  150. package/lib/parseError.js +21 -24
  151. package/lib/parseObject.d.ts +2 -1
  152. package/lib/parseObject.js +12 -13
  153. package/lib/parsePath.js +10 -12
  154. package/lib/parseQuery.d.ts +1 -1
  155. package/lib/parseQuery.js +17 -31
  156. package/lib/pick.js +10 -13
  157. package/lib/replaceCrlf.js +5 -7
  158. package/lib/reserve.js +6 -8
  159. package/lib/round.js +41 -44
  160. package/lib/sleep.d.ts +4 -2
  161. package/lib/sleep.js +11 -12
  162. package/lib/storage/factory.d.ts +2 -2
  163. package/lib/storage/factory.js +47 -60
  164. package/lib/storage/index.d.ts +4 -4
  165. package/lib/storage/index.js +12 -17
  166. package/lib/stringTrim.d.ts +3 -1
  167. package/lib/stringTrim.js +20 -24
  168. package/lib/stringifyQuery.d.ts +1 -1
  169. package/lib/stringifyQuery.js +15 -14
  170. package/lib/throttle.d.ts +5 -0
  171. package/lib/throttle.js +21 -0
  172. package/lib/typeOf.d.ts +1 -1
  173. package/lib/typeOf.js +5 -7
  174. package/package.json +23 -18
@@ -1,20 +1,15 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getLocal = exports.getCache = void 0;
7
- var _factory = require("./factory");
8
- var getStorage = function getStorage(type) {
9
- var instance = null;
10
- return function () {
11
- if (!instance) {
12
- instance = (0, _factory.factory)(type);
13
- }
14
- return instance;
15
- };
4
+ const factory_1 = require("./factory");
5
+ const getStorage = (type) => {
6
+ let instance = null;
7
+ return () => {
8
+ if (!instance) {
9
+ instance = (0, factory_1.factory)(type);
10
+ }
11
+ return instance;
12
+ };
16
13
  };
17
- var getCache = getStorage('sessionStorage');
18
- exports.getCache = getCache;
19
- var getLocal = getStorage('localStorage');
20
- exports.getLocal = getLocal;
14
+ exports.getCache = getStorage('sessionStorage');
15
+ exports.getLocal = getStorage('localStorage');
@@ -1,4 +1,6 @@
1
1
  /**
2
- *去除字符串空格
2
+ * 去除字符串空格
3
+ * @param str 字符串值
4
+ * @param type 方式 1-所有空格,2-前后空格,3-前空格,4-后空格
3
5
  */
4
6
  export declare function stringTrim(str: string, type?: 1 | 2 | 3 | 4): string;
package/lib/stringTrim.js CHANGED
@@ -1,27 +1,23 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.stringTrim = stringTrim;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringTrim = void 0;
7
4
  /**
8
- *去除字符串空格
5
+ * 去除字符串空格
6
+ * @param str 字符串值
7
+ * @param type 方式 1-所有空格,2-前后空格,3-前空格,4-后空格
9
8
  */
10
- function stringTrim(str, type) {
11
- var _type;
12
- // 1-所有空格,2-前后空格,3-前空格,4-后空格
13
- // eslint-disable-next-line no-param-reassign
14
- type = (_type = type) !== null && _type !== void 0 ? _type : 1;
15
- switch (type) {
16
- case 1:
17
- return str.replace(/\s+/g, '');
18
- case 2:
19
- return str.replace(/(^\s*)|(\s*$)/g, '');
20
- case 3:
21
- return str.replace(/(^\s*)/g, '');
22
- case 4:
23
- return str.replace(/(\s*$)/g, '');
24
- default:
25
- return str;
26
- }
27
- }
9
+ function stringTrim(str, type = 1) {
10
+ switch (type) {
11
+ case 1:
12
+ return str.replace(/\s+/g, '');
13
+ case 2:
14
+ return str.replace(/(^\s*)|(\s*$)/g, '');
15
+ case 3:
16
+ return str.replace(/(^\s*)/g, '');
17
+ case 4:
18
+ return str.replace(/(\s*$)/g, '');
19
+ default:
20
+ return str;
21
+ }
22
+ }
23
+ exports.stringTrim = stringTrim;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * 说明
3
3
  */
4
- export declare function stringifyQuery(v: object): string;
4
+ export declare function stringifyQuery(v: Record<string, any>): string;
@@ -1,19 +1,20 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.stringifyQuery = stringifyQuery;
7
- var _isEmptyObject = require("./isEmptyObject");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringifyQuery = void 0;
4
+ const isEmptyObject_1 = require("./isEmptyObject");
5
+ const isString_1 = require("./isString");
8
6
  /**
9
7
  * 说明
10
8
  */
11
9
  function stringifyQuery(v) {
12
- if ((0, _isEmptyObject.isEmptyObject)(v)) return '';
13
- var query = new URLSearchParams();
14
- Object.keys(v).forEach(function (key) {
15
- var value = typeof v[key] === 'string' ? v[key] : JSON.stringify(v[key]);
16
- query.append(key, value);
17
- });
18
- return query.toString();
19
- }
10
+ if ((0, isEmptyObject_1.isEmptyObject)(v)) {
11
+ return '';
12
+ }
13
+ const query = new URLSearchParams();
14
+ Object.keys(v).forEach((key) => {
15
+ const value = (0, isString_1.isString)(v[key]) ? v[key] : JSON.stringify(v[key]);
16
+ query.append(key, value);
17
+ });
18
+ return query.toString();
19
+ }
20
+ exports.stringifyQuery = stringifyQuery;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 节流函数
3
+ * 减少事件执行次数,有规律的执行
4
+ */
5
+ export declare function throttle<T extends (...args: []) => any>(fn: T, ms: number): (this: unknown, ...args: Parameters<T>) => void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throttle = void 0;
4
+ /**
5
+ * 节流函数
6
+ * 减少事件执行次数,有规律的执行
7
+ */
8
+ function throttle(fn, ms) {
9
+ let timer = null;
10
+ // eslint-disable-next-line func-names
11
+ return function (...args) {
12
+ if (timer) {
13
+ return;
14
+ }
15
+ timer = setTimeout(() => {
16
+ fn.apply(this, args);
17
+ timer = null;
18
+ }, ms);
19
+ };
20
+ }
21
+ exports.throttle = throttle;
package/lib/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<T>(val: T): val is T;
6
+ export declare function typeOf(val: unknown): string;
package/lib/typeOf.js CHANGED
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.typeOf = typeOf;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.typeOf = void 0;
7
4
  /**
8
5
  * 判断类型
9
6
  * @param val 待判断数据
10
7
  * @returns 'undefined'|'null'|'boolean'|'string'|'number'|'object'|'array'|'function'|'symbol'|'map'|'weakmap'|'bigint'|'regexp'|'date'
11
8
  */
12
9
  function typeOf(val) {
13
- return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
14
- }
10
+ return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
11
+ }
12
+ exports.typeOf = typeOf;
package/package.json CHANGED
@@ -1,23 +1,34 @@
1
1
  {
2
2
  "name": "@daysnap/utils",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "通用的工具库",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
7
- "typings": "lib/index.d.ts",
7
+ "types": "es/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./es/index.js",
11
+ "require": "./lib/index.js"
12
+ },
13
+ "./*": "./*"
14
+ },
8
15
  "scripts": {
9
16
  "gen": "plop --plopfile ./scripts/gen.js --force",
10
17
  "del": "plop --plopfile ./scripts/del.js --force",
11
18
  "entry": "plop --plopfile ./scripts/entry.js --force",
12
19
  "docs": "typedoc --plugin typedoc-plugin-markdown --out docs src/index.ts",
13
- "build": "dsc build",
20
+ "clean:es": "rimraf ./es",
21
+ "clean:lib": "rimraf ./lib",
22
+ "clean": "npm run clean:es && npm run clean:lib",
23
+ "build:es": "npm run clean:es && tsc -p ./tsconfig-esm.json",
24
+ "build:lib": "npm run clean:lib && tsc -p ./tsconfig.json",
25
+ "build": "npm run build:es && npm run build:lib",
14
26
  "test": "jest",
15
27
  "coverage": "jest --coverage",
16
28
  "prerelease": "npm run entry && npm run test && npm run docs",
17
29
  "release": "npm run build && dsc publish -t",
18
- "husky": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' >> ~/.huskyrc",
19
30
  "lint": "eslint 'src/**/*.{js,ts}' --fix",
20
- "prepare": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' >> ~/.huskyrc"
31
+ "prepare": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' > ~/.huskyrc"
21
32
  },
22
33
  "repository": {
23
34
  "type": "git",
@@ -43,24 +54,21 @@
43
54
  "devDependencies": {
44
55
  "@commitlint/cli": "^16.2.1",
45
56
  "@commitlint/config-conventional": "^16.2.1",
46
- "@types/jest": "^29.2.3",
47
- "@typescript-eslint/eslint-plugin": "^5.40.0",
48
- "@typescript-eslint/parser": "^5.40.0",
57
+ "@types/jest": "^27.5.2",
58
+ "@typescript-eslint/eslint-plugin": "^5.55.0",
59
+ "@typescript-eslint/parser": "^5.55.0",
49
60
  "commitizen": "^4.2.4",
50
- "eslint": "^8.25.0",
51
- "eslint-config-airbnb-base": "^15.0.0",
52
- "eslint-config-prettier": "^8.5.0",
53
- "eslint-plugin-import": "^2.26.0",
61
+ "eslint": "^8.36.0",
62
+ "eslint-config-prettier": "^8.7.0",
54
63
  "eslint-plugin-prettier": "^4.2.1",
55
64
  "husky": "^7.0.4",
56
65
  "jest": "^27.5.1",
57
66
  "lint-staged": "^13.0.3",
58
67
  "node-dir": "^0.1.17",
59
68
  "plop": "^3.1.1",
60
- "prettier": "^2.7.1",
69
+ "prettier": "^2.8.4",
61
70
  "rimraf": "^3.0.2",
62
- "ts-jest": "^27.1.4",
63
- "ts-node": "^10.9.1",
71
+ "ts-jest": "^27.1.5",
64
72
  "typedoc": "^0.23.21",
65
73
  "typedoc-plugin-markdown": "^3.14.0",
66
74
  "typescript": "^4.8.4"
@@ -74,8 +82,5 @@
74
82
  },
75
83
  "lint-staged": {
76
84
  "*.{js,ts}": "eslint --fix"
77
- },
78
- "dependencies": {
79
- "@babel/runtime": "^7.19.4"
80
85
  }
81
86
  }