Socket
Socket
Sign inDemoInstall

dree

Package Overview
Dependencies
Maintainers
1
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dree - npm Package Compare versions

Comparing version 4.5.8 to 4.6.0

24

bundled/lib/index.d.ts

@@ -26,3 +26,3 @@ import { BinaryToTextEncoding } from 'crypto';

* Returns a string representation of a Directory Tree given a path to a directory or file
* @param {string} dirTree The path which you want to inspect
* @param {string} path The path which you want to inspect
* @param {object} options An object used as options of the function

@@ -57,7 +57,8 @@ * @return {string} A string representing the Directory Tree of the given path

* @param {object} options An object used as options of the function
* @param {function} onFile A function called when a file is added - has the tree object and its stat as parameters
* @param {function} onDir A function called when a dir is added - has the tree object and its stat as parameters
* @param {function} onFile A function called when a file is added. It has the tree object and its stat as parameters. The object can me changed and extended here, on typescript there the function uses indeed generics.
* @param {function} onDir A function called when a dir is added. It has the tree object and its stat as parameters. The object can me changed and extended here, on typescript there the function uses indeed generics.
* @return {object} The directory tree as a Dree object
* @template Node The type of the tree object, which can be extended and changed by the onFile and onDir functions.
*/
export declare function scan(path: string, options?: ScanOptions, onFile?: Callback, onDir?: Callback): Dree;
export declare function scan<Node extends Dree = Dree>(path: string, options?: ScanOptions, onFile?: Callback<Node>, onDir?: Callback<Node>): Node;
/**

@@ -70,4 +71,5 @@ * Returns in a promise the Directory Tree of a given path. This function is asynchronous.

* @return {Promise<object>} A promise to the directory tree as a Dree object
* @template Node The type of the tree object, which can be extended and changed by the onFile and onDir functions.
*/
export declare function scanAsync(path: string, options?: ScanOptions, onFile?: CallbackAsync, onDir?: CallbackAsync): Promise<Dree>;
export declare function scanAsync<Node extends Dree = Dree>(path: string, options?: ScanOptions, onFile?: CallbackAsync<Node>, onDir?: CallbackAsync<Node>): Promise<Node>;
/**

@@ -271,9 +273,13 @@ * Interface of an object representing a Directory Tree

/**
* Callback used by [[scan]] when a file or dir is encountered
* Callback used by [[scan]] when a file or dir is encountered.
* Note that it can extend the node that will be returned in the directory tree.
* @template Node The type of the tree object, which can be extended and changed by the onFile and onDir functions.
*/
export type Callback = (dirTree: Dree, stat: Stats) => void;
export type Callback<Node extends Dree = Dree> = (dirTree: Node, stat: Stats) => void;
/**
* Callback used by [[scanAsync]] when a file or dir is encountered
* Callback used by [[scanAsync]] when a file or dir is encountered.
* Note that it can extend the node that will be returned in the directory tree.
* @template Node The type of the tree object, which can be extended and changed by the onFile and onDir functions.
*/
export type CallbackAsync = (dirTree: Dree, stat: Stats) => void | Promise<void>;
export type CallbackAsync<Node extends Dree = Dree> = (dirTree: Node, stat: Stats) => void | Promise<void>;
/**

@@ -280,0 +286,0 @@ * Function used to sort paths

# [4.6.0](https://github.com/euberdeveloper/dree/compare/4.5.8...4.6.0) (2023-12-07)
### Features
* add typings to extend nodes on file or dir ([3e4418f](https://github.com/euberdeveloper/dree/commit/3e4418fac0e86da6126cc19afc306b8ec6b22b20))
## [4.5.8](https://github.com/euberdeveloper/dree/compare/4.5.7...4.5.8) (2023-12-07)

@@ -4,0 +11,0 @@

{
"name": "dree",
"version": "4.5.8",
"version": "4.6.0",
"description": "A nodejs module wich helps you handle a directory tree providing you its abstraction through tested functions and a custom configuration.",

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

@@ -110,2 +110,26 @@ ![Test](https://github.com/euberdeveloper/dree/workflows/Test/badge.svg)

With typescript and by changing the objects onDir and onFile:
```ts
import * as dree from 'dree';
interface CustomResult extends dree.Dree {
description: string;
}
const options: dree.Options = {
stat: false
};
const fileCallback: dree.Callback<CustomResult> = function (node, stat) {
node.description = `${node.name} (${node.size})`;
};
const dirCallback: dree.Callback<CustomResult> = function (node, stat) {
node.description = `${node.name} (${node.size})`;
};
const tree: CustomResult = dree.scan<CustomResult>('./folder', options, fileCallback, dirCallback);
```
### Get a string

@@ -349,4 +373,4 @@

* __options__: Optional. Is of type `object` and allows you to customize the function behaviour.
* __fileCallback__: Optional. Called each time a file is added to the tree. It provides you the node, which **reflects** the fiven options, and its status returned by fs.stat (fs.lstat if `followLinks` option is enabled).
* __dirCallback__: Optional. Called each time a directory is added to the tree. It provides you the node, which **reflects** the fiven options, and its status returned by fs.lstat (fs.stat if `followLinks` option is enabled).
* __fileCallback__: Optional. Called each time a file is added to the tree. It provides you the node, which **reflects** the given options, and its status returned by fs.stat (fs.lstat if `followLinks` option is enabled). Note that it can be used also to modify the node (only by extending it) and that there are generics typings for it.
* __dirCallback__: Optional. Called each time a directory is added to the tree. It provides you the node, which **reflects** the given options, and its status returned by fs.lstat (fs.stat if `followLinks` option is enabled). Note that it can be used also to modify the node (only by extending it) and that there are generics typings for it.

@@ -417,4 +441,4 @@ **Options parameters:**

* __options__: Optional. Is of type `object` and allows you to customize the function behaviour.
* __fileCallback__: Optional. Called each time a file is added to the tree. It provides you the node, which **reflects** the fiven options, and its status returned by fs.stat (fs.lstat if `followLinks` option is enabled). The callback can be an **async function**.
* __dirCallback__: Optional. Called each time a directory is added to the tree. It provides you the node, which **reflects** the fiven options, and its status returned by fs.lstat (fs.stat if `followLinks` option is enabled). The callback can be an **async function**.
* __fileCallback__: Optional. Called each time a file is added to the tree. It provides you the node, which **reflects** the given options, and its status returned by fs.stat (fs.lstat if `followLinks` option is enabled). The callback can be an **async function**. Note that it can be used also to modify the node (only by extending it) and that there are generics typings for it.
* __dirCallback__: Optional. Called each time a directory is added to the tree. It provides you the node, which **reflects** the given options, and its status returned by fs.lstat (fs.stat if `followLinks` option is enabled). The callback can be an **async function**. Note that it can be used also to modify the node (only by extending it) and that there are generics typings for it.

@@ -565,2 +589,3 @@ **Options parameters:**

dree
├── .env.example
├── .release-it.json

@@ -567,0 +592,0 @@ ├── CHANGELOG.md

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