/
githubmirror
/
docusaurus
Обзор
Документация
Войти
/
githubmirror
/
docusaurus
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/docusaurus-plugin-client-redirects/src/redirectValidation.ts
28 строк
766 B
Sébastien Lorber
feat(client-redirects-plugin): support fully qualified urls and querystring/hash in destination/to url (#9171)
21 июл 2023, 20:54
Не верифицирован
21 июл 2023, 20:54
09ea3bc
Код
Авторство
О чём код?
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import {Joi, PathnameSchema} from '@docusaurus/utils-validation'; import type {RedirectItem} from './types'; const RedirectSchema = Joi.object<RedirectItem>({ from: PathnameSchema.required(), to: Joi.string().required(), }); export function validateRedirect(redirect: RedirectItem): void { const {error} = RedirectSchema.validate(redirect, { abortEarly: true, convert: false, }); if (error) { // Tells the user which redirect is the problem! throw new Error( `${JSON.stringify(redirect)} => Validation error: ${error.message}`, ); } }