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 2.5.1 to 2.5.2

23

lib/deepFilter.js
import { Children, cloneElement, isValidElement } from 'react';
import hasComplexChildren from './hasComplexChildren.js';
const deepFilter = (children, deepFilterFn) => {
return Children.toArray(children)
.filter(deepFilterFn)
.map((child) => {
if (isValidElement(child) && hasComplexChildren(child)) {
// Clone the child that has children and filter them too
return cloneElement(child, Object.assign(Object.assign({}, child.props), { children: deepFilter(child.props.children, deepFilterFn) }));
}
return child;
});
};
const deepFilter = (children, deepFilterFn) => Children.toArray(children)
.filter(deepFilterFn)
.map((child) => {
if (isValidElement(child) && hasComplexChildren(child)) {
// Clone the child that has children and filter them too
return cloneElement(child, {
...child.props,
children: deepFilter(child.props.children, deepFilterFn),
});
}
return child;
});
export default deepFilter;
//# sourceMappingURL=deepFilter.js.map
import { Children, cloneElement, isValidElement } from 'react';
import hasComplexChildren from './hasComplexChildren.js';
const deepMap = (children, deepMapFn) => {
return Children.toArray(children).map((child, index, mapChildren) => {
if (isValidElement(child) && hasComplexChildren(child)) {
// Clone the child that has children and map them too
return deepMapFn(cloneElement(child, Object.assign(Object.assign({}, child.props), { children: deepMap(child.props.children, deepMapFn) })));
}
return deepMapFn(child, index, mapChildren);
});
};
const deepMap = (children, deepMapFn) => Children.toArray(children).map((child, index, mapChildren) => {
if (isValidElement(child) && hasComplexChildren(child)) {
// Clone the child that has children and map them too
return deepMapFn(cloneElement(child, {
...child.props,
children: deepMap(child.props.children, deepMapFn),
}));
}
return deepMapFn(child, index, mapChildren);
});
export default deepMap;
//# sourceMappingURL=deepMap.js.map
import { Children } from 'react';
const filter = (children, filterFn) => {
return Children.toArray(children).filter(filterFn);
};
const filter = (children, filterFn) => Children.toArray(children).filter(filterFn);
export default filter;
//# sourceMappingURL=filter.js.map
import { Children, isValidElement } from 'react';
export const isChildInTypes = (child, types = []) => isValidElement(child) && typeof child.type === 'string' && types.includes(child.type);
const groupByType = (children, types = [], rest = 'rest') => {
return Children.toArray(children).reduce((groups, child) => {
const newGroups = Object.assign({}, groups);
const key = isChildInTypes(child, types) ? child.type : rest;
if (typeof newGroups[key] === 'undefined') {
newGroups[key] = [];
}
newGroups[key] = [...newGroups[key], child];
return newGroups;
}, {});
};
const groupByType = (children, types = [], rest = 'rest') => Children.toArray(children).reduce((groups, child) => {
const newGroups = { ...groups };
const key = isChildInTypes(child, types) ? child.type : rest;
if (typeof newGroups[key] === 'undefined') {
newGroups[key] = [];
}
newGroups[key] = [...newGroups[key], child];
return newGroups;
}, {});
export default groupByType;
//# sourceMappingURL=groupByType.js.map

@@ -1,5 +0,5 @@

