@ywfe/fe-tools 1.2.1-beta.3 → 1.2.1-beta.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/JSON2String.ts +17 -0
- package/index.ts +1 -0
- package/lib/JSON2String.d.ts +9 -0
- package/lib/index.d.ts +1 -0
- package/lib/userInputToJson.d.ts +1 -1
- package/lib/ywfe-tools.cjs +53 -25
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +53 -26
- package/lib/ywfe-tools.esm.js.map +1 -1
- package/lib/ywfe-tools.umd.js +4 -0
- package/lib/ywfe-tools.umd.js.map +1 -0
- package/package.json +1 -2
- package/request.ts +35 -36
- package/rollup.config.js +1 -4
- package/userInputToJson.ts +19 -12
package/JSON2String.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface Input {
|
|
2
|
+
data: object;
|
|
3
|
+
}
|
|
4
|
+
// Ctrl-S保存代码
|
|
5
|
+
function JSON2String({input}: { input: Input }){
|
|
6
|
+
const { data } = input;
|
|
7
|
+
const result:{content: string} = {content:''};
|
|
8
|
+
try {
|
|
9
|
+
const str = JSON.stringify(data);
|
|
10
|
+
result.content = '```json' + str + 'json```';
|
|
11
|
+
return result;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
result.content = '```json' + '{}' + 'json```';
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export default JSON2String
|
package/index.ts
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/userInputToJson.d.ts
CHANGED
package/lib/ywfe-tools.cjs
CHANGED
|
@@ -8706,50 +8706,53 @@ var require$$1 = /*@__PURE__*/getAugmentedNamespace(empty$1);
|
|
|
8706
8706
|
|
|
8707
8707
|
function request(_a) {
|
|
8708
8708
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
8709
|
-
var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption,
|
|
8709
|
+
var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, response, message, result;
|
|
8710
8710
|
var input = _b.input;
|
|
8711
8711
|
return __generator(this, function (_c) {
|
|
8712
8712
|
switch (_c.label) {
|
|
8713
8713
|
case 0:
|
|
8714
|
-
method = input.method ||
|
|
8714
|
+
method = input.method || "GET";
|
|
8715
8715
|
basePathMap = new Map([
|
|
8716
|
-
[
|
|
8717
|
-
[
|
|
8718
|
-
[
|
|
8719
|
-
[
|
|
8716
|
+
["prod", "https://gateway.ywwl.com"],
|
|
8717
|
+
["test", "https://test-gateway.ywwl.com"],
|
|
8718
|
+
["test2", "https://test2-gateway.ywwl.com"],
|
|
8719
|
+
["dev", "https://dev-gateway.ywwl.com"],
|
|
8720
8720
|
]);
|
|
8721
8721
|
getBasePath = function () {
|
|
8722
|
-
var env =
|
|
8722
|
+
var env = "{{env}}";
|
|
8723
8723
|
return basePathMap.get(env);
|
|
8724
8724
|
};
|
|
8725
8725
|
isValidURL = function (url) {
|
|
8726
|
-
var
|
|
8727
|
-
|
|
8728
|
-
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
|
8729
|
-
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
|
8730
|
-
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
|
8731
|
-
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
|
|
8732
|
-
return !!pattern.test(url);
|
|
8726
|
+
var regex = /^https?:\/\//;
|
|
8727
|
+
return regex.test(url);
|
|
8733
8728
|
};
|
|
8734
8729
|
prefix = getBasePath();
|
|
8735
8730
|
requestUrl = isValidURL(input.url) ? input.url : "".concat(prefix).concat(input.url);
|
|
8731
|
+
console.log('requestUrl', requestUrl, isValidURL(input.url));
|
|
8736
8732
|
fetchOption = {
|
|
8737
8733
|
method: method,
|
|
8738
8734
|
headers: {
|
|
8739
|
-
|
|
8740
|
-
|
|
8735
|
+
"Content-type": "application/json",
|
|
8736
|
+
"x-token": "{{token}}",
|
|
8741
8737
|
},
|
|
8742
8738
|
};
|
|
8743
|
-
if (method.toUpperCase() ===
|
|
8739
|
+
if (method.toUpperCase() === "POST") {
|
|
8744
8740
|
fetchOption.body = JSON.stringify(input.params);
|
|
8745
8741
|
}
|
|
8746
|
-
else if (method.toUpperCase() ===
|
|
8742
|
+
else if (method.toUpperCase() === "GET") {
|
|
8747
8743
|
requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
|
|
8748
8744
|
}
|
|
8749
8745
|
return [4 /*yield*/, fetch(requestUrl, fetchOption)];
|
|
8750
8746
|
case 1:
|
|
8751
|
-
|
|
8752
|
-
|
|
8747
|
+
response = _c.sent();
|
|
8748
|
+
if (!response.ok) {
|
|
8749
|
+
message = "An error has occured: ".concat(response.status);
|
|
8750
|
+
return [2 /*return*/, { success: false, message: message }];
|
|
8751
|
+
}
|
|
8752
|
+
return [4 /*yield*/, response.json()];
|
|
8753
|
+
case 2:
|
|
8754
|
+
result = _c.sent();
|
|
8755
|
+
return [2 /*return*/, result];
|
|
8753
8756
|
}
|
|
8754
8757
|
});
|
|
8755
8758
|
});
|
|
@@ -8757,25 +8760,50 @@ function request(_a) {
|
|
|
8757
8760
|
|
|
8758
8761
|
function userInputToJson(_a) {
|
|
8759
8762
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
8763
|
+
var res, result;
|
|
8760
8764
|
var input = _b.input;
|
|
8761
8765
|
return __generator(this, function (_c) {
|
|
8762
8766
|
switch (_c.label) {
|
|
8763
8767
|
case 0:
|
|
8764
|
-
input
|
|
8768
|
+
console.log("input", input);
|
|
8765
8769
|
return [4 /*yield*/, request({
|
|
8766
8770
|
input: {
|
|
8767
8771
|
url: "https://fc-typechat.ywwl.com/userInputToJson",
|
|
8768
|
-
method: "GET"
|
|
8769
|
-
|
|
8772
|
+
method: "GET",
|
|
8773
|
+
params: input,
|
|
8774
|
+
},
|
|
8770
8775
|
})];
|
|
8771
8776
|
case 1:
|
|
8772
|
-
_c.sent();
|
|
8773
|
-
|
|
8777
|
+
res = _c.sent();
|
|
8778
|
+
if (res.success) {
|
|
8779
|
+
result = res.data;
|
|
8780
|
+
return [2 /*return*/, result.success ? result.data : result];
|
|
8781
|
+
}
|
|
8782
|
+
else {
|
|
8783
|
+
return [2 /*return*/, res.success ? res.data : res];
|
|
8784
|
+
}
|
|
8774
8785
|
}
|
|
8775
8786
|
});
|
|
8776
8787
|
});
|
|
8777
8788
|
}
|
|
8778
8789
|
|
|
8790
|
+
// Ctrl-S保存代码
|
|
8791
|
+
function JSON2String(_a) {
|
|
8792
|
+
var input = _a.input;
|
|
8793
|
+
var data = input.data;
|
|
8794
|
+
var result = { content: '' };
|
|
8795
|
+
try {
|
|
8796
|
+
var str = JSON.stringify(data);
|
|
8797
|
+
result.content = '```json' + str + 'json```';
|
|
8798
|
+
return result;
|
|
8799
|
+
}
|
|
8800
|
+
catch (error) {
|
|
8801
|
+
result.content = '```json' + '{}' + 'json```';
|
|
8802
|
+
return result;
|
|
8803
|
+
}
|
|
8804
|
+
}
|
|
8805
|
+
|
|
8806
|
+
exports.JSON2String = JSON2String;
|
|
8779
8807
|
exports.request = request;
|
|
8780
8808
|
exports.userInputToJson = userInputToJson;
|
|
8781
8809
|
//# sourceMappingURL=ywfe-tools.cjs.map
|