@daysnap/utils 0.0.29 → 0.0.31

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 (49) hide show
  1. package/README.md +4 -0
  2. package/docs/.nojekyll +1 -0
  3. package/docs/README.md +18 -0
  4. package/docs/modules.md +1209 -0
  5. package/es/compareVersion.d.ts +6 -4
  6. package/es/compareVersion.js +14 -12
  7. package/es/inBrowser.d.ts +4 -0
  8. package/es/inBrowser.js +6 -0
  9. package/es/index.d.ts +9 -0
  10. package/es/index.js +10 -1
  11. package/es/isEmptyObject.d.ts +5 -0
  12. package/es/isEmptyObject.js +7 -0
  13. package/es/isError.d.ts +4 -0
  14. package/es/isError.js +6 -0
  15. package/es/isJSONString.d.ts +5 -0
  16. package/es/isJSONString.js +13 -0
  17. package/es/isLicenseCode.d.ts +5 -0
  18. package/es/isLicenseCode.js +7 -0
  19. package/es/isWindow.d.ts +5 -0
  20. package/es/isWindow.js +7 -0
  21. package/es/parseQuery.d.ts +6 -0
  22. package/es/parseQuery.js +33 -0
  23. package/es/sleep.d.ts +4 -0
  24. package/es/sleep.js +9 -0
  25. package/es/stringifyQuery.d.ts +4 -0
  26. package/es/stringifyQuery.js +13 -0
  27. package/lib/compareVersion.d.ts +6 -4
  28. package/lib/compareVersion.js +14 -12
  29. package/lib/inBrowser.d.ts +4 -0
  30. package/lib/inBrowser.js +12 -0
  31. package/lib/index.d.ts +9 -0
  32. package/lib/index.js +99 -0
  33. package/lib/isEmptyObject.d.ts +5 -0
  34. package/lib/isEmptyObject.js +13 -0
  35. package/lib/isError.d.ts +4 -0
  36. package/lib/isError.js +12 -0
  37. package/lib/isJSONString.d.ts +5 -0
  38. package/lib/isJSONString.js +19 -0
  39. package/lib/isLicenseCode.d.ts +5 -0
  40. package/lib/isLicenseCode.js +13 -0
  41. package/lib/isWindow.d.ts +5 -0
  42. package/lib/isWindow.js +13 -0
  43. package/lib/parseQuery.d.ts +6 -0
  44. package/lib/parseQuery.js +40 -0
  45. package/lib/sleep.d.ts +4 -0
  46. package/lib/sleep.js +15 -0
  47. package/lib/stringifyQuery.d.ts +4 -0
  48. package/lib/stringifyQuery.js +19 -0
  49. package/package.json +9 -4
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 解析url参数
3
+ * @param v URl
4
+ * @param k 键名
5
+ */
6
+ export declare function parseQuery(v?: string, k?: string): {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.parseQuery = parseQuery;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
10
+ var _isJSONString = require("./isJSONString");
11
+ /**
12
+ * 解析url参数
13
+ * @param v URl
14
+ * @param k 键名
15
+ */
16
+ function parseQuery(v, k) {
17
+ var url = new URL(v);
18
+ var searchStr = v ? url.search : window.location.search;
19
+ var query = new URLSearchParams(decodeURIComponent(searchStr));
20
+ // 单个直接返回
21
+ if (k) return query.get(k);
22
+ var res = {};
23
+ // eslint-disable-next-line no-restricted-syntax
24
+ var _iterator = (0, _createForOfIteratorHelper2["default"])(query.entries()),
25
+ _step;
26
+ try {
27
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
28
+ var _step$value = (0, _slicedToArray2["default"])(_step.value, 2),
29
+ key = _step$value[0],
30
+ value = _step$value[1];
31
+ console.log(key, value);
32
+ res[key] = (0, _isJSONString.isJSONString)(value) ? JSON.parse(value) : value;
33
+ }
34
+ } catch (err) {
35
+ _iterator.e(err);
36
+ } finally {
37
+ _iterator.f();
38
+ }
39
+ return res;
40
+ }
package/lib/sleep.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 说明
3
+ */
4
+ export declare function sleep(timeout: number, isSuccess?: boolean): Promise<void>;
package/lib/sleep.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sleep = sleep;
7
+ /**
8
+ * 说明
9
+ */
10
+ function sleep(timeout) {
11
+ var isSuccess = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
12
+ return new Promise(function (resolve, reject) {
13
+ setTimeout(isSuccess ? resolve : reject, timeout);
14
+ });
15
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 说明
3
+ */
4
+ export declare function stringifyQuery(v: object): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.stringifyQuery = stringifyQuery;
7
+ var _isEmptyObject = require("./isEmptyObject");
8
+ /**
9
+ * 说明
10
+ */
11
+ 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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daysnap/utils",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "description": "通用的工具库",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -9,11 +9,12 @@
9
9
  "gen": "plop --plopfile ./scripts/gen.js --force",
10
10
  "del": "plop --plopfile ./scripts/del.js --force",
11
11
  "entry": "plop --plopfile ./scripts/entry.js --force",
12
+ "docs": "typedoc --plugin typedoc-plugin-markdown --out docs src/index.ts",
12
13
  "build": "dsc build",
13
14
  "test": "jest",
14
15
  "coverage": "jest --coverage",
15
- "predeploy": "npm run entry && npm run test",
16
- "deploy": "npm run build && dsc publish",
16
+ "prerelease": "npm run entry && npm run test && npm run docs",
17
+ "release": "npm run build && dsc publish -t",
17
18
  "husky": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' >> ~/.huskyrc",
18
19
  "lint": "eslint 'src/**/*.{js,ts}' --fix",
19
20
  "prepare": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' >> ~/.huskyrc"
@@ -29,9 +30,11 @@
29
30
  ],
30
31
  "files": [
31
32
  "lib",
32
- "es"
33
+ "es",
34
+ "docs"
33
35
  ],
34
36
  "author": "woshiajuana <979703986@qq.com>",
37
+ "sideEffects": false,
35
38
  "license": "MIT",
36
39
  "bugs": {
37
40
  "url": "https://github.com/daysnap/utils/issues"
@@ -58,6 +61,8 @@
58
61
  "rimraf": "^3.0.2",
59
62
  "ts-jest": "^27.1.4",
60
63
  "ts-node": "^10.9.1",
64
+ "typedoc": "^0.23.21",
65
+ "typedoc-plugin-markdown": "^3.14.0",
61
66
  "typescript": "^4.8.4"
62
67
  },
63
68
  "publishConfig": {