-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
223 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// | ||
├── Jenkinsfile | ||
├── LICENSE | ||
├── config.js | ||
├── .git | ||
│ ├── articles | ||
│ └── utils | ||
├── functions | ||
├── src | ||
│ ├── articles | ||
│ ├── components | ||
│ │ ├── builder | ||
│ │ │ ├── center | ||
│ │ │ ├── left | ||
│ │ │ │ └── sections-asdf //sdfa | ||
│ │ │ ├── lists.sdf | ||
│ │ │ └── right | ||
│ │ │ └── sections.txt | ||
│ │ ├── dashboard.js | ||
│ │ ├── landing.ts | ||
│ │ ├── router.jsx | ||
│ │ └── shared | ||
│ └── utils | ||
└── static.xzxxx | ||
└── images | ||
├── screenshots | ||
└── templates.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// | ||
├── Jenkinsfile | ||
├── LICENSE | ||
├── config.js | ||
├── .git | ||
│ ├── articles | ||
│ └── utils | ||
├── functions | ||
├── src | ||
│ └── articles | ||
│ └── components | ||
│ └── utils | ||
└── static.xzxxx | ||
└── images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// | ||
├── functions | ||
├── src | ||
│ ├── articles | ||
│ ├── components | ||
│ │ ├── builder | ||
│ │ │ ├── center | ||
│ │ │ ├── left | ||
│ │ │ │ └── sections-asdf //sdfa | ||
│ │ │ └── right | ||
│ │ └── shared | ||
│ └── utils | ||
└── static.xzxxx | ||
└── images | ||
└── screenshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// | ||
├── .git | ||
│ ├── articles | ||
│ └── utils | ||
├── functions | ||
├── src | ||
│ ├── articles | ||
│ ├── components | ||
│ │ ├── builder | ||
│ │ │ ├── center | ||
│ │ │ ├── left | ||
│ │ │ │ └── sections-asdf //sdfa | ||
│ │ │ └── right | ||
│ │ └── shared | ||
│ └── utils | ||
└── static.xzxxx | ||
└── images | ||
└── screenshots |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,54 @@ | ||
import { getBranchPrefix } from "./utils"; | ||
import { ISettings, TreeType } from "./types"; | ||
import { defaultSettings, ISettings, TreeType } from "./types"; | ||
// @ts-ignore | ||
import isNondot from "@structure-codes/is-nondot"; | ||
|
||
/** | ||
* Converts JSON representation of a tree back to string format | ||
* @param tree | ||
* @param {TreeType[]} tree - The tree to convert to a string | ||
* @param {string} tabChar - The character(s) used to represent a tab in the string output (optional) | ||
* @param {ISettings} options - Parameters which can influence how the output string is generated (optional) | ||
* @returns string format of tree | ||
*/ | ||
export const treeJsonToString = (tree: TreeType[], tabChar = " ", options?: ISettings): string => { | ||
export const treeJsonToString = ({ | ||
tree, | ||
tabChar = " ", | ||
options = defaultSettings, | ||
}: { | ||
tree: TreeType[]; | ||
tabChar?: string; | ||
options?: ISettings; | ||
}): string => { | ||
let treeString = ""; | ||
const parseBranches = (tree: TreeType[], depth: boolean[]) => { | ||
tree.forEach((branch, index) => { | ||
// Hide all dot files and directories in output | ||
if ( | ||
options.hideDots && | ||
(branch.name.startsWith(".") || isNondot(branch.name)) | ||
) | ||
return; | ||
// Hide all files in output | ||
// Note: All leaves with 0 children may not be directories, so we do our best to infer here | ||
if ( | ||
options.hideFiles && | ||
branch.children.length === 0 && | ||
(branch.name.includes(".") || isNondot(branch.name)) | ||
) | ||
return; | ||
// Hide leaves below a certain depth | ||
if (options.depth > 0 && depth.length + 1 > options.depth) return; | ||
|
||
const isLastBranch = index === tree.length - 1; | ||
const prefix = getBranchPrefix(depth, isLastBranch, tabChar); | ||
const branchString = prefix + branch.name + "\n"; | ||
treeString = treeString.concat(branchString); | ||
if (!branch.children) return; | ||
parseBranches(branch.children, [...depth, isLastBranch]); | ||
const newDepth = [...depth, isLastBranch]; | ||
parseBranches(branch.children, newDepth); | ||
}); | ||
}; | ||
parseBranches(tree, []); | ||
treeString = treeString.replace(/\n$/, ""); | ||
|
||
return treeString; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
export interface TreeType { | ||
_index: number; | ||
name: string; | ||
index: number; | ||
children: TreeType[] | ||
attributes?: Record<string, string | number | boolean>, | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
export interface ISettings { | ||
/** | ||
* depth - How deep in the tree to print | ||
*/ | ||
depth: number; | ||
/** | ||
* hideFiles - Whether or not to hide all files in output | ||
*/ | ||
hideFiles: boolean; | ||
hideDotDirs: boolean; | ||
/** | ||
* hideDots - Whether or not to hide dot directories and files in the output | ||
*/ | ||
hideDots: boolean; | ||
} | ||
|
||
export const defaultSettings: ISettings = { | ||
depth: 0, | ||
hideFiles: false, | ||
hideDots: false, | ||
}; |