Sha256: 46fb00b0ca4275b2eaac03cb8a9a6ef49f4598581f361775c54cff9c42b7b840

Contents?: true

Size: 575 Bytes

Versions: 12

Compression:

Stored size: 575 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

12 entries across 12 versions & 1 rubygems

Version Path
isomorfeus-preact-10.6.14 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.13 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.12 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.11 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.10 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.9 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.8 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.7 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.6 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.5 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.4 node_modules/preact/compat/src/Children.js
isomorfeus-preact-10.6.3 node_modules/preact/compat/src/Children.js