Sha256: 9e4610894492e9a0f16919f332eb360912c494e71cef1224dd213803be0ba144

Contents?: true

Size: 554 Bytes

Versions: 69

Compression:

Stored size: 554 Bytes

Contents

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
};

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
isomorfeus-preact-10.5.10 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.5.9 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.5.8 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.5.7 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.5.6 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.5.5 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.5.4 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.5.3 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.5.2 node_modules/preact/compat/src/Children.js