Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-children-utilities

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-children-utilities - npm Package Compare versions

Comparing version 0.3.4 to 0.4.0

.flowconfig

2

dist/index.js

@@ -1,3 +0,3 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};var _typeof=typeof Symbol==='function'&&typeof Symbol.iterator==='symbol'?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==='function'&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};var _react=require('react');function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}var hasChildren=function hasChildren(child){return child&&child.props&&child.props.children};var hasComplexChildren=function hasComplexChildren(child){return hasChildren(child)&&_typeof(child.props.children)==='object'};exports.default=_extends({},_react.Children,{filter:function filter(children,filterFn){return _react.Children.toArray(children).filter(filterFn)},deepFilter:function deepFilter(children,deepFilterFn){var _this=this;return _react.Children.toArray(children).filter(deepFilterFn).map(function(child){if(hasComplexChildren(child)){return(0,_react.cloneElement)(child,_extends({},child.props,{children:_this.deepFilter(child.props.children,deepFilterFn)}))}return child})},groupByType:function groupByType(children,types,rest){return _react.Children.toArray(children).reduce(function(group,child){var isGrouped=types.includes(child.type);var addChild=isGrouped?child.props.children:child;var key=isGrouped?child.type:rest;return _extends({},group,_defineProperty({},key,[].concat(_toConsumableArray(group[key]||[]),[addChild])))},{})},deepMap:function deepMap(children,deepMapFn){var _this2=this;return _react.Children.map(children,function(child){if(hasComplexChildren(child)){return deepMapFn((0,_react.cloneElement)(child,_extends({},child.props,{children:_this2.deepMap(child.props.children,deepMapFn)})))}return deepMapFn(child)})},deepForEach:function deepForEach(children,deepForEachFn){var _this3=this;_react.Children.forEach(children,function(child){if(hasComplexChildren(child)){_this3.deepForEach(child.props.children,deepForEachFn)}deepForEachFn(child)})},deepFind:function deepFind(children,deepFindFn){var _this4=this;return _react.Children.toArray(children).find(function(child){if(hasComplexChildren(child)){return _this4.deepFind(child.props.children,deepFindFn)}return deepFindFn(child)})},onlyText:function onlyText(children){var _this5=this;return _react.Children.toArray(children).reduce(function(flattened,child){return[].concat(_toConsumableArray(flattened),[hasChildren(child)?_this5.onlyText(child.props.children):child])},[]).join('')}});
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};var _typeof=typeof Symbol==='function'&&typeof Symbol.iterator==='symbol'?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==='function'&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};var _react=require('react');function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}var hasChildren=function hasChildren(child){return Boolean(child&&child.props&&child.props.children)};var hasComplexChildren=function hasComplexChildren(child){return hasChildren(child)&&_typeof(child.props.children)==='object'};exports.default=_extends({},_react.Children,{filter:function filter(children,filterFn){return _react.Children.toArray(children).filter(filterFn)},deepFilter:function deepFilter(children,deepFilterFn){var _this=this;return _react.Children.toArray(children).filter(deepFilterFn).map(function(child){if(hasComplexChildren(child)){return(0,_react.cloneElement)(child,_extends({},child.props,{children:_this.deepFilter(child.props.children,deepFilterFn)}))}return child})},groupByType:function groupByType(children,types,rest){return _react.Children.toArray(children).reduce(function(group,child){var isGrouped=types.includes(child.type);var addChild=isGrouped?child.props.children:child;var key=isGrouped?child.type:rest;return _extends({},group,_defineProperty({},key,[].concat(_toConsumableArray(group[key]||[]),[addChild])))},{})},deepMap:function deepMap(children,deepMapFn){var _this2=this;return _react.Children.map(children,function(child){if(hasComplexChildren(child)){return deepMapFn((0,_react.cloneElement)(child,_extends({},child.props,{children:_this2.deepMap(child.props.children,deepMapFn)})))}return deepMapFn(child)})},deepForEach:function deepForEach(children,deepForEachFn){var _this3=this;_react.Children.forEach(children,function(child){if(hasComplexChildren(child)){_this3.deepForEach(child.props.children,deepForEachFn)}deepForEachFn(child)})},deepFind:function deepFind(children,deepFindFn){var _this4=this;return _react.Children.toArray(children).find(function(child){if(hasComplexChildren(child)){return _this4.deepFind(child.props.children,deepFindFn)}return deepFindFn(child)})},onlyText:function onlyText(children){var _this5=this;return _react.Children.toArray(children).reduce(function(flattened,child){return[].concat(_toConsumableArray(flattened),[hasChildren(child)?_this5.onlyText(child.props.children):child])},[]).join('')}});
//# sourceMappingURL=index.js.map
{
"name": "react-children-utilities",
"version": "0.3.4",
"version": "0.4.0",
"description": "Extended utils for React.Children opaque data structure",

@@ -48,4 +48,6 @@ "keywords": [

"babel-core": "^6.26.0",
"babel-eslint": "^8.2.2",
"babel-jest": "^22.4.1",
"babel-preset-env": "^1.6.1",
"babel-preset-flow": "^6.23.0",
"babel-preset-react": "^6.24.1",

@@ -59,5 +61,7 @@ "babel-preset-stage-2": "^6.24.1",

"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-flowtype": "^2.46.1",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
"flow-bin": "^0.68.0",
"husky": "^0.15.0-rc.9",

@@ -74,4 +78,4 @@ "jest": "^22.4.2",

"engines": {
"node": ">=6.0.0"
"node": ">=8.0.0"
}
}

@@ -0,6 +1,11 @@

// @flow
import { Children, cloneElement } from 'react';
import type { Element, Node } from 'react';
const hasChildren = child => child && child.props && child.props.children;
const hasComplexChildren = child => hasChildren(child) && typeof child.props.children === 'object';
const hasChildren = (child: Element<any>): boolean =>
Boolean(child && child.props && child.props.children);
const hasComplexChildren = (child: Element<any>): boolean =>
hasChildren(child) && typeof child.props.children === 'object';
export default {

@@ -16,3 +21,3 @@

*/
filter(children, filterFn) {
filter(children: number, filterFn: (child: Node) => boolean): Node {
return Children

@@ -27,4 +32,5 @@ .toArray(children)

* @param {function} deepFilterFn - Deep Filter callback
* @returns {array} - Deep Filtered children
*/
deepFilter(children, deepFilterFn) {
deepFilter(children: Node, deepFilterFn: (child: Node) => boolean): Node {
return Children

@@ -53,3 +59,3 @@ .toArray(children)

*/
groupByType(children, types, rest) {
groupByType(children: Node, types: [string], rest: string): Object {
return Children

@@ -75,3 +81,3 @@ .toArray(children)

*/
deepMap(children, deepMapFn) {
deepMap(children: Node, deepMapFn: (child: Node) => Node): Node {
return Children

@@ -95,3 +101,3 @@ .map(children, (child) => {

*/
deepForEach(children, deepForEachFn) {
deepForEach(children: Node, deepForEachFn: (child: Node) => void): void {
Children

@@ -113,3 +119,3 @@ .forEach(children, (child) => {

*/
deepFind(children, deepFindFn) {
deepFind(children: Node, deepFindFn): Node {
return Children

@@ -131,3 +137,3 @@ .toArray(children)

*/
onlyText(children) {
onlyText(children: Node): string {
return Children

@@ -134,0 +140,0 @@ .toArray(children)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc