
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
return-tree-objects-path
Advanced tools
A utility to recursively find paths in a list of objects
The Return Tree Objects Path Library is a utility that allows you to recursively find paths in a list of objects based on a specified target key and value. It provides a simple and flexible way to traverse and search through complex object structures, enabling you to retrieve paths from the root to the target.
You can install the Return Tree Objects Path Library via npm. Make sure you have Node.js and npm installed. Then, run the following command:
npm install return-tree-objects-path
import { returnTreeObjectsPath } from 'return-tree-objects-path';
// Sample usage
const objects = [
{
id: 1,
name: 'Parent',
children: [
{
id: 2,
name: 'Child 1',
children: [],
},
{
id: 3,
name: 'Child 2',
children: [
{
id: 4,
name: 'Grandchild 1',
children: [],
},
],
},
],
},
];
const paths = returnTreeObjectsPath(objects, 'id', 4, 'children');
console.log(paths);
[
{ "id": 1, "name": "Parent" },
{ "id": 3, "name": "Child 2" },
{ "id": 4, "name": "Grandchild 1" }
]
returnTreeObjectsPath(objects, targetKey, targetValue, childrenProperty)
Recursively finds paths in a list of objects based on a specified target key and value.
objects
: An array of objects to search through.targetKey
: The key to search for in the objects.targetValue
: The value to find in the objects based on the target key.childrenProperty
: The property name representing the children of each object.Returns an array of objects representing the path from the root to the target.
The Return Tree Objects Path Library can be useful for building breadcrumbs in a tree structure. Here's an example of how you can use the library to generate breadcrumbs from a hierarchical list of objects:
import { returnTreeObjectsPath } from 'return-tree-objects-path';
// Sample data representing a tree structure
const categories = [
{
id: 1,
name: 'Home',
children: [
{
id: 2,
name: 'Products',
children: [
{
id: 3,
name: 'Laptops',
children: [
{
id: 4,
name: 'Gaming Laptops',
children: [],
},
{
id: 5,
name: 'Business Laptops',
children: [],
},
],
},
{
id: 6,
name: 'Smartphones',
children: [],
},
],
},
{
id: 7,
name: 'About Us',
children: [],
},
],
},
];
We welcome contributions! If you find a bug or have a suggestion, please open an issue or create a pull request.
This project is licensed under the MIT License - see the LICENSE.md file for details.
FAQs
A utility to recursively find paths in a list of objects
The npm package return-tree-objects-path receives a total of 2 weekly downloads. As such, return-tree-objects-path popularity was classified as not popular.
We found that return-tree-objects-path demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.