Farmbot-Web-App/frontend/util/urls.ts

15 lines
522 B
TypeScript
Raw Permalink Normal View History

2018-04-25 11:45:22 -06:00
import { history } from "../history";
2018-12-03 21:16:23 -07:00
import { trim } from "lodash";
2018-04-25 11:45:22 -06:00
/** When needing to reference the url in some js universally or vice versa. */
export function urlFriendly(stringToFormat: string) {
return encodeURIComponent(stringToFormat.replace(/ /gi, "_").toLowerCase());
}
/** Get remainder of current url after the last "/". */
2018-12-03 21:16:23 -07:00
export function lastUrlChunk(): string {
2018-04-25 11:45:22 -06:00
const p = history.getCurrentLocation().pathname;
2018-12-03 21:16:23 -07:00
const pathArray = trim(p, "/").split("/");
return pathArray[pathArray.length - 1];
2018-04-25 11:45:22 -06:00
}