封装url和urlSearchParams
This commit is contained in:
parent
e253485da1
commit
f359b69956
|
|
@ -16,7 +16,7 @@ export * from './actions/action';
|
|||
export * from './actions/relation';
|
||||
export { SimpleConnector } from './utils/SimpleConnector';
|
||||
export { assert } from './utils/assert';
|
||||
export { composeUrl } from './utils/url';
|
||||
export { composeUrl } from './utils/domain';
|
||||
export { checkAttributesNotNull, checkAttributesScope, } from './utils/validator';
|
||||
export { compareVersion } from './utils/version';
|
||||
export * from './types';
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ var SimpleConnector_1 = require("./utils/SimpleConnector");
|
|||
Object.defineProperty(exports, "SimpleConnector", { enumerable: true, get: function () { return SimpleConnector_1.SimpleConnector; } });
|
||||
var assert_1 = require("./utils/assert");
|
||||
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return assert_1.assert; } });
|
||||
var url_1 = require("./utils/url");
|
||||
Object.defineProperty(exports, "composeUrl", { enumerable: true, get: function () { return url_1.composeUrl; } });
|
||||
var domain_1 = require("./utils/domain");
|
||||
Object.defineProperty(exports, "composeUrl", { enumerable: true, get: function () { return domain_1.composeUrl; } });
|
||||
var validator_1 = require("./utils/validator");
|
||||
Object.defineProperty(exports, "checkAttributesNotNull", { enumerable: true, get: function () { return validator_1.checkAttributesNotNull; } });
|
||||
Object.defineProperty(exports, "checkAttributesScope", { enumerable: true, get: function () { return validator_1.checkAttributesScope; } });
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.composeUrl = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const url_1 = tslib_1.__importDefault(require("url"));
|
||||
function composeUrl(url, params) {
|
||||
const urlSp = new url_1.default.URLSearchParams(params);
|
||||
const urlSp = new URLSearchParams(params);
|
||||
if (url.includes('?')) {
|
||||
return `${url}&${urlSp}`;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/// <reference types="node" />
|
||||
import { URL, URLSearchParams } from 'node:url';
|
||||
import type { UrlObject } from 'node:url';
|
||||
declare const url: typeof URL;
|
||||
declare const urlSearchParams: typeof URLSearchParams;
|
||||
type urlObject = UrlObject;
|
||||
export { url, urlSearchParams, urlObject };
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.urlSearchParams = exports.url = void 0;
|
||||
const node_url_1 = require("node:url");
|
||||
const url = node_url_1.URL;
|
||||
exports.url = url;
|
||||
const urlSearchParams = node_url_1.URLSearchParams;
|
||||
exports.urlSearchParams = urlSearchParams;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import { URL, URLSearchParams } from 'whatwg-url';
|
||||
declare const url: typeof URL;
|
||||
declare const urlSearchParams: typeof URLSearchParams;
|
||||
export { url, urlSearchParams };
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.urlSearchParams = exports.url = void 0;
|
||||
const whatwg_url_1 = require("whatwg-url");
|
||||
const url = whatwg_url_1.URL;
|
||||
exports.url = url;
|
||||
const urlSearchParams = whatwg_url_1.URLSearchParams;
|
||||
exports.urlSearchParams = urlSearchParams;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
declare const url: {
|
||||
new (url: string | URL, base?: string | URL | undefined): URL;
|
||||
prototype: URL;
|
||||
canParse(url: string | URL, base?: string | undefined): boolean;
|
||||
createObjectURL(obj: Blob | MediaSource): string;
|
||||
revokeObjectURL(url: string): void;
|
||||
};
|
||||
declare const urlSearchParams: {
|
||||
new (init?: string | Record<string, string> | string[][] | URLSearchParams | undefined): URLSearchParams;
|
||||
prototype: URLSearchParams;
|
||||
};
|
||||
export { url, urlSearchParams };
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.urlSearchParams = exports.url = void 0;
|
||||
const url = URL;
|
||||
exports.url = url;
|
||||
const urlSearchParams = URLSearchParams;
|
||||
exports.urlSearchParams = urlSearchParams;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
declare const url: {
|
||||
new (url: string | URL, base?: string | URL | undefined): URL;
|
||||
prototype: URL;
|
||||
canParse(url: string | URL, base?: string | undefined): boolean;
|
||||
createObjectURL(obj: Blob | MediaSource): string;
|
||||
revokeObjectURL(url: string): void;
|
||||
};
|
||||
declare const urlSearchParams: {
|
||||
new (init?: string | Record<string, string> | string[][] | URLSearchParams | undefined): URLSearchParams;
|
||||
prototype: URLSearchParams;
|
||||
};
|
||||
export { url, urlSearchParams };
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.urlSearchParams = exports.url = void 0;
|
||||
const url = URL;
|
||||
exports.url = url;
|
||||
const urlSearchParams = URLSearchParams;
|
||||
exports.urlSearchParams = urlSearchParams;
|
||||
|
|
@ -31,6 +31,7 @@
|
|||
"@types/react": "^17.0.2",
|
||||
"@types/uuid": "^8.3.0",
|
||||
"@types/wechat-miniprogram": "^3.4.1",
|
||||
"@types/whatwg-url": "^11.0.3",
|
||||
"assert": "^2.0.0",
|
||||
"cross-env": "^7.0.2",
|
||||
"cross-spawn": "^7.0.3",
|
||||
|
|
@ -44,6 +45,7 @@
|
|||
"dependencies": {
|
||||
"dayjs": "^1.11.9",
|
||||
"node-schedule": "^2.1.1",
|
||||
"uuid": "^9.0.0"
|
||||
"uuid": "^9.0.0",
|
||||
"whatwg-url": "^14.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export * from './actions/relation';
|
|||
|
||||
export { SimpleConnector } from './utils/SimpleConnector';
|
||||
export { assert } from './utils/assert';
|
||||
export { composeUrl } from './utils/url';
|
||||
export { composeUrl } from './utils/domain';
|
||||
export {
|
||||
checkAttributesNotNull,
|
||||
checkAttributesScope,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import URL from 'url';
|
||||
|
||||
export function composeUrl(url: string, params: Record<string, any>) {
|
||||
const urlSp = new URL.URLSearchParams(params);
|
||||
const urlSp = new URLSearchParams(params);
|
||||
if (url.includes('?')) {
|
||||
return `${url}&${urlSp}`;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
|
||||
import { URL, URLSearchParams } from 'whatwg-url';
|
||||
|
||||
const url = URL;
|
||||
const urlSearchParams = URLSearchParams;
|
||||
|
||||
export { url, urlSearchParams };
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
const url = URL;
|
||||
const urlSearchParams = URLSearchParams;
|
||||
|
||||
export { url, urlSearchParams };
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
|
||||
|
||||
import { URL, URLSearchParams } from 'node:url';
|
||||
import type {
|
||||
UrlObject,
|
||||
URLFormatOptions,
|
||||
UrlWithParsedQuery,
|
||||
UrlWithStringQuery,
|
||||
Url
|
||||
} from 'node:url';
|
||||
|
||||
|
||||
const url = URL;
|
||||
const urlSearchParams = URLSearchParams;
|
||||
type urlObject = UrlObject
|
||||
|
||||
export { url, urlSearchParams, urlObject };
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
|
||||
|
||||
const url = URL;
|
||||
const urlSearchParams = URLSearchParams;
|
||||
|
||||
export { url, urlSearchParams };
|
||||
Loading…
Reference in New Issue