@types/traverse

  • Version 0.6.36
  • Published
  • 9.45 kB
  • No dependencies
  • MIT license

Install

npm i @types/traverse
yarn add @types/traverse
pnpm add @types/traverse

Overview

TypeScript definitions for traverse

Index

Functions

function clone

clone: <T>(obj: T) => T;
  • Create a deep clone of the object.

function forEach

forEach: (obj: any, cb: (this: TraverseContext, v: any) => void) => any;
  • Execute fn for each node in the object but unlike .map(), when this.update() is called it updates the object in-place.

function get

get: (obj: any, path: string[]) => any;
  • Get the element at the array path.

function has

has: (obj: any, path: string[]) => boolean;
  • Return whether the element at the array path exists.

function map

map: (obj: any, cb: (this: TraverseContext, v: any) => void) => any;
  • Execute fn for each node in the object and return a new object with the results of the walk. To update nodes in the result use this.update(value).

function nodes

nodes: (obj: any) => any[];
  • Return an Array of every node in the object.

function paths

paths: (obj: any) => string[][];
  • Return an Array of every possible non-cyclic path in the object. Paths are Arrays of string keys.

function reduce

reduce: (
obj: any,
cb: (this: TraverseContext, acc: any, v: any) => void,
init?: any
) => any;
  • For each node in the object, perform a [left-fold](http://en.wikipedia.org/wiki/Fold_(higher-order_function)) with the return value of fn(acc, node).

    If init isn't specified, init is set to the root object for the first step and the root element is skipped.

function set

set: (obj: any, path: string[], value: any) => any;
  • Set the element at the array path to value.

function traverse

traverse: typeof traverse;

    Interfaces

    interface Traverse

    interface Traverse<T> {}

      method clone

      clone: () => T;
      • Create a deep clone of the object.

      method forEach

      forEach: (cb: (this: TraverseContext, v: any) => void) => any;
      • Execute fn for each node in the object but unlike .map(), when this.update() is called it updates the object in-place.

      method get

      get: (path: string[]) => any;
      • Get the element at the array path.

      method has

      has: (path: string[]) => boolean;
      • Return whether the element at the array path exists.

      method map

      map: (cb: (this: TraverseContext, v: any) => void) => any;
      • Execute fn for each node in the object and return a new object with the results of the walk. To update nodes in the result use this.update(value).

      method nodes

      nodes: () => any[];
      • Return an Array of every node in the object.

      method paths

      paths: () => string[][];
      • Return an Array of every possible non-cyclic path in the object. Paths are Arrays of string keys.

      method reduce

      reduce: (
      cb: (this: TraverseContext, acc: any, v: any) => void,
      init?: any
      ) => any;
      • For each node in the object, perform a [left-fold](http://en.wikipedia.org/wiki/Fold_(higher-order_function)) with the return value of fn(acc, node).

        If init isn't specified, init is set to the root object for the first step and the root element is skipped.

      method set

      set: (path: string[], value: any) => any;
      • Set the element at the array path to value.

      interface TraverseContext

      interface TraverseContext {}

        property circular

        circular: TraverseContext | undefined;
        • If the node equals one of its parents, the circular attribute is set to the context of that parent and the traversal progresses no deeper.

        property isLeaf

        isLeaf: boolean;
        • Whether or not the present node is a leaf node (has no children)

        property isRoot

        isRoot: boolean;
        • Whether the present node is the root node

        property key

        key: string | undefined;
        • The name of the key of the present node in its parent. This is undefined for the root node.

        property keys

        keys: string[] | null;
        • Object keys of the node.

        property level

        level: number;
        • Depth of the node within the traversal

        property node

        node: any;
        • The present node on the recursive walk

        property notLeaf

        notLeaf: boolean;
        • Whether or not the present node is not a leaf node (has children)

        property notRoot

        notRoot: boolean;
        • Whether the present node is not the root node

        property parent

        parent: TraverseContext | undefined;
        • The context of the node's parent. This is undefined for the root node.

        property parents

        parents: TraverseContext[];
        • The contexts of the node's parents.

        property path

        path: string[];
        • An array of string keys from the root to the present node

        method after

        after: (callback: (this: TraverseContext, value: any) => void) => void;
        • Call this function after all of the children are traversed.

        method before

        before: (callback: (this: TraverseContext, value: any) => void) => void;
        • Call this function before all of the children are traversed. You can assign into this.keys here to traverse in a custom order.

        method block

        block: () => void;
        • Prevents traversing descendents of the current node.

        method delete

        delete: (stopHere?: boolean) => void;
        • Delete the current element from its parent in the output. Calls delete even on Arrays.

        method post

        post: (callback: (this: TraverseContext, child: any) => void) => void;
        • Call this function after each of the children are traversed.

        method pre

        pre: (callback: (this: TraverseContext, child: any, key: any) => void) => void;
        • Call this function before each of the children are traversed.

        method remove

        remove: (stopHere?: boolean) => void;
        • Remove the current element from the output. If the node is in an Array it will be spliced off. Otherwise it will be deleted from its parent.

        method stop

        stop: () => void;
        • Stops traversal entirely.

        method update

        update: (value: any, stopHere?: boolean) => void;
        • Set a new value for the present node.

          All the elements in value will be recursively traversed unless stopHere is true (false by default).

        Package Files (1)

        Dependencies (0)

        No dependencies.

        Dev Dependencies (0)

        No dev dependencies.

        Peer Dependencies (0)

        No peer dependencies.

        Badge

        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/traverse.

        • Markdown
          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/traverse)
        • HTML
          <a href="https://www.jsdocs.io/package/@types/traverse"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>