import type { ReactNode, ReactText } from 'react';
export declare const childToString: (child?: boolean | {} | ReactText | null | undefined) => string;
import type { ReactNode } from 'react';
export declare const childToString: (child?: ReactNode) => string;
declare const onlyText: (children: ReactNode) => string;
export default onlyText;
//# sourceMappingURL=onlyText.d.ts.map
{
"name": "react-children-utilities",
"version": "2.5.1",
"version": "2.5.2",
"description": "Recursive and extended utils for React children opaque data structure",

@@ -42,3 +42,3 @@ "keywords": [

"flowgen": "flowgen react-children-utilities.d.ts --quiet -o react-children-utilities.js.flow",
"format": "prettier --write ** ./* ./.??*",
"format": "prettier --no-error-on-unmatched-pattern --write ** ./* ./.??*",
"_postinstall": "husky install",

@@ -60,11 +60,11 @@ "lint": "eslint . --ext js,jsx,ts,tsx",

"devDependencies": {
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@types/enzyme": "^3.10.8",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.5",
"@types/react-dom": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^4.22.1",
"@typescript-eslint/parser": "^4.22.1",
"@types/react": "^17.0.6",
"@types/react-dom": "^17.0.5",
"@typescript-eslint/eslint-plugin": "^4.24.0",
"@typescript-eslint/parser": "^4.24.0",
"all-contributors-cli": "^6.20.0",

@@ -77,6 +77,6 @@ "bundlesize": "^1.0.0-beta.2",

"enzyme-adapter-react-16": "^1.15.6",
"eslint": "7.25.0",
"eslint": "^7.26.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jest": "^24.3.6",

@@ -87,4 +87,4 @@ "eslint-plugin-jsx-a11y": "^6.4.1",

"eslint-plugin-react-hooks": "^4.2.0",
"flow-bin": "^0.150.0",
"flowgen": "1.14.1",
"flow-bin": "^0.151.0",
"flowgen": "^1.14.1",
"husky": "^6.0.0",

@@ -95,15 +95,15 @@ "jest": "^26.6.3",

"jest-junit": "^12.0.0",
"lint-staged": "^10.5.4",
"lint-staged": "^11.0.0",
"normalize.css": "^8.0.1",
"pinst": "^2.1.6",
"prettier": "^2.2.1",
"prettier-plugin-organize-imports": "^2.0.0",
"prettier": "^2.3.0",
"prettier-plugin-organize-imports": "^2.1.0",
"prettier-plugin-packagejson": "^2.2.11",
"raf": "^3.4.1",
"react": "^17.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-test-renderer": "^17.0.2",
"rollup": "^2.47.0",
"rollup": "^2.48.0",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "26.5.6",
"ts-jest": "^26.5.6",
"typescript": "^4.2.4"

@@ -110,0 +110,0 @@ },

@@ -13,3 +13,5 @@ import { Children } from 'react';

export { deepFilter, deepFind, deepForEach, deepMap, filter, groupByType, hasChildren, hasComplexChildren, onlyText, onlyValid, };
export default Object.assign(Object.assign({}, Children), { deepFilter,
export default {
...Children,
deepFilter,
deepFind,

@@ -23,3 +25,4 @@ deepForEach,

onlyText,
onlyValid });
onlyValid,
};
//# sourceMappingURL=react-children-utilities.js.map

@@ -1,2 +0,2 @@

import{isValidElement as e,Children as t,cloneElement as r}from"react";const o=t=>e(t)&&Boolean(t.t.children),n=r=>e(r)&&o(r)&&t.toArray(r.t.children).reduce(((t,r)=>t||e(r)),!1),l=(o,c)=>t.toArray(o).filter(c).map((t=>e(t)&&n(t)?r(t,Object.assign(Object.assign({},t.t),{children:l(t.t.children,c)})):t)),c=(r,o)=>{let l;return t.toArray(r).find(((t,r,d)=>o(t,r,d)?(l=t,!0):!(!e(t)||!n(t))&&(l=c(t.t.children,o),void 0!==l))),l},d=(r,o)=>{t.forEach(r,((t,r)=>{e(t)&&n(t)&&d(t.t.children,o),o(t,r)}))},i=(o,l)=>t.toArray(o).map(((t,o,c)=>e(t)&&n(t)?l(r(t,Object.assign(Object.assign({},t.t),{children:i(t.t.children,l)}))):l(t,o,c))),p=(e,r)=>t.toArray(e).filter(r),a=(r,o=[],n="rest")=>t.toArray(r).reduce(((t,r)=>{const l=Object.assign({},t),c=((t,r=[])=>e(t)&&"string"==typeof t.type&&r.includes(t.type))(r,o)?r.type:n;return void 0===l[c]&&(l[c]=[]),l[c]=[...l[c],r],l}),{}),b=e=>null==e||"boolean"==typeof e||"{}"===JSON.stringify(e)?"":e.toString(),O=r=>r instanceof Array||e(r)?t.toArray(r).reduce(((t,r)=>{let n="";return n=e(r)&&o(r)?O(r.t.children):e(r)&&!o(r)?"":b(r),t.concat(n)}),""):b(r),h=t=>l(t,(t=>e(t)));var j=Object.assign(Object.assign({},t),{o:l,l:c,i:d,p:i,filter:p,O:a,h:o,j:n,u:O,m:h});export default j;export{l as deepFilter,c as deepFind,d as deepForEach,i as deepMap,p as filter,a as groupByType,o as hasChildren,n as hasComplexChildren,O as onlyText,h as onlyValid};
import{isValidElement as e,Children as r,cloneElement as o}from"react";const t=r=>e(r)&&Boolean(r.o.children),n=o=>e(o)&&t(o)&&r.toArray(o.o.children).reduce(((r,o)=>r||e(o)),!1),l=(t,d)=>r.toArray(t).filter(d).map((r=>e(r)&&n(r)?o(r,{...r.o,children:l(r.o.children,d)}):r)),d=(o,t)=>{let l;return r.toArray(o).find(((r,o,i)=>t(r,o,i)?(l=r,!0):!(!e(r)||!n(r))&&(l=d(r.o.children,t),void 0!==l))),l},i=(o,t)=>{r.forEach(o,((r,o)=>{e(r)&&n(r)&&i(r.o.children,t),t(r,o)}))},p=(t,l)=>r.toArray(t).map(((r,t,d)=>e(r)&&n(r)?l(o(r,{...r.o,children:p(r.o.children,l)})):l(r,t,d))),a=(e,o)=>r.toArray(e).filter(o),c=(o,t=[],n="rest")=>r.toArray(o).reduce(((r,o)=>{const l={...r},d=((r,o=[])=>e(r)&&"string"==typeof r.type&&o.includes(r.type))(o,t)?o.type:n;return void 0===l[d]&&(l[d]=[]),l[d]=[...l[d],o],l}),{}),h=e=>null==e||"boolean"==typeof e||"{}"===JSON.stringify(e)?"":e.toString(),s=o=>o instanceof Array||e(o)?r.toArray(o).reduce(((r,o)=>{let n="";return n=e(o)&&t(o)?s(o.o.children):e(o)&&!t(o)?"":h(o),r.concat(n)}),""):h(o),y=r=>l(r,(r=>e(r)));var f={...r,t:l,l:d,i:i,p:p,filter:a,h:c,u:t,m:n,v:s,C:y};export default f;export{l as deepFilter,d as deepFind,i as deepForEach,p as deepMap,a as filter,c as groupByType,t as hasChildren,n as hasComplexChildren,s as onlyText,y as onlyValid};
//# sourceMappingURL=react-children-utilities.min.js.map

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

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

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