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.1.12 to 0.1.13

jest.config.js

2

dist/index.js

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

'use strict';Object.defineProperty(exports,'__esModule',{value:true});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 _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 _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)}}exports.default=_extends({},_react.Children,{filter:function filter(children,filterFn){return _react.Children.toArray(children).filter(filterFn)},groupByType:function groupByType(children,types,rest){return _react.Children.toArray(children).reduce(function(group,child){var isGrouped=types.includes(child.type),addChild=isGrouped?child.props.children:child,key=isGrouped?child.type:rest;return _extends({},group,_defineProperty({},key,[].concat(_toConsumableArray(group[key]||[]),[addChild])))},{})},deepMap:function deepMap(children,deepMapFn){var _this=this;return _react.Children.map(children,function(child){if(child.props&&child.props.children&&_typeof(child.props.children)==='object'){return deepMapFn((0,_react.cloneElement)(child,_extends({},child.props,{children:_this.deepMap(child.props.children,deepMapFn)})))}return deepMapFn(child)})},deepForEach:function deepForEach(children,deepForEachFn){var _this2=this;_react.Children.forEach(children,function(child){if(child.props&&child.props.children&&_typeof(child.props.children)==='object'){_this2.deepForEach(child.props.children,deepForEachFn)}deepForEachFn(child)})},deepFind:function deepFind(children,deepFindFn){var _this3=this;return _react.Children.toArray(children).find(function(child){if(child.props&&child.props.children&&_typeof(child.props.children)==='object'){return _this3.deepFind(child.props.children,deepFindFn)}return deepFindFn(child)})},onlyText:function onlyText(children){var _this4=this;return _react.Children.toArray(children).reduce(function(flattened,child){return[].concat(_toConsumableArray(flattened),[child.props&&child.props.children?_this4.onlyText(child.props.children):child])},[]).join('')}});
'use strict';Object.defineProperty(exports,'__esModule',{value:true});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 _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 _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)}}exports.default=_extends({},_react.Children,{filter:function filter(children,filterFn){return _react.Children.toArray(children).filter(filterFn)},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 _this=this;return _react.Children.map(children,function(child){if(child.props&&child.props.children&&_typeof(child.props.children)==='object'){return deepMapFn((0,_react.cloneElement)(child,_extends({},child.props,{children:_this.deepMap(child.props.children,deepMapFn)})))}return deepMapFn(child)})},deepForEach:function deepForEach(children,deepForEachFn){var _this2=this;_react.Children.forEach(children,function(child){if(child.props&&child.props.children&&_typeof(child.props.children)==='object'){_this2.deepForEach(child.props.children,deepForEachFn)}deepForEachFn(child)})},deepFind:function deepFind(children,deepFindFn){var _this3=this;return _react.Children.toArray(children).find(function(child){if(child.props&&child.props.children&&_typeof(child.props.children)==='object'){return _this3.deepFind(child.props.children,deepFindFn)}return deepFindFn(child)})},onlyText:function onlyText(children){var _this4=this;return _react.Children.toArray(children).reduce(function(flattened,child){return[].concat(_toConsumableArray(flattened),[child.props&&child.props.children?_this4.onlyText(child.props.children):child])},[]).join('')}});
//# sourceMappingURL=index.js.map
{
"name": "react-children-utilities",
"version": "0.1.12",
"version": "0.1.13",
"description": "Extended utils for React.Children opaque data structure",

@@ -23,25 +23,19 @@ "keywords": [

"scripts": {
"test": "jest --coverage",
"lint": "eslint .",
"test": "jest",
"coverage": "rm -rf coverage && jest --coverage",
"build": "rm -rf dist && mkdir dist && babel src/index.js --minified --source-maps --no-comments --out-file dist/index.js",
"prebuild": "npm run -s lint && npm test",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"check": "npm run -s lint && npm run -s coverage",
"dist": "rm -rf dist && mkdir dist && babel src/index.js --minified --source-maps --no-comments --out-file dist/index.js",
"build": "npm run -s check && npm run -s dist",
"travis": "npm run -s build && npm run -s coveralls",
"prepublishOnly": "npm run -s dist",
"preversion": "npm run -s check",
"prepublishOnly": "npm run -s build",
"preversion": "npm run -s prebuild",
"commitmsg": "validate-commit-msg",
"precommit": "npm run -s lint",
"prepush": "npm run -s check",
"prepush": "npm run -s prebuild",
"preparecommitmsg": "prepare-commit-msg-angular $2 $3"
},
"jest": {
"coverageDirectory": "coverage",
"setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js"
},
"dependencies": {
"prop-types": "^15.5.10",
"react": "^15.6.0",
"react-dom": "^15.6.0"
"react": "^15.6.1",
"react-dom": "^15.6.1"
},

@@ -57,4 +51,5 @@ "devDependencies": {

"enzyme": "^2.8.2",
"eslint": "^4.0.0",
"eslint-config-fernandopasik": "^0.8.2",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-jsx-a11y": "^5.0.3",

@@ -67,3 +62,3 @@ "eslint-plugin-react": "^7.1.0",

"react-addons-test-utils": "^15.6.0",
"react-test-renderer": "^15.5.4",
"react-test-renderer": "^15.6.1",
"validate-commit-msg": "^2.12.2"

@@ -70,0 +65,0 @@ },

@@ -31,9 +31,9 @@ import { Children, cloneElement } from 'react';

.reduce((group, child) => {
const
isGrouped = types.includes(child.type),
addChild = isGrouped ? child.props.children : child,
key = isGrouped ? child.type : rest;
const isGrouped = types.includes(child.type);
const addChild = isGrouped ? child.props.children : child;
const key = isGrouped ? child.type : rest;
return {
...group,
[key]: [ ...(group[key] || []), addChild ]
[key]: [...(group[key] || []), addChild],
};

@@ -51,3 +51,3 @@ }, {});

return Children
.map(children, child => {
.map(children, (child) => {
if (child.props && child.props.children

@@ -58,3 +58,3 @@ && typeof child.props.children === 'object') {

...child.props,
children: this.deepMap(child.props.children, deepMapFn)
children: this.deepMap(child.props.children, deepMapFn),
}));

@@ -73,3 +73,3 @@ }

Children
.forEach(children, child => {
.forEach(children, (child) => {
if (child.props && child.props.children

@@ -93,3 +93,3 @@ && typeof child.props.children === 'object') {

.toArray(children)
.find(child => {
.find((child) => {
if (child.props && child.props.children

@@ -114,6 +114,6 @@ && typeof child.props.children === 'object') {

...flattened,
child.props && child.props.children ? this.onlyText(child.props.children) : child
child.props && child.props.children ? this.onlyText(child.props.children) : child,
], [])
.join('');
}
},
};
import React, { cloneElement } from 'react';
import Children from '../src/index.js';
import PropTypes from 'prop-types';
import { shallow } from 'enzyme';
import Children from '../src/';
describe('Children', () => {
it('filter', () => {
const Filtered = props => <div>{ Children.filter(props.children, item => item.type === 'span') }</div>;
Filtered.propTypes = { children: PropTypes.node };
Filtered.propTypes = { children: PropTypes.node.isRequired };
const wrapper = shallow(<Filtered><span>1</span><span>2</span><strong>3</strong></Filtered>);

@@ -20,10 +19,10 @@ expect(wrapper.find('span')).toBePresent();

<div>
<div className="spans">{ Children.groupByType(props.children, [ 'span', 'i' ], 'rest').span }</div>
<div className="rest">{ Children.groupByType(props.children, [ 'span', 'i' ], 'rest').rest }</div>
<div className="empty">{ Children.groupByType(props.children, [ 'span', 'i' ], 'rest').i }</div>
<div className="spans">{ Children.groupByType(props.children, ['span', 'i'], 'rest').span }</div>
<div className="rest">{ Children.groupByType(props.children, ['span', 'i'], 'rest').rest }</div>
<div className="empty">{ Children.groupByType(props.children, ['span', 'i'], 'rest').i }</div>
</div>
);
Grouped.propTypes = { children: PropTypes.node };
Grouped.propTypes = { children: PropTypes.node.isRequired };
const wrapper = shallow(
<Grouped><span><b>1</b></span><span><b>2</b></span><strong>3</strong></Grouped>
<Grouped><span><b>1</b></span><span><b>2</b></span><strong>3</strong></Grouped>,
);

@@ -43,11 +42,13 @@ expect(wrapper.find('.spans b')).toBePresent();

{ Children.deepMap(props.children,
child => child.type === 'b'
? cloneElement(child, { ...child.props, className: 'mapped' })
: child
child => (
child.type === 'b'
? cloneElement(child, { ...child.props, className: 'mapped' })
: child
),
) }
</div>
);
DeepMapped.propTypes = { children: PropTypes.node };
DeepMapped.propTypes = { children: PropTypes.node.isRequired };
const wrapper = shallow(
<DeepMapped><b>1</b><b>2</b><span><b>3</b></span><div><div><b>4</b></div></div></DeepMapped>
<DeepMapped><b>1</b><b>2</b><span><b>3</b></span><div><div><b>4</b></div></div></DeepMapped>,
);

@@ -62,3 +63,3 @@ expect(wrapper.find('.mapped')).toBePresent();

<div>
{ Children.deepForEach(props.children, child => {
{ Children.deepForEach(props.children, (child) => {
if (child.type === 'b') {

@@ -70,7 +71,9 @@ texts.push(child.props.children);

);
DeepForEached.propTypes = { children: PropTypes.node };
DeepForEached.propTypes = { children: PropTypes.node.isRequired };
shallow(
<DeepForEached><b>1</b><b>2</b><span><b>3</b></span><div><div><b>4</b></div></div></DeepForEached>
<DeepForEached>
<b>1</b><b>2</b><span><b>3</b></span><div><div><b>4</b></div></div>
</DeepForEached>,
);
expect(texts).toEqual([ '1', '2', '3', '4' ]);
expect(texts).toEqual(['1', '2', '3', '4']);
});

@@ -80,7 +83,7 @@

const DeepFound = props => (<div>{ Children.deepFind(props.children, child => child.type === 'i') }</div>);
DeepFound.propTypes = { children: PropTypes.node };
const wrapper = shallow(<DeepFound><b>1</b><b>2</b><span><b>3</b></span><i>4</i></DeepFound>);
DeepFound.propTypes = { children: PropTypes.node.isRequired };
const wrapper = shallow(<DeepFound><b>1</b><b>2</b><span><i>3</i></span><i>4</i></DeepFound>);
expect(wrapper.find('i')).toBePresent();
expect(wrapper.find('i')).toHaveLength(1);
expect(wrapper).toHaveText('4');
expect(wrapper).toHaveText('3');
});

@@ -90,5 +93,5 @@

const OnlyText = props => (<div>{ Children.onlyText(props.children) }</div>);
OnlyText.propTypes = { children: PropTypes.node };
OnlyText.propTypes = { children: PropTypes.node.isRequired };
const wrapper = shallow(
<OnlyText><span>0</span><b>1</b><span><i>2</i></span><i>3</i></OnlyText>
<OnlyText><span>0</span><b>1</b><span><i>2</i></span><i>3</i></OnlyText>,
);

@@ -95,0 +98,0 @@ expect(wrapper.find('i')).toBeEmpty();

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

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