/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/url/src/get-path.ts
20 строк
517 B
Eshaan Dabasiya
Migrate `@packages/url` package to TypeScript (#70496)
18 июл 2025, 13:25
Не верифицирован
18 июл 2025, 13:25
443d8fa
Код
Авторство
О чём код?
/** * Returns the path part of the URL. * * @param url The full URL. * * @example * ```js * const path1 = getPath( 'http://localhost:8080/this/is/a/test?query=true' ); // 'this/is/a/test' * const path2 = getPath( 'https://wordpress.org/help/faq/' ); // 'help/faq' * ``` * * @return The path part of the URL. */ export function getPath( url: string ): string | void { const matches = /^[^\/\s:]+:(?:\/\/)?[^\/\s#?]+[\/]([^\s#?]+)[#?]{0,1}\S*$/.exec( url ); if ( matches ) { return matches[ 1 ]; } }