封装url和urlSearchParams

This commit is contained in:
wkj 2023-11-30 21:13:29 +08:00
parent e253485da1
commit f359b69956
19 changed files with 114 additions and 10 deletions

2
lib/index.d.ts vendored
View File

@ -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';

View File

@ -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; } });

View File

@ -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}`;
}

7
lib/utils/url/index.d.ts vendored Normal file
View File

@ -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 };

8
lib/utils/url/index.js Normal file
View File

@ -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;

4
lib/utils/url/index.mp.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
import { URL, URLSearchParams } from 'whatwg-url';
declare const url: typeof URL;
declare const urlSearchParams: typeof URLSearchParams;
export { url, urlSearchParams };

View File

@ -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;

12
lib/utils/url/index.native.d.ts vendored Normal file
View File

@ -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 };

View File

@ -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;

12
lib/utils/url/index.web.d.ts vendored Normal file
View File

@ -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 };

View File

@ -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;

View File

@ -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"
}
}

View File

@ -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,

View File

@ -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}`;
}

View File

@ -0,0 +1,8 @@
import { URL, URLSearchParams } from 'whatwg-url';
const url = URL;
const urlSearchParams = URLSearchParams;
export { url, urlSearchParams };

View File

@ -0,0 +1,7 @@
const url = URL;
const urlSearchParams = URLSearchParams;
export { url, urlSearchParams };

18
src/utils/url/index.ts Normal file
View File

@ -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 };

View File

@ -0,0 +1,7 @@
const url = URL;
const urlSearchParams = URLSearchParams;
export { url, urlSearchParams };