<commit_before>type FunctionalComponent = (props: Props) => JSX.Element;
type TsxElement = string | FunctionalComponent;

export interface Props {
    [key: string]: string;
}

const parseNode = (element: string, children: string[]) => {
    let elementString = `<${element}>`;

    children.forEach((child) => {
        elementString += child;
    });

    elementString += `</${element}>`;

    return elementString;
};

const tsxParser = (element: TsxElement, properties: Props = {}, ...children: string[]) => {
    if (typeof element === 'function') {
        return element(properties);
    }

    return parseNode(element, children);
};

export const textAddSpaces = (text?: string): string => `&nbsp${text}&nbsp`;

export default tsxParser;<commit_msg>Add support for renaming properties and short closing void elements.<commit_after>type FunctionalComponent = (props: Partial<Props>) => JSX.Element;
type TsxElement = string | FunctionalComponent;

export interface Props {
    [key: string]: string | [];
}

interface PropertRewrites {
    [key: string]: string;
}

const propertyRewrites: PropertRewrites = {
    httpEquiv: 'http-equiv',
    className: 'class',
};

interface VoidElements {
    [key: string]: string;
}

const voidElements: VoidElements = {
    meta: 'meta',
    link: 'link',
    br: 'br',
};

const parseNode = (element: string, properties: Partial<Props>, children: string[]) => {
    let elementString = `<${element} `;

    Object.keys(properties).forEach((property) => {
        elementString += `${propertyRewrites[property] || property}="${properties[property]}" `;
    });

    elementString += voidElements[element] ? '/>' : '>';

    children.forEach((child) => {
        elementString += child;
    });

    if (!voidElements[element]) {
        elementString += `</${element}>`;
    }

    return elementString;
};

const tsxParser = (element: TsxElement, properties: Partial<Props> = {}, ...children: string[]) => {
    if (typeof element === 'function') {
        return element(properties);
    }

    return parseNode(element, properties || {}, children);
};

export const textAddSpaces = (text?: string): string => `&nbsp${text}&nbsp`;

export default tsxParser;
{'fraction_non_alphanumeric': 0.16266425011327593, 'fraction_numerical': 0.0, 'mean_word_length': 3.9285714285714284, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5176066', 'n_tokens_mistral': 652, 'n_tokens_neox': 627, 'n_words': 161}