/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/url/src/get-protocol.ts
19 строк
442 B
Eshaan Dabasiya
Migrate `@packages/url` package to TypeScript (#70496)
18 июл 2025, 13:25
Не верифицирован
18 июл 2025, 13:25
443d8fa
Код
Авторство
О чём код?
/** * Returns the protocol part of the URL. * * @param url The full URL. * * @example * ```js * const protocol1 = getProtocol( 'tel:012345678' ); // 'tel:' * const protocol2 = getProtocol( 'https://wordpress.org' ); // 'https:' * ``` * * @return The protocol part of the URL. */ export function getProtocol( url: string ): string | void { const matches = /^([^\s:]+:)/.exec( url ); if ( matches ) { return matches[ 1 ]; } }