react-children-utilities
Advanced tools
Comparing version 2.0.12 to 2.0.13
import { ReactNode } from 'react'; | ||
export declare type MapFunction = (child: ReactNode, index?: number, children?: ReactNode[]) => ReactNode; | ||
declare const deepMap: (children: ReactNode, deepMapFn: MapFunction) => ReactNode; | ||
declare const deepMap: (children: ReactNode, deepMapFn: MapFunction) => ReactNode[]; | ||
export default deepMap; | ||
//# sourceMappingURL=deepMap.d.ts.map |
import { Children, cloneElement, isValidElement } from 'react'; | ||
import hasComplexChildren from './hasComplexChildren'; | ||
const deepMap = (children, deepMapFn) => { | ||
return Children.map(children, (child) => { | ||
return Children.toArray(children).map((child) => { | ||
if (isValidElement(child) && hasComplexChildren(child)) { | ||
@@ -6,0 +6,0 @@ // Clone the child that has children and map them too |
@@ -1,4 +0,6 @@ | ||
import { ReactNode } from 'react'; | ||
declare const hasComplexChildren: (element: ReactNode) => boolean; | ||
import { ReactElement, ReactNode } from 'react'; | ||
declare const hasComplexChildren: (element: ReactNode) => element is ReactElement<{ | ||
children: ReactNode[]; | ||
}, string | ((props: any) => ReactElement<any, string | any | (new (props: any) => import("react").Component<any, any, any>)> | null) | (new (props: any) => import("react").Component<any, any, any>)>; | ||
export default hasComplexChildren; | ||
//# sourceMappingURL=hasComplexChildren.d.ts.map |
{ | ||
"name": "react-children-utilities", | ||
"version": "2.0.12", | ||
"version": "2.0.13", | ||
"description": "Recursive and extended utils for React children opaque data structure", | ||
@@ -56,8 +56,8 @@ "keywords": [ | ||
"@types/enzyme-adapter-react-16": "^1.0.6", | ||
"@types/jest": "^25.1.4", | ||
"@types/react": "^16.9.26", | ||
"@types/react-dom": "^16.9.5", | ||
"@typescript-eslint/eslint-plugin": "^2.25.0", | ||
"@typescript-eslint/parser": "^2.25.0", | ||
"all-contributors-cli": "^6.14.0", | ||
"@types/jest": "^25.2.1", | ||
"@types/react": "^16.9.34", | ||
"@types/react-dom": "^16.9.6", | ||
"@typescript-eslint/eslint-plugin": "^2.27.0", | ||
"@typescript-eslint/parser": "^2.27.0", | ||
"all-contributors-cli": "^6.14.1", | ||
"bundlesize": "^0.18.0", | ||
@@ -72,3 +72,3 @@ "codecov": "^3.6.5", | ||
"eslint-config-prettier": "^6.10.1", | ||
"eslint-plugin-import": "^2.20.1", | ||
"eslint-plugin-import": "^2.20.2", | ||
"eslint-plugin-jest": "^23.8.2", | ||
@@ -79,13 +79,13 @@ "eslint-plugin-jsx-a11y": "^6.2.3", | ||
"eslint-plugin-react-hooks": "^3.0.0", | ||
"flow-bin": "^0.121.0", | ||
"flow-bin": "^0.122.0", | ||
"flowgen": "^1.10.0", | ||
"husky": "^4.2.3", | ||
"jest": "^25.2.3", | ||
"husky": "^4.2.5", | ||
"jest": "^25.3.0", | ||
"jest-environment-enzyme": "^7.1.2", | ||
"jest-enzyme": "^7.1.2", | ||
"jest-junit": "^10.0.0", | ||
"lint-staged": "^10.0.9", | ||
"lint-staged": "^10.1.3", | ||
"make-dir-cli": "^2.0.0", | ||
"normalize.css": "^8.0.1", | ||
"prettier": "^2.0.2", | ||
"prettier": "^2.0.4", | ||
"raf": "^3.4.1", | ||
@@ -95,5 +95,5 @@ "react": "^16.13.1", | ||
"react-test-renderer": "^16.13.1", | ||
"rollup": "^2.2.0", | ||
"rollup": "^2.6.0", | ||
"rollup-plugin-terser": "^5.3.0", | ||
"ts-jest": "^25.2.1", | ||
"ts-jest": "25.2.1", | ||
"typescript": "^3.8.3" | ||
@@ -100,0 +100,0 @@ }, |
@@ -16,3 +16,3 @@ /// <reference types="react" /> | ||
deepForEach: (children: import("react").ReactNode, deepForEachFn: import("./lib/deepForEach").ForEachFunction) => void; | ||
deepMap: (children: import("react").ReactNode, deepMapFn: import("./lib/deepMap").MapFunction) => import("react").ReactNode; | ||
deepMap: (children: import("react").ReactNode, deepMapFn: import("./lib/deepMap").MapFunction) => import("react").ReactNode[]; | ||
filter: (children: import("react").ReactNode, filterFn: (child: import("react").ReactNode, index?: number | undefined, children?: import("react").ReactNode[] | undefined) => boolean) => import("react").ReactNode[]; | ||
@@ -23,3 +23,5 @@ groupByType: (children: import("react").ReactNode, types?: readonly import("react").ReactNode[], rest?: string) => import("./lib/groupByType").GroupedChildren; | ||
}, string | ((props: any) => import("react").ReactElement<any, string | any | (new (props: any) => import("react").Component<any, any, any>)> | null) | (new (props: any) => import("react").Component<any, any, any>)>; | ||
hasComplexChildren: (element: import("react").ReactNode) => boolean; | ||
hasComplexChildren: (element: import("react").ReactNode) => element is import("react").ReactElement<{ | ||
children: import("react").ReactNode[]; | ||
}, string | ((props: any) => import("react").ReactElement<any, string | any | (new (props: any) => import("react").Component<any, any, any>)> | null) | (new (props: any) => import("react").Component<any, any, any>)>; | ||
onlyText: (children: import("react").ReactNode) => string; | ||
@@ -26,0 +28,0 @@ map<T, C>(children: C | C[], fn: (child: C, index: number) => T): C extends null | undefined ? C : Exclude<T, boolean | null | undefined>[]; |
@@ -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=>o(t)?(l=t,!0):!(!e(t)||!n(t))&&(l=c(t.t.children,o),void 0!==l)),l},p=(r,o)=>{t.forEach(r,t=>{e(t)&&n(t)&&p(t.t.children,o),o(t)})},d=(o,l)=>t.map(o,t=>e(t)&&n(t)?l(r(t,Object.assign(Object.assign({},t.t),{children:d(t.t.children,l)}))):l(t)),i=(e,r)=>t.toArray(e).filter(r),a=(r,o=[],n="rest")=>t.toArray(r).reduce((t,r)=>{const l=Object.assign({},t);let c=n;return e(r)&&"string"==typeof r.type&&o.includes(r.type)&&(c=r.type),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):b(r),t.concat(n)},""):b(r);var h=Object.assign(Object.assign({},t),{o:l,l:c,p:p,i:d,filter:i,O:a,h:o,j:n,s:O});export default h;export{l as deepFilter,c as deepFind,p as deepForEach,d as deepMap,i as filter,a as groupByType,o as hasChildren,n as hasComplexChildren,O as onlyText}; | ||
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=>o(t)?(l=t,!0):!(!e(t)||!n(t))&&(l=c(t.t.children,o),void 0!==l)),l},p=(r,o)=>{t.forEach(r,t=>{e(t)&&n(t)&&p(t.t.children,o),o(t)})},d=(o,l)=>t.toArray(o).map(t=>e(t)&&n(t)?l(r(t,Object.assign(Object.assign({},t.t),{children:d(t.t.children,l)}))):l(t)),i=(e,r)=>t.toArray(e).filter(r),a=(r,o=[],n="rest")=>t.toArray(r).reduce((t,r)=>{const l=Object.assign({},t);let c=n;return e(r)&&"string"==typeof r.type&&o.includes(r.type)&&(c=r.type),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):b(r),t.concat(n)},""):b(r);var h=Object.assign(Object.assign({},t),{o:l,l:c,p:p,i:d,filter:i,O:a,h:o,j:n,s:O});export default h;export{l as deepFilter,c as deepFind,p as deepForEach,d as deepMap,i as filter,a as groupByType,o as hasChildren,n as hasComplexChildren,O as onlyText}; | ||
//# 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52239
216