@daysnap/utils 0.0.48 → 0.0.49

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.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 格式化字符串参数,一般用来处理 api path params
3
+ * const url = 'api/v1/user/{id}'
4
+ * const { path, rest } = formatPathParams(url, { id: 123, xxx: 1 })
5
+ * path = 'api/v1/user/123'
6
+ * rest = { xxx: 1 }
7
+ */
8
+ export declare function formatPathParams(path: string, params?: Record<string, any>): {
9
+ path: string;
10
+ rest: {
11
+ [x: string]: any;
12
+ };
13
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 格式化字符串参数,一般用来处理 api path params
3
+ * const url = 'api/v1/user/{id}'
4
+ * const { path, rest } = formatPathParams(url, { id: 123, xxx: 1 })
5
+ * path = 'api/v1/user/123'
6
+ * rest = { xxx: 1 }
7
+ */
8
+ export function formatPathParams(path, params = {}) {
9
+ const rest = Object.assign({}, params);
10
+ if (path.includes('{')) {
11
+ Object.keys(rest).forEach((key) => {
12
+ if (path.includes(`{${key}}`)) {
13
+ path = path.replace(`{${key}}`, rest[key]);
14
+ delete rest[key];
15
+ }
16
+ });
17
+ }
18
+ return { path, rest };
19
+ }
package/es/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export * from './filterPhone';
20
20
  export * from './formatAmount';
21
21
  export * from './formatDate';
22
22
  export * from './formatMessage';
23
+ export * from './formatPathParams';
23
24
  export * from './getBlobByUrl';
24
25
  export * from './getDayMillisecond';
25
26
  export * from './getImageInfo';
package/es/index.js CHANGED
@@ -21,6 +21,7 @@ export * from './filterPhone';
21
21
  export * from './formatAmount';
22
22
  export * from './formatDate';
23
23
  export * from './formatMessage';
24
+ export * from './formatPathParams';
24
25
  export * from './getBlobByUrl';
25
26
  export * from './getDayMillisecond';
26
27
  export * from './getImageInfo';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 格式化字符串参数,一般用来处理 api path params
3
+ * const url = 'api/v1/user/{id}'
4
+ * const { path, rest } = formatPathParams(url, { id: 123, xxx: 1 })
5
+ * path = 'api/v1/user/123'
6
+ * rest = { xxx: 1 }
7
+ */
8
+ export declare function formatPathParams(path: string, params?: Record<string, any>): {
9
+ path: string;
10
+ rest: {
11
+ [x: string]: any;
12
+ };
13
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatPathParams = void 0;
4
+ /**
5
+ * 格式化字符串参数,一般用来处理 api path params
6
+ * const url = 'api/v1/user/{id}'
7
+ * const { path, rest } = formatPathParams(url, { id: 123, xxx: 1 })
8
+ * path = 'api/v1/user/123'
9
+ * rest = { xxx: 1 }
10
+ */
11
+ function formatPathParams(path, params = {}) {
12
+ const rest = Object.assign({}, params);
13
+ if (path.includes('{')) {
14
+ Object.keys(rest).forEach((key) => {
15
+ if (path.includes(`{${key}}`)) {
16
+ path = path.replace(`{${key}}`, rest[key]);
17
+ delete rest[key];
18
+ }
19
+ });
20
+ }
21
+ return { path, rest };
22
+ }
23
+ exports.formatPathParams = formatPathParams;
package/lib/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export * from './filterPhone';
20
20
  export * from './formatAmount';
21
21
  export * from './formatDate';
22
22
  export * from './formatMessage';
23
+ export * from './formatPathParams';
23
24
  export * from './getBlobByUrl';
24
25
  export * from './getDayMillisecond';
25
26
  export * from './getImageInfo';
package/lib/index.js CHANGED
@@ -37,6 +37,7 @@ __exportStar(require("./filterPhone"), exports);
37
37
  __exportStar(require("./formatAmount"), exports);
38
38
  __exportStar(require("./formatDate"), exports);
39
39
  __exportStar(require("./formatMessage"), exports);
40
+ __exportStar(require("./formatPathParams"), exports);
40
41
  __exportStar(require("./getBlobByUrl"), exports);
41
42
  __exportStar(require("./getDayMillisecond"), exports);
42
43
  __exportStar(require("./getImageInfo"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daysnap/utils",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "description": "通用的工具库",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",