UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

28 lines (27 loc) 1.17 kB
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; } } return void 0; } function getAllChildrenOfType(children, type) { const childArray = Array.isArray(children) ? children : [children]; return childArray.filter(child => isChildOfType(child, type)); } function getAllChildrenNotOfType(children, type) { const childArray = Array.isArray(children) ? children : [children]; return childArray.filter(child => !isChildOfType(child, type)); } function filterAllowedChildrenElements(children, allowedTypes) { const childArray = Array.isArray(children) ? children : [children]; return childArray.filter(child => isValidElement(child) && allowedTypes.some(type => child.type === type)); } export { filterAllowedChildrenElements, getAllChildrenNotOfType, getAllChildrenOfType, getFirstChildOfType, isChildOfType }; //# sourceMappingURL=children.mjs.map