UNPKG

@wordpress/url

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