source: trip-planner-front/node_modules/@angular/common/esm2015/src/location/util.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8/**
9 * Joins two parts of a URL with a slash if needed.
10 *
11 * @param start URL string
12 * @param end URL string
13 *
14 *
15 * @returns The joined URL string.
16 */
17export function joinWithSlash(start, end) {
18 if (start.length == 0) {
19 return end;
20 }
21 if (end.length == 0) {
22 return start;
23 }
24 let slashes = 0;
25 if (start.endsWith('/')) {
26 slashes++;
27 }
28 if (end.startsWith('/')) {
29 slashes++;
30 }
31 if (slashes == 2) {
32 return start + end.substring(1);
33 }
34 if (slashes == 1) {
35 return start + end;
36 }
37 return start + '/' + end;
38}
39/**
40 * Removes a trailing slash from a URL string if needed.
41 * Looks for the first occurrence of either `#`, `?`, or the end of the
42 * line as `/` characters and removes the trailing slash if one exists.
43 *
44 * @param url URL string.
45 *
46 * @returns The URL string, modified if needed.
47 */
48export function stripTrailingSlash(url) {
49 const match = url.match(/#|\?|$/);
50 const pathEndIdx = match && match.index || url.length;
51 const droppedSlashIdx = pathEndIdx - (url[pathEndIdx - 1] === '/' ? 1 : 0);
52 return url.slice(0, droppedSlashIdx) + url.slice(pathEndIdx);
53}
54/**
55 * Normalizes URL parameters by prepending with `?` if needed.
56 *
57 * @param params String of URL parameters.
58 *
59 * @returns The normalized URL parameters string.
60 */
61export function normalizeQueryParams(params) {
62 return params && params[0] !== '?' ? '?' + params : params;
63}
64//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbW1vbi9zcmMvbG9jY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