Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tree-visit

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-visit - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

lib/__mocks__/node.d.ts

11

lib/index.d.ts

@@ -1,8 +0,13 @@

export * from './indexPath';
export * from './options';
export * from './visit';
export * from './access';
export * from './ancestors';
export * from './diagram';
export * from './find';
export * from './flat';
export * from './indexPath';
export * from './insert';
export * from './move';
export * from './options';
export { RemoveOptions, remove } from './remove';
export * from './sort';
export * from './visit';
export * from './withOptions';

@@ -13,9 +13,16 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./indexPath"), exports);
__exportStar(require("./options"), exports);
__exportStar(require("./visit"), exports);
exports.remove = void 0;
__exportStar(require("./access"), exports);
__exportStar(require("./ancestors"), exports);
__exportStar(require("./diagram"), exports);
__exportStar(require("./find"), exports);
__exportStar(require("./flat"), exports);
__exportStar(require("./indexPath"), exports);
__exportStar(require("./insert"), exports);
__exportStar(require("./move"), exports);
__exportStar(require("./options"), exports);
var remove_1 = require("./remove");
Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return remove_1.remove; } });
__exportStar(require("./sort"), exports);
__exportStar(require("./visit"), exports);
__exportStar(require("./withOptions"), exports);

@@ -15,6 +15,7 @@ "use strict";

var _a, _b;
indexPath = [0, ...indexPath];
const key = indexPath.join();
// Add a 0 so we can always slice off the last element to get a unique parent key
const keyIndexPath = [0, ...indexPath];
const key = keyIndexPath.join();
const transformed = options.transform(child, (_a = childrenMap[key]) !== null && _a !== void 0 ? _a : [], indexPath);
const parentKey = indexPath.slice(0, -1).join();
const parentKey = keyIndexPath.slice(0, -1).join();
const parentChildren = (_b = childrenMap[parentKey]) !== null && _b !== void 0 ? _b : [];

@@ -21,0 +22,0 @@ parentChildren.push(transformed);

@@ -5,1 +5,7 @@ import { IndexPath } from './indexPath';

};
export declare type MutationBaseOptions<T> = BaseOptions<T> & {
/**
* Create a new node based on the original node and its new children
*/
create: (node: T, children: T[], indexPath: IndexPath) => T;
};

@@ -5,5 +5,8 @@ import { DiagramOptions } from './diagram';

import { IndexPath } from './indexPath';
import { InsertOptions } from './insert';
import { MapOptions } from './map';
import { BaseOptions } from './options';
import { MoveOptions } from './move';
import { BaseOptions, MutationBaseOptions } from './options';
import { ReduceOptions } from './reduce';
import { RemoveOptions } from './remove';
import { VisitOptions } from './visit';

@@ -75,3 +78,21 @@ declare type WithoutBase<O> = Omit<O, keyof BaseOptions<unknown>>;

visit(node: T, options: WithoutBase<VisitOptions<T>>): void;
/**
* Insert nodes at a given `IndexPath`.
*/
insert(node: T, options: WithoutBase<InsertOptions<T>>): T;
/**
* Remove nodes at the given `IndexPath`s.
*/
remove(node: T, options: WithoutBase<RemoveOptions<T>>): T;
/**
* Move nodes from one `IndexPath` to another.
*/
move(node: T, options: WithoutBase<MoveOptions<T>>): T;
};
declare type WithoutMutationBase<O> = Omit<O, keyof MutationBaseOptions<unknown>>;
export declare type WithMutationOptions<T> = Omit<WithOptions<T>, 'insert' | 'remove' | 'move'> & {
insert: (node: T, options: WithoutMutationBase<InsertOptions<T>>) => T;
remove: (node: T, options: WithoutMutationBase<RemoveOptions<T>>) => T;
move: (node: T, options: WithoutMutationBase<MoveOptions<T>>) => T;
};
/**

@@ -83,2 +104,3 @@ * Return every tree utility function with options partially applied.

export declare function withOptions<T>(baseOptions: BaseOptions<T>): WithOptions<T>;
export declare function withOptions<T>(baseOptions: MutationBaseOptions<T>): WithMutationOptions<T>;
export {};

@@ -9,11 +9,9 @@ "use strict";

const flatMap_1 = require("./flatMap");
const insert_1 = require("./insert");
const map_1 = require("./map");
const move_1 = require("./move");
const reduce_1 = require("./reduce");
const remove_1 = require("./remove");
const visit_1 = require("./visit");
/**
* Return every tree utility function with options partially applied.
*
* @param baseOptions
*/
function withOptions(baseOptions) {
function withOptionsBase(baseOptions) {
return {

@@ -44,4 +42,17 @@ access: (node, indexPath) => (0, access_1.access)(node, indexPath, baseOptions),

: (0, visit_1.visit)(node, Object.assign(Object.assign({}, baseOptions), onEnterOrOptions)),
insert: (node, options) => (0, insert_1.insert)(node, Object.assign(Object.assign({}, baseOptions), options)),
remove: (node, options) => (0, remove_1.remove)(node, Object.assign(Object.assign({}, baseOptions), options)),
move: (node, options) => (0, move_1.move)(node, Object.assign(Object.assign({}, baseOptions), options)),
};
}
function withMutationOptions(baseOptions) {
const tree = withOptionsBase(baseOptions);
return Object.assign(Object.assign({}, tree), { insert: (node, options) => (0, insert_1.insert)(node, Object.assign(Object.assign({}, baseOptions), options)), remove: (node, options) => (0, remove_1.remove)(node, Object.assign(Object.assign({}, baseOptions), options)), move: (node, options) => (0, move_1.move)(node, Object.assign(Object.assign({}, baseOptions), options)) });
}
function withOptions(baseOptions) {
if ('create' in baseOptions) {
return withMutationOptions(baseOptions);
}
return withOptionsBase(baseOptions);
}
exports.withOptions = withOptions;
{
"name": "tree-visit",
"version": "0.1.4",
"version": "0.2.0",
"description": "A tree traversal library.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc