import {
BOOLEAN,
OVERLOADED_BOOLEAN,
getPropertyInfo,
isAttributeNameSafe,
shouldIgnoreAttribute,
shouldRemoveAttribute,
} from '../shared/DOMProperty';
import sanitizeURL from '../shared/sanitizeURL';
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
import quoteAttributeValueForBrowser from './quoteAttributeValueForBrowser';
export function createMarkupForProperty(name: string, value: mixed): string {
const propertyInfo = getPropertyInfo(name);
if (name !== 'style' && shouldIgnoreAttribute(name, propertyInfo, false)) {
return '';
}
if (shouldRemoveAttribute(name, value, propertyInfo, false)) {
return '';
}
if (propertyInfo !== null) {
const attributeName = propertyInfo.attributeName;
const {type} = propertyInfo;
if (type === BOOLEAN || (type === OVERLOADED_BOOLEAN && value === true)) {
return attributeName + '=""';
} else {
if (propertyInfo.sanitizeURL) {
if (__DEV__) {
checkAttributeStringCoercion(value, attributeName);
}
value = '' + (value: any);
sanitizeURL(value);
}
return attributeName + '=' + quoteAttributeValueForBrowser(value);
}
} else if (isAttributeNameSafe(name)) {
return name + '=' + quoteAttributeValueForBrowser(value);
}
return '';
}
export function createMarkupForCustomAttribute(
name: string,
value: mixed,
): string {
if (
!isAttributeNameSafe(name) ||
value == null ||
typeof value === 'function' ||
typeof value === 'symbol'
) {
return '';
}
return name + '=' + quoteAttributeValueForBrowser(value);
}