one
Version:
One is a new React Framework that makes Vite serve both native and web.
20 lines (19 loc) • 1.03 kB
JavaScript
import { isValidElement } from "react";
function isChildOfType(element, type) {
return isValidElement(element) && element.type === type;
}
function getFirstChildOfType(children, type) {
const childArray = Array.isArray(children) ? children : [children];
for (const child of childArray) if (isChildOfType(child, type)) return child;
}
function getAllChildrenOfType(children, type) {
return (Array.isArray(children) ? children : [children]).filter(child => isChildOfType(child, type));
}
function getAllChildrenNotOfType(children, type) {
return (Array.isArray(children) ? children : [children]).filter(child => !isChildOfType(child, type));
}
function filterAllowedChildrenElements(children, allowedTypes) {
return (Array.isArray(children) ? children : [children]).filter(child => isValidElement(child) && allowedTypes.some(type => child.type === type));
}
export { filterAllowedChildrenElements, getAllChildrenNotOfType, getAllChildrenOfType, getFirstChildOfType, isChildOfType };
//# sourceMappingURL=children.mjs.map