trimPath

It receives a path-like string, and remove the bars around it, preserving the bars in the middle of it.
  • "/path/to/something/" will resolve to "path/to/something".
  • Useful when handling API requests call.
    Parameter ListReturnsRejection Errors
    • path: string
    • tuple: Array (optional)
    Promise<string || Array>
    Related FunctionsFunction Signature
    function trimPath(path[, tuple]): Promise<string || Array>
    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();