@evlop/commons 1.0.195 → 1.0.196

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"pathHelper.d.ts","sourceRoot":"","sources":["../../../src/helpers/pathHelper.ts"],"names":[],"mappings":"AAGA,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,UA4B7D"}
1
+ {"version":3,"file":"pathHelper.d.ts","sourceRoot":"","sources":["../../../src/helpers/pathHelper.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,UA0B7D"}
@@ -4,33 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generatePath = void 0;
7
- const lodash_1 = require("lodash");
8
7
  const query_string_1 = __importDefault(require("query-string"));
9
8
  function generatePath(pathTemplate, params) {
10
- const parts = lodash_1.compact(lodash_1.split(pathTemplate, '/'));
11
- const { pathSegments, usedParams } = lodash_1.reduce(parts, ({ pathSegments, usedParams }, part) => {
12
- const isOptional = part[part.length - 1] === '?';
13
- if (isOptional)
14
- part = part.slice(0, -1);
15
- if (part[0] === ':') {
16
- const key = part.slice(1);
17
- if (lodash_1.has(params, [key])) {
18
- pathSegments.push(encodeURIComponent(params[key]));
19
- usedParams[key] = true;
20
- }
21
- else if (!isOptional) {
22
- pathSegments.push(part);
23
- }
9
+ if (!pathTemplate || !params)
10
+ return pathTemplate;
11
+ const paramsCopy = Object.assign({}, params);
12
+ // Replace placeholders in the path
13
+ let path = String(pathTemplate).replace(/:\w+/g, (match) => {
14
+ const paramKey = match.substring(1); // Remove the ':' prefix
15
+ if (paramsCopy[paramKey] !== undefined) {
16
+ const value = paramsCopy[paramKey];
17
+ delete paramsCopy[paramKey]; // Remove the param from the copy to avoid duplicating in the query string
18
+ return encodeURIComponent(value);
24
19
  }
25
- else {
26
- pathSegments.push(part);
27
- }
28
- return { pathSegments, usedParams };
29
- }, { pathSegments: [], usedParams: {} });
30
- const remainingParams = lodash_1.omit(params, Object.keys(usedParams));
31
- const query = query_string_1.default.stringify(remainingParams);
32
- const path = '/' + pathSegments.join('/');
33
- return path + (query ? '?' + query : '');
20
+ return match;
21
+ });
22
+ // Use query-string to stringify the remaining params from the copy
23
+ const query = query_string_1.default.stringify(paramsCopy);
24
+ // Append query string if it's not empty
25
+ if (query) {
26
+ path += `?${query}`;
27
+ }
28
+ return path;
34
29
  }
35
30
  exports.generatePath = generatePath;
36
31
  //# sourceMappingURL=pathHelper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pathHelper.js","sourceRoot":"","sources":["../../../src/helpers/pathHelper.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA2D;AAC3D,gEAAuC;AAEvC,SAAgB,YAAY,CAAC,YAAoB,EAAE,MAAW;IAC1D,MAAM,KAAK,GAAG,gBAAO,CAAC,cAAK,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC;IAEhD,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,eAAM,CAAC,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE;QACtF,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;QACjD,IAAI,UAAU;YAAE,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAEzC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YACjB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC1B,IAAI,YAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE;gBACpB,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBACnD,U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ACpC,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;YACnC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,0EAA0E;YACvG,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;SACpC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,mEAAmE;IACnE,MAAM,KAAK,GAAG,sBAAW,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAEhD,wCAAwC;IACxC,IAAI,KAAK,EAAE;QACP,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;KACvB;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AA1BD,oCA0BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evlop/commons",
3
- "version": "1.0.195",
3
+ "version": "1.0.196",
4
4
  "description": "",
5
5
  "main": "dist/main.js",
6
6
  "peerDependencies": {