@molopos/shared 2.0.17 → 2.0.19
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/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -17,4 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./date"), exports);
|
|
18
18
|
__exportStar(require("./enum"), exports);
|
|
19
19
|
__exportStar(require("./lib/utils"), exports);
|
|
20
|
-
__exportStar(require("./url-
|
|
20
|
+
__exportStar(require("./url-endpoint"), exports);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.
|
|
1
|
+
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.19","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"date-fns":"^4.1.0","luxon":"^3.7.2"}}
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
+
import type { UrlObject } from "url";
|
|
2
|
+
export type Url = string | UrlObject;
|
|
1
3
|
export type EndpointLike<T extends string> = `/${T}`;
|
|
2
4
|
/**
|
|
3
5
|
* Create a URL with query parameters
|
|
4
6
|
* @param baseUrl - The base URL
|
|
5
7
|
* @param endpoint - The endpoint
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
+
* @param params - The URL parameters
|
|
9
|
+
* @param query - The query parameters
|
|
8
10
|
* @returns
|
|
9
11
|
*
|
|
10
12
|
* @example
|
|
11
13
|
* const url = URLEndpoint({
|
|
12
14
|
* baseUrl: "https://api.example.com",
|
|
13
|
-
* endpoint: "/users",
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* endpoint: "/users/:id",
|
|
16
|
+
* params: { id: "123" },
|
|
17
|
+
* query: { limit: 10, page: 1 },
|
|
16
18
|
* });
|
|
17
|
-
* // https://api.example.com/users/123?limit=10&
|
|
19
|
+
* // https://api.example.com/users/123?limit=10&page=1
|
|
18
20
|
*
|
|
19
21
|
*/
|
|
20
22
|
export declare const URLEndpoint: ({ query, params, baseUrl, endpoint, }: {
|
|
21
23
|
query?: Object;
|
|
22
|
-
baseUrl:
|
|
24
|
+
baseUrl: Url;
|
|
23
25
|
params?: Object;
|
|
24
26
|
endpoint: EndpointLike<string>;
|
|
25
|
-
}) =>
|
|
27
|
+
}) => Url;
|
|
@@ -5,18 +5,18 @@ exports.URLEndpoint = void 0;
|
|
|
5
5
|
* Create a URL with query parameters
|
|
6
6
|
* @param baseUrl - The base URL
|
|
7
7
|
* @param endpoint - The endpoint
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
8
|
+
* @param params - The URL parameters
|
|
9
|
+
* @param query - The query parameters
|
|
10
10
|
* @returns
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* const url = URLEndpoint({
|
|
14
14
|
* baseUrl: "https://api.example.com",
|
|
15
|
-
* endpoint: "/users",
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* endpoint: "/users/:id",
|
|
16
|
+
* params: { id: "123" },
|
|
17
|
+
* query: { limit: 10, page: 1 },
|
|
18
18
|
* });
|
|
19
|
-
* // https://api.example.com/users/123?limit=10&
|
|
19
|
+
* // https://api.example.com/users/123?limit=10&page=1
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
22
|
const URLEndpoint = ({ query, params, baseUrl, endpoint, }) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("./index");
|
|
4
|
+
describe("URLEndpoint", () => {
|
|
5
|
+
test("URLEndpoint", () => {
|
|
6
|
+
const baseUrl = "https://api.example.com";
|
|
7
|
+
const result = (0, index_1.URLEndpoint)({
|
|
8
|
+
baseUrl,
|
|
9
|
+
endpoint: "/users/:id",
|
|
10
|
+
params: { id: "123" },
|
|
11
|
+
query: { limit: 10, page: 1 },
|
|
12
|
+
});
|
|
13
|
+
expect(result).toEqual(`${baseUrl}/users/123?limit=10&page=1`);
|
|
14
|
+
});
|
|
15
|
+
});
|