@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.
- package/README.md +4 -0
- package/docs/.nojekyll +1 -0
- package/docs/README.md +18 -0
- package/docs/modules.md +1209 -0
- package/es/compareVersion.d.ts +6 -4
- package/es/compareVersion.js +14 -12
- package/es/inBrowser.d.ts +4 -0
- package/es/inBrowser.js +6 -0
- package/es/index.d.ts +9 -0
- package/es/index.js +10 -1
- package/es/isEmptyObject.d.ts +5 -0
- package/es/isEmptyObject.js +7 -0
- package/es/isError.d.ts +4 -0
- package/es/isError.js +6 -0
- package/es/isJSONString.d.ts +5 -0
- package/es/isJSONString.js +13 -0
- package/es/isLicenseCode.d.ts +5 -0
- package/es/isLicenseCode.js +7 -0
- package/es/isWindow.d.ts +5 -0
- package/es/isWindow.js +7 -0
- package/es/parseQuery.d.ts +6 -0
- package/es/parseQuery.js +33 -0
- package/es/sleep.d.ts +4 -0
- package/es/sleep.js +9 -0
- package/es/stringifyQuery.d.ts +4 -0
- package/es/stringifyQuery.js +13 -0
- package/lib/compareVersion.d.ts +6 -4
- package/lib/compareVersion.js +14 -12
- package/lib/inBrowser.d.ts +4 -0
- package/lib/inBrowser.js +12 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +99 -0
- package/lib/isEmptyObject.d.ts +5 -0
- package/lib/isEmptyObject.js +13 -0
- package/lib/isError.d.ts +4 -0
- package/lib/isError.js +12 -0
- package/lib/isJSONString.d.ts +5 -0
- package/lib/isJSONString.js +19 -0
- package/lib/isLicenseCode.d.ts +5 -0
- package/lib/isLicenseCode.js +13 -0
- package/lib/isWindow.d.ts +5 -0
- package/lib/isWindow.js +13 -0
- package/lib/parseQuery.d.ts +6 -0
- package/lib/parseQuery.js +40 -0
- package/lib/sleep.d.ts +4 -0
- package/lib/sleep.js +15 -0
- package/lib/stringifyQuery.d.ts +4 -0
- package/lib/stringifyQuery.js +19 -0
- package/package.json +9 -4
|
@@ -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
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,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.
|
|
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
|
-
"
|
|
16
|
-
"
|
|
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": {
|