react-nanny
Advanced tools
Comparing version 2.8.0 to 2.9.0
@@ -0,1 +1,7 @@ | ||
## [2.9.0] - 2021-05-17 | ||
- Added typing generics for child items | ||
## [2.8.0] - 2021-04-16 | ||
- Added overload for 'ByType' functions to accept single type arg as well as an array of types | ||
## [2.6.0] - 2021-01-19 | ||
@@ -2,0 +8,0 @@ - Added getChildrenWithDescendant |
@@ -7,5 +7,6 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T} - The first matching child | ||
* @param {(child: TChild) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TChild} - The first matching child | ||
* @example | ||
@@ -15,3 +16,3 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true | ||
*/ | ||
export declare const getChild: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T; | ||
export declare const getChild: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC; | ||
/** | ||
@@ -22,5 +23,6 @@ * Gets first child by specified predicate (deep search) | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T} - The first matching child | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TChild} - The first matching child | ||
* @example | ||
@@ -30,2 +32,2 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true | ||
*/ | ||
export declare const getChildDeep: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T; | ||
export declare const getChildDeep: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC; |
@@ -10,5 +10,6 @@ "use strict"; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T} - The first matching child | ||
* @param {(child: TChild) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TChild} - The first matching child | ||
* @example | ||
@@ -27,5 +28,6 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T} - The first matching child | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TChild} - The first matching child | ||
* @example | ||
@@ -32,0 +34,0 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true |
@@ -7,5 +7,6 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All matching children | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All matching children | ||
* @example | ||
@@ -15,3 +16,3 @@ * // Finds all children that have an 'active' prop set to true | ||
*/ | ||
export declare const getChildren: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T[]; | ||
export declare const getChildren: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC[]; | ||
/** | ||
@@ -22,5 +23,6 @@ * Gets all children by specified predicate (deep search) | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All matching children | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All matching children | ||
* @example | ||
@@ -30,2 +32,2 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true | ||
*/ | ||
export declare const getChildrenDeep: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T[]; | ||
export declare const getChildrenDeep: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC[]; |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -17,5 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All matching children | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All matching children | ||
* @example | ||
@@ -34,5 +33,6 @@ * // Finds all children that have an 'active' prop set to true | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All matching children | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All matching children | ||
* @example | ||
@@ -49,6 +49,6 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true | ||
if (predicate(child)) { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
if ((_a = child.props) === null || _a === void 0 ? void 0 : _a.children) { | ||
output = __spreadArrays(output, exports.getChildrenDeep(child.props.children, predicate)); | ||
output = __spreadArray(__spreadArray([], output), exports.getChildrenDeep(child.props.children, predicate)); | ||
} | ||
@@ -55,0 +55,0 @@ } |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -88,6 +86,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
if (_types.indexOf(typeOfComponent_1.typeOfComponent(child, customTypeKey)) !== -1) { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
if ((_b = child.props) === null || _b === void 0 ? void 0 : _b.children) { | ||
output = __spreadArrays(output, exports.getChildrenByTypeDeep(child.props.children, _types, { customTypeKey: customTypeKey })); | ||
output = __spreadArray(__spreadArray([], output), exports.getChildrenByTypeDeep(child.props.children, _types, { customTypeKey: customTypeKey })); | ||
} | ||
@@ -94,0 +92,0 @@ } |
@@ -7,6 +7,7 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All children that match the predicate or have a descendant which matches the predicate | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All children that match the predicate or have a descendant which matches the predicate | ||
*/ | ||
export declare const getChildrenWithDescendant: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T[]; | ||
export declare const getChildrenWithDescendant: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC[]; |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -18,5 +16,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All children that match the predicate or have a descendant which matches the predicate | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All children that match the predicate or have a descendant which matches the predicate | ||
*/ | ||
@@ -29,3 +28,3 @@ var getChildrenWithDescendant = function (children, predicate) { | ||
if (getChild_1.getChildDeep(child, predicate)) { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
@@ -32,0 +31,0 @@ } |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -50,3 +48,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
if (getChildByType_1.getChildByTypeDeep(child, types, { customTypeKey: customTypeKey, prioritized: false })) { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
@@ -53,0 +51,0 @@ } |
@@ -8,2 +8,3 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
@@ -13,2 +14,2 @@ * @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
*/ | ||
export declare const getDescendantDepth: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => IDescendantDepth<T>[]; | ||
export declare const getDescendantDepth: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => IDescendantDepth<TC>[]; |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -17,2 +15,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
@@ -53,3 +52,3 @@ * @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
if (depthToMatch >= 0) { | ||
output = __spreadArrays(output, [{ ancestor: child, depthToMatch: depthToMatch }]); | ||
output = __spreadArray(__spreadArray([], output), [{ ancestor: child, depthToMatch: depthToMatch }]); | ||
} | ||
@@ -56,0 +55,0 @@ } |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -76,3 +74,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
if (depthToMatch >= 0) { | ||
output = __spreadArrays(output, [{ ancestor: child, depthToMatch: depthToMatch }]); | ||
output = __spreadArray(__spreadArray([], output), [{ ancestor: child, depthToMatch: depthToMatch }]); | ||
} | ||
@@ -79,0 +77,0 @@ } |
@@ -7,2 +7,3 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
@@ -15,3 +16,3 @@ * @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
*/ | ||
export declare const removeChildren: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T[]; | ||
export declare const removeChildren: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC[]; | ||
/** | ||
@@ -22,4 +23,5 @@ * Removes all children by specified predicate (deep search) | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All non-matching children | ||
@@ -30,2 +32,2 @@ * @example | ||
*/ | ||
export declare const removeChildrenDeep: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T[]; | ||
export declare const removeChildrenDeep: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC[]; |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -17,2 +15,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
@@ -34,4 +33,5 @@ * @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All non-matching children | ||
@@ -50,3 +50,3 @@ * @example | ||
if ((_a = child.props) === null || _a === void 0 ? void 0 : _a.children) { | ||
output = __spreadArrays(output, [ | ||
output = __spreadArray(__spreadArray([], output), [ | ||
Object.assign(child, { | ||
@@ -62,3 +62,3 @@ props: Object.assign(child.props, { | ||
else { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
@@ -65,0 +65,0 @@ } |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -88,3 +86,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
if ((_b = child.props) === null || _b === void 0 ? void 0 : _b.children) { | ||
output = __spreadArrays(output, [ | ||
output = __spreadArray(__spreadArray([], output), [ | ||
Object.assign({}, child, { | ||
@@ -100,3 +98,3 @@ props: Object.assign({}, child.props, { | ||
else { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
@@ -103,0 +101,0 @@ } |
@@ -7,5 +7,6 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T} - The first matching child | ||
* @param {(child: TChild) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TChild} - The first matching child | ||
* @example | ||
@@ -15,3 +16,3 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true | ||
*/ | ||
export declare const getChild: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T; | ||
export declare const getChild: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC; | ||
/** | ||
@@ -22,5 +23,6 @@ * Gets first child by specified predicate (deep search) | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T} - The first matching child | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TChild} - The first matching child | ||
* @example | ||
@@ -30,2 +32,2 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true | ||
*/ | ||
export declare const getChildDeep: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T; | ||
export declare const getChildDeep: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC; |
@@ -7,5 +7,6 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T} - The first matching child | ||
* @param {(child: TChild) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TChild} - The first matching child | ||
* @example | ||
@@ -23,5 +24,6 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T} - The first matching child | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TChild} - The first matching child | ||
* @example | ||
@@ -28,0 +30,0 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true |
@@ -7,5 +7,6 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All matching children | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All matching children | ||
* @example | ||
@@ -15,3 +16,3 @@ * // Finds all children that have an 'active' prop set to true | ||
*/ | ||
export declare const getChildren: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T[]; | ||
export declare const getChildren: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC[]; | ||
/** | ||
@@ -22,5 +23,6 @@ * Gets all children by specified predicate (deep search) | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All matching children | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All matching children | ||
* @example | ||
@@ -30,2 +32,2 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true | ||
*/ | ||
export declare const getChildrenDeep: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T[]; | ||
export declare const getChildrenDeep: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC[]; |
@@ -1,7 +0,5 @@ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -14,5 +12,6 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All matching children | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All matching children | ||
* @example | ||
@@ -30,5 +29,6 @@ * // Finds all children that have an 'active' prop set to true | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All matching children | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All matching children | ||
* @example | ||
@@ -45,6 +45,6 @@ * // Finds the first occurrence of a child that has a prop of 'active' set to true | ||
if (predicate(child)) { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
if ((_a = child.props) === null || _a === void 0 ? void 0 : _a.children) { | ||
output = __spreadArrays(output, getChildrenDeep(child.props.children, predicate)); | ||
output = __spreadArray(__spreadArray([], output), getChildrenDeep(child.props.children, predicate)); | ||
} | ||
@@ -51,0 +51,0 @@ } |
@@ -1,7 +0,5 @@ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -84,6 +82,6 @@ import * as React from 'react'; | ||
if (_types.indexOf(typeOfComponent(child, customTypeKey)) !== -1) { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
if ((_b = child.props) === null || _b === void 0 ? void 0 : _b.children) { | ||
output = __spreadArrays(output, getChildrenByTypeDeep(child.props.children, _types, { customTypeKey: customTypeKey })); | ||
output = __spreadArray(__spreadArray([], output), getChildrenByTypeDeep(child.props.children, _types, { customTypeKey: customTypeKey })); | ||
} | ||
@@ -90,0 +88,0 @@ } |
@@ -7,6 +7,7 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All children that match the predicate or have a descendant which matches the predicate | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All children that match the predicate or have a descendant which matches the predicate | ||
*/ | ||
export declare const getChildrenWithDescendant: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T[]; | ||
export declare const getChildrenWithDescendant: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC[]; |
@@ -1,7 +0,5 @@ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -15,5 +13,6 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All children that match the predicate or have a descendant which matches the predicate | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {TC[]} - All children that match the predicate or have a descendant which matches the predicate | ||
*/ | ||
@@ -26,3 +25,3 @@ export var getChildrenWithDescendant = function (children, predicate) { | ||
if (getChildDeep(child, predicate)) { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
@@ -29,0 +28,0 @@ } |
@@ -1,7 +0,5 @@ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -47,3 +45,3 @@ import * as React from 'react'; | ||
if (getChildByTypeDeep(child, types, { customTypeKey: customTypeKey, prioritized: false })) { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
@@ -50,0 +48,0 @@ } |
@@ -8,2 +8,3 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
@@ -13,2 +14,2 @@ * @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
*/ | ||
export declare const getDescendantDepth: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => IDescendantDepth<T>[]; | ||
export declare const getDescendantDepth: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => IDescendantDepth<TC>[]; |
@@ -1,7 +0,5 @@ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -14,2 +12,3 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
@@ -50,3 +49,3 @@ * @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
if (depthToMatch >= 0) { | ||
output = __spreadArrays(output, [{ ancestor: child, depthToMatch: depthToMatch }]); | ||
output = __spreadArray(__spreadArray([], output), [{ ancestor: child, depthToMatch: depthToMatch }]); | ||
} | ||
@@ -53,0 +52,0 @@ } |
@@ -1,7 +0,5 @@ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -73,3 +71,3 @@ import * as React from 'react'; | ||
if (depthToMatch >= 0) { | ||
output = __spreadArrays(output, [{ ancestor: child, depthToMatch: depthToMatch }]); | ||
output = __spreadArray(__spreadArray([], output), [{ ancestor: child, depthToMatch: depthToMatch }]); | ||
} | ||
@@ -76,0 +74,0 @@ } |
@@ -7,2 +7,3 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
@@ -15,3 +16,3 @@ * @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
*/ | ||
export declare const removeChildren: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T[]; | ||
export declare const removeChildren: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC[]; | ||
/** | ||
@@ -22,4 +23,5 @@ * Removes all children by specified predicate (deep search) | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All non-matching children | ||
@@ -30,2 +32,2 @@ * @example | ||
*/ | ||
export declare const removeChildrenDeep: <T = React.ReactNode>(children: T, predicate: (child: T) => boolean) => T[]; | ||
export declare const removeChildrenDeep: <T = React.ReactNode, TC = React.ReactNode>(children: T, predicate: (child: TC) => boolean) => TC[]; |
@@ -1,7 +0,5 @@ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -14,2 +12,3 @@ import * as React from 'react'; | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
@@ -30,4 +29,5 @@ * @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @template T | ||
* @template TC - Type of child | ||
* @param {T} children - JSX children | ||
* @param {(child: T) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @param {(child: TC) => boolean} predicate - The predicate to determine if the given child is a match | ||
* @returns {T[]} - All non-matching children | ||
@@ -46,3 +46,3 @@ * @example | ||
if ((_a = child.props) === null || _a === void 0 ? void 0 : _a.children) { | ||
output = __spreadArrays(output, [ | ||
output = __spreadArray(__spreadArray([], output), [ | ||
Object.assign(child, { | ||
@@ -58,3 +58,3 @@ props: Object.assign(child.props, { | ||
else { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
@@ -61,0 +61,0 @@ } |
@@ -1,7 +0,5 @@ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
@@ -84,3 +82,3 @@ import * as React from 'react'; | ||
if ((_b = child.props) === null || _b === void 0 ? void 0 : _b.children) { | ||
output = __spreadArrays(output, [ | ||
output = __spreadArray(__spreadArray([], output), [ | ||
Object.assign({}, child, { | ||
@@ -96,3 +94,3 @@ props: Object.assign({}, child.props, { | ||
else { | ||
output = __spreadArrays(output, [child]); | ||
output = __spreadArray(__spreadArray([], output), [child]); | ||
} | ||
@@ -99,0 +97,0 @@ } |
{ | ||
"name": "react-nanny", | ||
"version": "2.8.0", | ||
"version": "2.9.0", | ||
"description": "Utils to manage your React Children; find and filter children by type or custom function, enforce child content, and more!", | ||
@@ -5,0 +5,0 @@ "main": "lib/es5/index.js", |
@@ -20,3 +20,3 @@ [![Build Status](https://travis-ci.com/TheSpicyMeatball/react-nanny.svg?branch=main)](https://travis-ci.com/TheSpicyMeatball/react-nanny) | ||
<p><b>Version:</b> 2.7.0</p> | ||
<p><b>Version:</b> 2.9.0</p> | ||
@@ -128,4 +128,4 @@ <h3>Dependencies</h3> | ||
└───/getChild | ||
└───index.d.ts - 1.1 KB | ||
└───index.js - 1.73 KB | ||
└───index.d.ts - 1.23 KB | ||
└───index.js - 1.81 KB | ||
└───/getChildByType | ||
@@ -135,19 +135,19 @@ └───index.d.ts - 4.16 KB | ||
└───/getChildren | ||
└───index.d.ts - 1.1 KB | ||
└───index.js - 2.11 KB | ||
└───index.d.ts - 1.21 KB | ||
└───index.js - 2.07 KB | ||
└───/getChildrenByType | ||
└───index.d.ts - 3.59 KB | ||
└───index.js - 5.13 KB | ||
└───index.js - 5.03 KB | ||
└───/getChildrenWithDescendant | ||
└───index.d.ts - 579 Bytes | ||
└───index.js - 1.4 KB | ||
└───index.d.ts - 638 Bytes | ||
└───index.js - 1.31 KB | ||
└───/getChildrenWithDescendantByType | ||
└───index.d.ts - 2.26 KB | ||
└───index.js - 3.14 KB | ||
└───index.js - 3.02 KB | ||
└───/getDescendantDepth | ||
└───index.d.ts - 1.09 KB | ||
└───index.js - 2.54 KB | ||
└───index.d.ts - 1.14 KB | ||
└───index.js - 2.46 KB | ||
└───/getDescendantDepthByType | ||
└───index.d.ts - 2.39 KB | ||
└───index.js - 4.06 KB | ||
└───index.js - 3.93 KB | ||
└───index.d.ts - 1.08 KB | ||
@@ -162,7 +162,7 @@ └───index.js - 4.06 KB | ||
└───/removeChildren | ||
└───index.d.ts - 1.11 KB | ||
└───index.js - 2.61 KB | ||
└───index.d.ts - 1.22 KB | ||
└───index.js - 2.57 KB | ||
└───/removeChildrenByType | ||
└───index.d.ts - 3.71 KB | ||
└───index.js - 5.74 KB | ||
└───index.js - 5.63 KB | ||
└───/typeOfComponent | ||
@@ -178,4 +178,4 @@ └───index.d.ts - 614 Bytes | ||
└───/getChild | ||
└───index.d.ts - 1.1 KB | ||
└───index.js - 1.55 KB | ||
└───index.d.ts - 1.23 KB | ||
└───index.js - 1.63 KB | ||
└───/getChildByType | ||
@@ -185,19 +185,19 @@ └───index.d.ts - 4.16 KB | ||
└───/getChildren | ||
└───index.d.ts - 1.1 KB | ||
└───index.js - 1.91 KB | ||
└───index.d.ts - 1.21 KB | ||
└───index.js - 1.87 KB | ||
└───/getChildrenByType | ||
└───index.d.ts - 3.59 KB | ||
└───index.js - 4.85 KB | ||
└───index.js - 4.75 KB | ||
└───/getChildrenWithDescendant | ||
└───index.d.ts - 579 Bytes | ||
└───index.js - 1.22 KB | ||
└───index.d.ts - 638 Bytes | ||
└───index.js - 1.13 KB | ||
└───/getChildrenWithDescendantByType | ||
└───index.d.ts - 2.26 KB | ||
└───index.js - 2.93 KB | ||
└───index.js - 2.81 KB | ||
└───/getDescendantDepth | ||
└───index.d.ts - 1.09 KB | ||
└───index.js - 2.39 KB | ||
└───index.d.ts - 1.14 KB | ||
└───index.js - 2.3 KB | ||
└───/getDescendantDepthByType | ||
└───index.d.ts - 2.39 KB | ||
└───index.js - 3.86 KB | ||
└───index.js - 3.74 KB | ||
└───index.d.ts - 1.08 KB | ||
@@ -212,7 +212,7 @@ └───index.js - 886 Bytes | ||
└───/removeChildren | ||
└───index.d.ts - 1.11 KB | ||
└───index.js - 2.38 KB | ||
└───index.d.ts - 1.22 KB | ||
└───index.js - 2.34 KB | ||
└───/removeChildrenByType | ||
└───index.d.ts - 3.71 KB | ||
└───index.js - 5.43 KB | ||
└───index.js - 5.32 KB | ||
└───/typeOfComponent | ||
@@ -219,0 +219,0 @@ └───index.d.ts - 614 Bytes |
144636