1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 10:19:24 +02:00
Oinktube/node_modules/preact/compat/src/Children.js
2024-05-03 12:16:27 -03:00

21 lines
554 B
JavaScript

import { toChildArray } from 'preact';
const mapFn = (children, fn) => {
if (children == null) return null;
return toChildArray(toChildArray(children).map(fn));
};
// This API is completely unnecessary for Preact, so it's basically passthrough.
export const Children = {
map: mapFn,
forEach: mapFn,
count(children) {
return children ? toChildArray(children).length : 0;
},
only(children) {
const normalized = toChildArray(children);
if (normalized.length !== 1) throw 'Children.only';
return normalized[0];
},
toArray: toChildArray
};