trimPath
Description
It receives a path-like string, and remove the bars around it, preserving the bars in the middle of it.
Useful when handling API requests call.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<string || Array> | |
Related Functions | Function Signature | |
function trimPath(path[, tuple]): Promise<string || Array> |
Examples
1
2
3
import { trimPath } from "puddy-m/lib/helpers";
trimPath("/foo/bar/fizz/buzz/").then((trimmedPath) => console.log(trimmedPath)); // foo/bar/fizz/buzz
1
2
3
4
5
6
7
8
import { trimPath } from "puddy-m/lib/helpers"
trimPath("/foo/bar/fizz/buzz/", [])
.then((tuple) => trimPath("////foo/bar////", tuple))
.then(([trimmedPath1, trimmedPath2]) => {
console.log(trimmedPath1); // foo/bar/fizz/buzz
console.log(trimmedPath2); // foo/bar
});
1
2
3
4
5
6
7
8
9
import { trimPath } from "puddy-m/lib/helpers";
// It also works with await.
const f = async () => {
const trimmedPath = await trimPath("/foo/");
console.log(trimmedPath); // foo
};
f();