woocommerce/plugins/woocommerce-admin/client/utils/url-helpers.ts

12 lines
408 B
TypeScript
Raw Normal View History

/**
* Extracts all segments from the path query param as a string array.
*
* @param path The query path param
* @return The list of segments from the path
*/
export function getSegmentsFromPath( path?: string ): string[] {
const firstIndex = path?.startsWith( '/' ) ? 1 : 0;
const lastIndex = path?.endsWith( '/' ) ? -1 : undefined;
return path?.slice( firstIndex, lastIndex )?.split( '/' ) ?? [];
}