directory-tree
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -21,2 +21,3 @@ import { Stats } from 'fs'; | ||
isSymbolicLink?: boolean; | ||
custom: { [key: string]: any }; | ||
} | ||
@@ -23,0 +24,0 @@ export interface DirectoryTreeOptions { |
{ | ||
"name": "directory-tree", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Convert a directory tree to a JS object.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -169,2 +169,29 @@ [![Build Status](https://api.travis-ci.com/mihneadb/node-directory-tree.svg?branch=master)](https://api.travis-ci.com/mihneadb/node-directory-tree.svg?branch=master) | ||
## Adding custom fields | ||
You can easily extend a `DirectoryTree` object with custom fields by adding them to the custom field. | ||
For example add an `id` based on the path of a `DirectoryTree` object for each directory and file like so: | ||
``` | ||
import { createHash } from 'crypto'; | ||
import * as directoryTree from 'directory-tree'; | ||
import { DirectoryTree, DirectoryTreeOptions, DirectoryTreeCallback } from 'directory-tree'; | ||
const callback: DirectoryTreeCallback = ( | ||
item: DirectoryTree, | ||
path: string | ||
) => { | ||
item.custom.id = createHash('sha1').update(path).digest('base64'); | ||
}; | ||
const dirTree: DirectoryTree & { id?: string } = directoryTree( | ||
"<your-directory-path>", | ||
{}, | ||
callback, | ||
callback | ||
); | ||
// to explore the object with the new custom fields | ||
console.log(JSON.stringify(dirTree, null, 2)); | ||
``` | ||
## Note | ||
@@ -171,0 +198,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17572
264
237