Skip to content

Commit

Permalink
chore(release): 1.4.0
Browse files Browse the repository at this point in the history
# [1.4.0](v1.3.6...v1.4.0) (2022-04-26)

### Features

* add walk/getByPath methods to file tree ([#19](#19)) ([852e150](852e150))
  • Loading branch information
semantic-release-bot committed Apr 26, 2022
1 parent 852e150 commit 7caa924
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 21 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [1.4.0](https://github.com/jaredLunde/exploration/compare/v1.3.6...v1.4.0) (2022-04-26)


### Features

* add walk/getByPath methods to file tree ([#19](https://github.com/jaredLunde/exploration/issues/19)) ([852e150](https://github.com/jaredLunde/exploration/commit/852e1501e658ac22c80b36a4454d3e68e60316ac))

## [1.3.6](https://github.com/jaredLunde/exploration/compare/v1.3.5...v1.3.6) (2022-04-25)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "exploration",
"version": "1.3.6",
"version": "1.4.0",
"description": "",
"license": "MIT",
"author": "Jared Lunde <[email protected]> (https://jaredlunde.com/)",
Expand Down
54 changes: 39 additions & 15 deletions types/file-tree.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ export declare class FileTree<Meta = {}> extends Tree<FileTreeData<Meta>> {
comparator: (a: FileTreeNode<Meta>, b: FileTreeNode<Meta>) => number;
root: Dir<Meta>;
});
/**
* Get a node in the tree by its path. Note that this requires walking the tree,
* which has O(n) complexity. It should therefore be avoided unless absolutely necessary.
*
* @param path - The path to search for in the tree
*/
getByPath(path: string): FileTreeNode<Meta> | undefined;
/**
* Walks the tree starting at a given directory and calls a visitor
* function for each node.
*
* @param dir - The directory to walk
* @param visitor - A function that is called for each node in the tree. Returning
* `false` will stop the walk.
* @example
* tree.walk(tree.root, node => {
* console.log(node.path);
*
* if (node.path === '/foo/bar') {
* return false
* }
* })
*/
walk(dir: Dir<Meta>, visitor: (node: FileTreeNode<Meta>, parent: FileTreeNode<Meta>) => boolean | void): void;
/**
* Produce a new tree with the given function applied to the given node.
* This is similar to `immer`'s produce function as you're working on a draft
Expand Down Expand Up @@ -125,6 +149,8 @@ export declare class FileTree<Meta = {}> extends Tree<FileTreeData<Meta>> {
}
export declare class File<Meta = {}> extends Leaf<FileTreeData<Meta>> {
readonly $$type = "file";
private _basenameName?;
private _basename?;
/**
* The parent directory of the file
*/
Expand All @@ -138,30 +164,32 @@ export declare class File<Meta = {}> extends Leaf<FileTreeData<Meta>> {
*/
get path(): string;
}
export declare class Prompt<Meta = {}> extends Leaf<FileTreeData<Meta>> {
readonly $$type = "prompt";
export declare class Dir<Meta = {}> extends Branch<FileTreeData<Meta>> {
readonly $$type = "dir";
private _basenameName?;
private _basename?;
/**
* The parent directory of this directory
*/
get parent(): Dir<Meta> | null;
/**
* The basename of the directory
*/
get basename(): string;
/**
* The full path of the prompt
* The full path of the directory
*/
get path(): string;
}
export declare class Dir<Meta = {}> extends Branch<FileTreeData<Meta>> {
readonly $$type = "dir";
export declare class Prompt<Meta = {}> extends Leaf<FileTreeData<Meta>> {
readonly $$type = "prompt";
/**
* The parent directory of this directory
*/
get parent(): Dir<Meta> | null;
/**
* The basename of the directory
*/
get basename(): string;
/**
* The full path of the directory
* The full path of the prompt
*/
get path(): string;
}
Expand All @@ -177,9 +205,7 @@ export declare function defaultComparator(a: FileTreeNode, b: FileTreeNode): num
*
* @param treeNode - A tree node
*/
export declare function isPrompt<Meta>(treeNode: FileTreeNode<Meta>): treeNode is Prompt<Meta> & {
readonly $$type: "prompt";
};
export declare function isPrompt<Meta>(treeNode: FileTreeNode<Meta>): treeNode is Prompt<Meta>;
/**
* Returns `true` if the given node is a file
*
Expand All @@ -192,9 +218,7 @@ export declare function isFile<Meta>(treeNode: FileTreeNode<Meta>): treeNode is
* @param treeNode - A tree node
*/
export declare function isDir<Meta>(treeNode: FileTreeNode<Meta>): treeNode is Dir<Meta>;
export declare type FileTreeNode<Meta = {}> = File<Meta> | Dir<Meta> | (Prompt<Meta> & {
readonly $$type: "prompt";
});
export declare type FileTreeNode<Meta = {}> = File<Meta> | Dir<Meta> | Prompt<Meta>;
export declare type FileTreeData<Meta = {}> = {
name: string;
meta?: Meta;
Expand Down
5 changes: 3 additions & 2 deletions types/path-fx.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export declare const SEP = "/";
/**
* Returns `true` if the path is relative.
*
Expand All @@ -24,8 +25,8 @@ export declare function relative(from: string, to: string): string;
*/
export declare function split(path: string): string[];
/**
* Normalize a path, taking care of `..` and `.`, and removing redundant slashes.
* Unlike Node's `path`, this removes any trailing slashes.
* Normalize a path, taking care of `..` and `.`, and removing redundant slashes
* while preserving trailing slashes.
*
* @param path - The path to normalize.
*/
Expand Down
2 changes: 1 addition & 1 deletion types/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions types/use-file-tree-snapshot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import type { FileTreeSnapshot } from "./types";
* file tree when you initially load it.
*
* @param fileTree - A file tree
* @param callback - A callback that handles the file tree snapshot
* @param observer - A callback that handles the file tree snapshot
*/
export declare function useFileTreeSnapshot<Meta>(fileTree: FileTree<Meta>, callback: (state: FileTreeSnapshot) => Promise<void> | void): void;
export declare function useFileTreeSnapshot<Meta>(fileTree: FileTree<Meta>, observer: (state: FileTreeSnapshot) => Promise<void> | void): void;

0 comments on commit 7caa924

Please sign in to comment.