/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-dom-bindings/src/shared/isAttributeNameSafe.js
40 строк
1 KB
Jan Kassens
lint: enable reportUnusedDisableDirectives and remove unused suppressions (#28721)
21 июн 2024, 19:24
Не верифицирован
21 июн 2024, 19:24
b565373
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow */ import hasOwnProperty from 'shared/hasOwnProperty'; const ATTRIBUTE_NAME_START_CHAR = ':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD'; export const ATTRIBUTE_NAME_CHAR: string = ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040'; const VALID_ATTRIBUTE_NAME_REGEX: RegExp = new RegExp( '^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$', ); const illegalAttributeNameCache: {[string]: boolean} = {}; const validatedAttributeNameCache: {[string]: boolean} = {}; export default function isAttributeNameSafe(attributeName: string): boolean { if (hasOwnProperty.call(validatedAttributeNameCache, attributeName)) { return true; } if (hasOwnProperty.call(illegalAttributeNameCache, attributeName)) { return false; } if (VALID_ATTRIBUTE_NAME_REGEX.test(attributeName)) { validatedAttributeNameCache[attributeName] = true; return true; } illegalAttributeNameCache[attributeName] = true; if (__DEV__) { console.error('Invalid attribute name: `%s`', attributeName); } return false; }