react-children-utilities
Advanced tools
Comparing version 2.1.0 to 2.1.1
import { ReactNode } from 'react'; | ||
export declare type FindFunction = (child: ReactNode, index?: number, children?: readonly ReactNode[]) => boolean; | ||
declare const deepFind: (children: ReactNode, deepFindFn: FindFunction) => ReactNode; | ||
declare const deepFind: (children: ReactNode, deepFindFn: FindFunction) => ReactNode | undefined; | ||
export default deepFind; | ||
//# sourceMappingURL=deepFind.d.ts.map |
import { Children, isValidElement } from 'react'; | ||
import hasComplexChildren from './hasComplexChildren'; | ||
const deepFind = (children, deepFindFn) => { | ||
// eslint-disable-next-line @typescript-eslint/init-declarations | ||
let found; | ||
@@ -5,0 +6,0 @@ Children.toArray(children).find((child, index, findChildren) => { |
@@ -17,6 +17,9 @@ import { Children, isValidElement } from 'react'; | ||
return Children.toArray(children).reduce((text, child) => { | ||
let newText; | ||
let newText = ''; | ||
if (isValidElement(child) && hasChildren(child)) { | ||
newText = onlyText(child.props.children); | ||
} | ||
else if (isValidElement(child) && !hasChildren(child)) { | ||
newText = ''; | ||
} | ||
else { | ||
@@ -23,0 +26,0 @@ newText = childToString(child); |
{ | ||
"name": "react-children-utilities", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Recursive and extended utils for React children opaque data structure", | ||
@@ -26,3 +26,4 @@ "keywords": [ | ||
"Ryosuke IWANAGA (https://github.com/riywo)", | ||
"Daniel Pinyol (https://github.com/dpinol)" | ||
"Daniel Pinyol (https://github.com/dpinol)", | ||
"Brian Bartholomew (https://github.com/bcbrian)" | ||
], | ||
@@ -58,7 +59,7 @@ "sideEffects": false, | ||
"@types/enzyme-adapter-react-16": "^1.0.6", | ||
"@types/jest": "^25.2.1", | ||
"@types/react": "^16.9.34", | ||
"@types/react-dom": "^16.9.6", | ||
"@typescript-eslint/eslint-plugin": "^2.28.0", | ||
"@typescript-eslint/parser": "^2.28.0", | ||
"@types/jest": "^25.2.2", | ||
"@types/react": "^16.9.35", | ||
"@types/react-dom": "^16.9.8", | ||
"@typescript-eslint/eslint-plugin": "^2.33.0", | ||
"@typescript-eslint/parser": "^2.33.0", | ||
"all-contributors-cli": "^6.14.2", | ||
@@ -71,22 +72,22 @@ "bundlesize": "^0.18.0", | ||
"enzyme-adapter-react-16": "^1.15.2", | ||
"eslint": "^6.8.0", | ||
"eslint": "^7.0.0", | ||
"eslint-config-airbnb": "^18.1.0", | ||
"eslint-config-prettier": "^6.10.1", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
"eslint-plugin-jest": "^23.8.2", | ||
"eslint-plugin-jest": "^23.11.0", | ||
"eslint-plugin-jsx-a11y": "^6.2.3", | ||
"eslint-plugin-prettier": "^3.1.3", | ||
"eslint-plugin-react": "^7.19.0", | ||
"eslint-plugin-react-hooks": "^3.0.0", | ||
"flow-bin": "^0.123.0", | ||
"eslint-plugin-react": "^7.20.0", | ||
"eslint-plugin-react-hooks": "^4.0.2", | ||
"flow-bin": "^0.124.0", | ||
"flowgen": "^1.10.0", | ||
"husky": "^4.2.5", | ||
"jest": "^25.3.0", | ||
"jest": "^26.0.1", | ||
"jest-environment-enzyme": "^7.1.2", | ||
"jest-enzyme": "^7.1.2", | ||
"jest-junit": "^10.0.0", | ||
"lint-staged": "^10.1.6", | ||
"lint-staged": "^10.2.2", | ||
"make-dir-cli": "^2.0.0", | ||
"normalize.css": "^8.0.1", | ||
"prettier": "^2.0.4", | ||
"prettier": "^2.0.5", | ||
"raf": "^3.4.1", | ||
@@ -96,6 +97,6 @@ "react": "^16.13.1", | ||
"react-test-renderer": "^16.13.1", | ||
"rollup": "^2.6.1", | ||
"rollup": "^2.10.0", | ||
"rollup-plugin-terser": "^5.3.0", | ||
"ts-jest": "^25.4.0", | ||
"typescript": "^3.8.3" | ||
"ts-jest": "^25.5.1", | ||
"typescript": "^3.9.2" | ||
}, | ||
@@ -102,0 +103,0 @@ "peerDependencies": { |
@@ -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,p)=>o(t,r,p)?(l=t,!0):!(!e(t)||!n(t))&&(l=c(t.t.children,o),void 0!==l)),l},p=(r,o)=>{t.forEach(r,(t,r)=>{e(t)&&n(t)&&p(t.t.children,o),o(t,r)})},d=(o,l)=>t.toArray(o).map((t,o,c)=>e(t)&&n(t)?l(r(t,Object.assign(Object.assign({},t.t),{children:d(t.t.children,l)}))):l(t,o,c)),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,r,p)=>o(t,r,p)?(l=t,!0):!(!e(t)||!n(t))&&(l=c(t.t.children,o),void 0!==l)),l},p=(r,o)=>{t.forEach(r,(t,r)=>{e(t)&&n(t)&&p(t.t.children,o),o(t,r)})},d=(o,l)=>t.toArray(o).map((t,o,c)=>e(t)&&n(t)?l(r(t,Object.assign(Object.assign({},t.t),{children:d(t.t.children,l)}))):l(t,o,c)),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):e(r)&&!o(r)?"":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 |
# React Children Utilities | ||
[![Gzip Bundle Size][badge-size]][url-size] | ||
[![Build Status][badge-ci]][url-ci] | ||
[![Test Coverage Status][badge-cov]][url-cov] | ||
[![Known Vulnerabilities][badge-sec]][url-sec] | ||
[![Gzip Bundle Size][badge-size]][url-size] [![Build Status][badge-ci]][url-ci] [![Test Coverage Status][badge-cov]][url-cov] [![Known Vulnerabilities][badge-sec]][url-sec] | ||
[![All Contributors][badge-contributors]](#contributors-) | ||
[![npm version][badge-version]][url-version] | ||
[![npm downloads][badge-downloads]][url-downloads] | ||
[![All Contributors][badge-contributors]](#contributors-) [![npm version][badge-version]][url-version] [![npm downloads][badge-downloads]][url-downloads] | ||
@@ -16,3 +11,3 @@ [badge-size]: http://img.badgesize.io/https://unpkg.com/react-children-utilities/react-children-utilities.min.js?compression=gzip | ||
[badge-sec]: https://snyk.io/test/github/fernandopasik/react-children-utilities/badge.svg?targetFile=package.json | ||
[badge-contributors]: https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square | ||
[badge-contributors]: https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square | ||
[badge-version]: https://img.shields.io/npm/v/react-children-utilities.svg | ||
@@ -96,2 +91,5 @@ [badge-downloads]: https://img.shields.io/npm/dm/react-children-utilities.svg | ||
</tr> | ||
<tr> | ||
<td align="center"><a href="http://brianbartholomew.com"><img src="https://avatars0.githubusercontent.com/u/6721622?v=4" width="100px;" alt=""/><br /><sub><b>Brian Bartholomew</b></sub></a><br /><a href="https://github.com/fernandopasik/react-children-utilities/issues?q=author%3Abcbrian" title="Bug reports">🐛</a> <a href="https://github.com/fernandopasik/react-children-utilities/commits?author=bcbrian" title="Code">💻</a></td> | ||
</tr> | ||
</table> | ||
@@ -98,0 +96,0 @@ |
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
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
54874
221
104