Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kkristof200/ts-walk
https://github.com/kkristof200/ts-walk
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kkristof200/ts-walk
- Owner: kkristof200
- License: mit
- Created: 2020-09-26T18:18:25.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-26T21:10:45.000Z (about 4 years ago)
- Last Synced: 2024-05-07T11:03:10.340Z (6 months ago)
- Language: TypeScript
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-walk
Extract all file or directory/folder paths from a specified directory that justify a set of rules (file extension, etc)
## Install
```bash
npm i ts-walk
```## Walk options
#### Folder/Directory walk options:
| option name | description | type | default value |
| - | - | - | - |
| recursive | walk subfolders or no | boolean | false |
| absolutePaths | return absolute or relative paths | boolean | true (absolute paths) |#### File walk options:
| option name | description | type | default value |
| - | - | - | - |
| recursive | walk subfolders or no | boolean | false |
| absolutePaths | return absolute or relative paths | boolean | true (absolute paths) |
| fileFilter | filter the returned results | FileFilter | null (no filter) |#### FileFilter options:
| option name | description | type | default value |
| - | - | - | - |
| allowedExtensions | filter by allowed extensions | string[] | null (no filter) |
| sizeBytes | filter by size (in bytes) | FilterMinMax | null (no filter) |
| lastAccessedMs | filter by last access time time | FilterMinMax | null (no filter) |
| lastModifiedMs | filter by last modification time time | FilterMinMax | null (no filter) |
| createdMs | filter by max creation time | FilterMinMax | null (no filter) |#### FilterMinMax options:
| option name | description | type | default value |
| - | - | - | - |
| min | minimum value | number | null (no comparison) |
| max | maximum value | number | null (no comparison) |## Usage
```typescript
import { Walk } from 'ts-walk'// all files from current folder with full path (absolute_path)
console.log(Walk.files('./'))
// all files from current folder with relative path
console.log(Walk.files('./', { absolutePaths: false }))
// all files from current folder (recursive) with relative path
console.log(Walk.files('./', { recursive: true, absolutePaths: false }))
// all .js and .ts files from current folder (recursive) with relative path
console.log(Walk.files('./', { recursive: true, absolutePaths: false, fileFilter: { allowedExtensions: ['js', 'ts'] }}))
// all .ts files (smaller, than 2000 bytes) from current folder with absolute path
console.log(Walk.files('./src', {
fileFilter: {
allowedExtensions: ['ts'],
sizeBytes: { max: 2000 }
// lastAccessedMs: null,
// lastModifiedMs: null,
// createdMs: null
}
}))// all dirs from current folder with full path (absolute_path)
console.log(Walk.dirs('./'))
// all dirs from current folder with relative path
console.log(Walk.dirs('./', { absolutePaths: false }))
// all dirs from current folder (recursive) with relative path
console.log(Walk.dirs('./', { recursive: true, absolutePaths: false }))
```