UNPKG

@wordpress/url

Version:
20 lines (19 loc) 442 B
/** * Checks for invalid characters within the provided path. * * @param {string} path The URL path. * * @example * ```js * const isValid = isValidPath( 'test/path/' ); // true * const isNotValid = isValidPath( '/invalid?test/path/' ); // false * ``` * * @return {boolean} True if the argument contains a valid path */ export function isValidPath( path ) { if ( ! path ) { return false; } return /^[^\s#?]+$/.test( path ); }