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.6.30 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.29 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.28 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.27 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.26 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.25 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.24 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.23 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.22 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.21 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.20 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.19 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.18 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.17 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.16 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.15 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.2 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.1 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.0 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.5.11 node_modules/preact/compat/src/Children.js