async-traverse-tree
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

async-traverse-tree

npm version Build Status Coverage Status License

async-traverse-tree is a lightweight, asynchronous library for traversing and mapping tree-like data structures.

Features

  • Asynchronously traverses and modifies objects and arrays.
  • Easy-to-use API for applying custom functions to each value in the tree.
  • Prevents circular references to maintain data integrity.

Installation

You can install async-traverse-tree using npm or yarn:

npm install async-traverse-tree

or

yarn add async-traverse-tree

Usage

Here's a simple example of how to use async-traverse-tree with the updated implementation:

// Import the 'traverse' function from 'async-traverse-tree'
import { traverse } from 'async-traverse-tree';

// Define a custom mapper function
const mapper = async (key, value) => {
  // Apply your custom logic here asynchronously
  return value;
};

// Your data structure
const data = /* Your data structure here */;

// Asynchronously traverse and map the data
traverse(data, mapper)
  .then(result => {
    // Process the result
    console.log(result);
  })
  .catch(error => {
    console.error(error);
  });

Motivation

An easy way to iterate over an object-like structure is to use JSON.parse(JSON.stringify(obj), (key, value) => ... ).
The problem with this approach is that it can't handle circular references and is synchronous. async-traverse-tree can act like an async drop-in replacement for that which can also handle circular references.

Package Sidebar

Install

npm i async-traverse-tree

Weekly Downloads

77

Version

1.0.1

License

MIT

Unpacked Size

6.96 kB

Total Files

5

Last publish

Collaborators

  • bezoerb