tory
Your directory utility belt
Install
$ npm install tory
Usage
const ToryFile ToryFolder = ; // This example assumes your current working directory is this// repo itself (although you can also pass absolute paths)const source = 'source'; for const filer of source // 'filer' is a term which means 'file or folder' console;// Visited: index.ts (file)// Visited: tory-file.ts (file)// Visited: tory-folder.ts (file)// Visited: helpers (folder) for const filer of source console;// Visited: index.ts (file)// Visited: tory-file.ts (file)// Visited: tory-folder.ts (file)// Visited: helpers (folder)// Visited: iterable-from-tory-folder.ts (file)// Visited: sort-lexicographically.ts (file)// Visited: tory-error.ts (file)// Visited: tory-filer.ts (file)// Visited: tory-folder-diff.ts (file) const package = 'package.json';console;console;console;// package.json - sha256: ce472d76d57b62c8e38993becd6d78fd11d6df2da800be8214a759c524edfcb4// package.json - size (bytes): 1518// package.json - modify time: 2020-02-24T00:23:30.617Z const projectRoot = '.';const customProjectIterable = projectRoot;for const filer of customProjectIterable if filertype === 'file' && !filername continue; console;// Visited: .git (folder)// Visited: dist (folder)// Visited: node_modules (folder)// Visited: index.ts (file)// Visited: tory-file.ts (file)// Visited: tory-folder.ts (file)// Visited: iterable-from-tory-folder.ts (file)// Visited: sort-lexicographically.ts (file)// Visited: tory-error.ts (file)// Visited: tory-filer.ts (file)// Visited: tory-folder-diff.ts (file)// Visited: helpers (folder)// Visited: source (folder)// Visited: test.ts (file)// Visited: attempt-delete.ts (file)// Visited: get-random-numbers-with-sum-constraint.ts (file)// Visited: get-random-test-folder.ts (file)// Visited: get-temp-jetpack.ts (file)// Visited: shuffle-array-in-place.ts (file)// Visited: helpers (folder)// Visited: test (folder)
TypeScript usage
Tory is written in TypeScript and comes with complete type declarations. This means that you will have great code completions right in your editor, and also means that you can use Tory perfectly with TypeScript:
;// ...
API
Note: This API documentation is far from complete. However, the public methods are not too hard to understand from their name and arguments, so please take a look at the source code for ToryFile and ToryFolder for more information. A full API documentation is coming soon.
new ToryFolder(folderPath)
Creates a new ToryFolder instance representing the folder in the given path. This constructor throws if a folder cannot be found in the given path.
This constructor is very fast, since it does not perform any disk operations at all (except for checking the existence of the folder). In Tory, everything is Lazy Loaded (i.e. loaded only when you really need it).
folderPath
Type: string
new ToryFile(filePath)
Creates a new ToryFile instance representing the file in the given path. This constructor throws if a file cannot be found in the given path.
This constructor is very fast, since it does not perform any disk operations at all (except for checking the existence of the file). In Tory, everything is Lazy Loaded (i.e. loaded only when you really need it).
filePath
Type: string
The path to the file. It can be an absolute path or a relative path to process.cwd()
. In windows, both /
and \
are accepted as path separators.