<commit_before>import {Fiber} from "react-reconciler";

export const sleep = (duration: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, duration));

export type Predicate<Arg> = (arg: Arg) => boolean;

export const queryTree = (node: JSX.Element, predicate: Predicate<JSX.Element>): JSX.Element | null => {
    // check current node
    if (predicate(node)) {
        return node;
    }
    // check children
    if (node?.props?.children) {
        for (const child of [node.props.children].flat()) {
            const result = queryTree(child, predicate);
            if (result) {
                return result;
            }
        }
    }

    return null;
};

export type Direction = null | "up" | "down" | "both";

export const queryFiber = (fiber: Fiber, predicate: Predicate<Fiber>, direction = "up", depth = 30, current = 0): Fiber | null => {
    // check depth
    if (current > depth) {
        return null;
    }

    // check current node
    if (predicate(fiber)) {
        return fiber;
    }

    // check parent (upwards)
    if ((direction === "up" || direction === "both") && fiber.return) {
        const result = queryFiber(fiber.return, predicate, "up", depth, current + 1);
        if (result) {
            return result;
        }
    }

    // check children (downwards)
    if ((direction === "down" || direction === "both") && fiber.child) {
        let child = fiber.child;
        while (child) {
            const result = queryFiber(child, predicate, "down", depth, current + 1);
            if (result) {
                return result;
            }
            child = child.sibling;
        }
    }

    return null;
};
<commit_msg>Fix typing<commit_after>import {Fiber} from "react-reconciler";

export const sleep = (duration: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, duration));

export type Predicate<Arg> = (arg: Arg) => boolean;

export const queryTree = (node: JSX.Element, predicate: Predicate<JSX.Element>): JSX.Element | null => {
    // check current node
    if (predicate(node)) {
        return node;
    }
    // check children
    if (node?.props?.children) {
        for (const child of [node.props.children].flat()) {
            const result = queryTree(child, predicate);
            if (result) {
                return result;
            }
        }
    }

    return null;
};

export type Direction = null | "up" | "down" | "both";

export const queryFiber = (fiber: Fiber, predicate: Predicate<Fiber>, direction: Direction = "up", depth = 30, current = 0): Fiber | null => {
    // check depth
    if (current > depth) {
        return null;
    }

    // check current node
    if (predicate(fiber)) {
        return fiber;
    }

    // check parent (upwards)
    if ((direction === "up" || direction === "both") && fiber.return) {
        const result = queryFiber(fiber.return, predicate, "up", depth, current + 1);
        if (result) {
            return result;
        }
    }

    // check children (downwards)
    if ((direction === "down" || direction === "both") && fiber.child) {
        let child = fiber.child;
        while (child) {
            const result = queryFiber(child, predicate, "down", depth, current + 1);
            if (result) {
                return result;
            }
            child = child.sibling;
        }
    }

    return null;
};

{'fraction_non_alphanumeric': 0.1423099587507366, 'fraction_numerical': 0.0029463759575721863, 'mean_word_length': 2.1348107109879964, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '2441734', 'n_tokens_mistral': 1013, 'n_tokens_neox': 978, 'n_words': 286}