/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/hooks/src/validateNamespace.ts
27 строк
739 B
Eshaan Dabasiya
Migrate `hooks` package to TypeScript (#70488)
11 июл 2025, 08:13
Не верифицирован
11 июл 2025, 08:13
7db8f38
Код
Авторство
О чём код?
/** * Validate a namespace string. * * @param namespace The namespace to validate - should take the form * `vendor/plugin/function`. * * @return Whether the namespace is valid. */ function validateNamespace( namespace: string ): boolean { if ( 'string' !== typeof namespace || '' === namespace ) { // eslint-disable-next-line no-console console.error( 'The namespace must be a non-empty string.' ); return false; } if ( ! /^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test( namespace ) ) { // eslint-disable-next-line no-console console.error( 'The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.' ); return false; } return true; } export default validateNamespace;